collective-memory
Skill4 starsChanged 5 months agoMITView on GitHub
Broadcast a single memory note to multiple AI-agent workspaces in one shot, upserting into MEMORY.md / AGENTS.md / TOOLS.md / USER.md across all targets. Pure file-ops, zero network, zero LLM. Works on OpenClaw, Claude Code, Cursor, and any agent runtime that stores per-project memory as Markdown. Triggers: "broadcast memory", "tell every agent", "remember this everywhere", "sync this to all agents", "make all my agents know", "集体记忆", "广播这条记忆", "你们全都记住", "所有agent记住", "大家都记一下", "让他们都记住".
- Reads credentials
- Installs packages
In this repository16 other files it gives its agents.
- agent-avatar-managerSkill
- agent-team-meshSkill
- claw-memory-managerSkill
- codex-thread-repairSkill
- copy-my-profileSkill
- hello-envSkill
- init-hooksSkill
- multica-squad-load-balancerSkill
- multica-squad-onboardSkill
- openviking-projectsSkill
- recover-codex-project-chatsSkill
- rename-sessionSkill
- session-recoverySkill
- subagent-timeout-configSkill
- token-slimSkill
- workspace-git-setupSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 47
When unsure, default to MEMORY.md.
- Very specific: line 97
Sensitive content guard: if content contains token, password, secret, api_key, private_key, or _token= patterns, always add a red warning …
- Very specific: line 107
Before invoking the script, the calling agent may read each target file's existing ## headings and decide if key semantically matches one …
- Very specific: line 109
If yes, replace key with the exact heading text to ensure precise overwrite.
- Distinctive: line 191
Step 2: no heading matched → append to the end of the file.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Collective Memory
- Author: Evan Song · github.com/Songhonglei
- Repository: https://github.com/Songhonglei/better-agent-skills
- License: MIT
Broadcast a single memory note to multiple agent workspaces in one shot —
idempotent upsert into MEMORY.md, AGENTS.md, TOOLS.md, USER.md, or
any Markdown file across all targets.
Pure file-ops, zero network, zero LLM. The calling agent decides what to write and which key to look up; this script does the file work atomically.
Execution Flow
Step 1 — Extract the memory
From the user's request, extract three things:
content: the full Markdown block (must include its own##heading line)key: 1–5 word lookup phrase used to find an existing heading to updatefile: which file to write into (defaultMEMORY.md)
File routing rules:
| Content type | Target file |
| Facts, rules, lessons, tool paths, APIs | MEMORY.md |
| Workflows, do/don't, dev conventions | AGENTS.md |
| Tool commands, config params, account info | TOOLS.md |
| Information about the user themselves | USER.md |
When unsure, default to MEMORY.md.
Step 2 — Resolve agent targets (hybrid: explicit > discovery > confirm)
Pick the first strategy that yields targets:
A. Explicit (preferred when known)
--target /path/to/ws1:MEMORY.md \
--target /path/to/ws2:MEMORY.mdOr via env: COLLECTIVE_MEMORY_TARGETS="/ws1:MEMORY.md,/ws2:MEMORY.md".
B. Auto-discover (when user says "all my agents")
--discover-under ~/.claude/projects --file MEMORY.md
--discover-under ~/.openclaw/agents --file MEMORY.md
--discover-under ~/code --file AGENTS.mdEach --discover-under <parent> finds first-level subdirectories.
Discovery defaults to check (in order, stop at first non-empty):
$COLLECTIVE_MEMORY_TARGETSenv~/.claude/projects/(Claude Code)~/.openclaw/agents/(OpenClaw)- CWD's immediate sibling directories
- Ask the user
Step 3 — Confirm before broadcasting (REQUIRED for ≥2 targets)
Show the plan and wait for user y/n:
About to broadcast to 3 target(s):
• /home/me/code/proj-a → MEMORY.md
• /home/me/code/proj-b → MEMORY.md
• /home/me/code/proj-c → MEMORY.md
Content: [first 80 chars of content]
Lookup key: [key]
Proceed? (y/n)Single target → skip confirmation, run directly.
Sensitive content guard: if content contains token, password,
secret, api_key, private_key, or _token= patterns, always add a
red warning line to the confirmation prompt:
⚠️ This memory contains apparent secrets. Broadcasting will write to every target. Are you sure? (y/n)
Step 4 — (Optional) AI synonym pre-pass
Before invoking the script, the calling agent may read each target file's
existing ## headings and decide if key semantically matches one of them.
If yes, replace key with the exact heading text to ensure precise overwrite.
The script itself does no AI calls — only literal heading tokenization (English single-char + CJK 2-gram OR match).
Step 5 — Execute broadcast
Recommended multi-target form (single Python invocation):
python3 <skill-install-path>/scripts/update_memory.py \
--target /path/to/ws1:MEMORY.md \
--target /path/to/ws2:MEMORY.md \
--target /path/to/ws3:MEMORY.md \
--key "API key path" \
--content "## API key path
stored in .secrets/api-keys.env (chmod 600)"Auto-discover form:
python3 <skill-install-path>/scripts/update_memory.py \
--discover-under ~/.claude/projects \
--discover-under ~/.openclaw/agents \
--file MEMORY.md \
--key "API key path" \
--content "## API key path
..."Legacy single-target (backward compatible):
python3 <skill-install-path>/scripts/update_memory.py \
--workspace /path/to/ws --file MEMORY.md \
--key "..." --content "..."Step 6 — Report results
The script prints one line per target with status: updated / appended /
would_update / would_append / error. With --json, the output is
machine-readable for downstream tooling.
Broadcast to 3 target(s):
✅ [appended] /home/me/code/proj-a → MEMORY.md
✅ [updated] /home/me/code/proj-b → MEMORY.md
❌ [error] /home/me/code/proj-c → MEMORY.md — workspace not foundExit code 0 = all targets OK; 1 = at least one failure.
CLI Reference
python3 update_memory.py [options]| Flag | Repeatable | Description |
--workspace <path> | no | Single workspace (legacy mode). Requires --file. |
--target <ws>:<file> | yes | Explicit workspace:filename pair, e.g. /proj:MEMORY.md |
--discover-under <parent> | yes | Auto-find first-level subdirs. Requires --file. |
--file <name> | no | Default file used by --workspace and --discover-under |
--key <text> | no | Required. Heading lookup key. |
--content <markdown> | no | Required. Full block to upsert, must include its own ## heading. |
--dry-run | no | Preview only; no files written. |
--json | no | Emit JSON result instead of human text. |
Match Behaviour
- Step 1: tokenize
key(English/digit runs lowercased, CJK 2+ char spans) → OR-match against every##heading in the file → if hit, replace that section up to the next same-or-higher level heading. - Step 2: no heading matched → append to the end of the file.
- Both branches are idempotent: re-running the same command never produces duplicate sections.
What This Skill Is NOT
- Not a real-time sync service. Each invocation is one-shot file write.
- Not an LLM-based merger. Tokenization is literal; if you want fuzzy semantic matching, do it in Step 4 (AI pre-pass) before calling the script.
- Not a remote-agent broadcaster by itself. For remote agents (ACP / HTTP / SSH), the calling agent must orchestrate transport separately and invoke this script on each remote machine.
Dependencies
- Python 3.8+ (standard library only — no
pip installrequired)
Key Files
| File | Purpose |
scripts/update_memory.py | The upsert engine. Multi-target + dry-run + JSON. |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

