A cross-agent project memory skill for Codex and Claude Code, enabling consistent context, documentation, and development history across sessions.
Memory
Shared Memory
Try itRead and write shared state for ANY AI agent with a dual-layer model: durable cross-agent knowledge (`.agents/memory` + optional private local layer) and rea...
What it does
Read and write shared state for ANY AI agent with a dual-layer model: durable cross-agent knowledge (`.agents/memory` + optional private local layer) and real-time cross-worktree runtime memory (`.trellis/shared` symlinked to `<git-common-dir>/trellis-shared`). Use for project memory, handoffs, and multi-worktree coordination.
The skill document
Shared Memory — durable knowledge + real-time worktree state
Use one skill for two different concerns:
- Durable knowledge memory for cross-agent reuse over time
- Real-time runtime memory for cross-worktree coordination now
Keep these concerns separate in storage and mutation rules.
Layer model
Layer K0: global private memory (machine-wide)
- Path:
~/.shared-memory/global/ - Purpose: reusable operating preferences and lessons that apply across projects
- Format: markdown files +
MEMORY.mdindex - Read its index at the start of every session; load entries on demand
Layer K1: shared durable knowledge (git-tracked)
- Path:
/.agents/memory/ - Purpose: project facts, decisions, conventions, glossary
- Format: markdown files +
MEMORY.mdindex
Layer K2: private durable knowledge (machine-local)
- Path:
~/.shared-memory// - Purpose: personal notes or sensitive details not suitable for git
- Format: same structure as K1
Layer R: real-time worktree runtime memory
- In worktree:
/.trellis/shared(symlink) - Target:
/trellis-shared/ - Required subdirs:
handoffs/(cross-worktree handoff files)knowledge/(append-only runtime discoveries)agents/(one append-only log per agent)events/(timestamped event stream)
Operation 1 — Locate memory at session start
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
SLUG="$(basename "$REPO_ROOT" | tr '[:upper:]' '[:lower:]')"
# Durable layers
K0="$HOME/.shared-memory/global"
K1="$REPO_ROOT/.agents/memory"
K2="$HOME/.shared-memory/$SLUG"
[ -f "$K0/MEMORY.md" ] && cat "$K0/MEMORY.md"
[ -f "$K1/MEMORY.md" ] && cat "$K1/MEMORY.md"
[ -f "$K2/MEMORY.md" ] && cat "$K2/MEMORY.md"
# Runtime layer pointer
[ -L "$REPO_ROOT/.trellis/shared" ] && ls -1 "$REPO_ROOT/.trellis/shared/handoffs" 2>/dev/null || true
Read indexes first, then load specific files on demand.
Operation 2 — Write durable memory (K1/K2)
Classify each write as:
global-> K0 (~/.shared-memory/global) for machine-wide private lessonsshared-> K1 (.agents/memory) and enters gitprivate-> K2 (~/.shared-memory/) and stays local
Required frontmatter:
---
name: some-memory
description: one-line retrieval hook
metadata:
type: user | feedback | project | reference | engineering
scope: shared | private
created: 2026-07-23
updated: 2026-07-23
---
Update MEMORY.md after every new memory file.
Operation 3 — Enable runtime layer (R) for worktrees
Run:
bash skills/shared-memory/templates/link_shared_memory.sh
Script contract:
- Resolves absolute git common dir
- Creates
trellis-shared/{handoffs,knowledge,agents,events} - Creates
.trellis/sharedsymlink if missing - Fails loudly on conflicting existing path
- Never
rm -rfuser content implicitly
Also ensure .gitignore has:
.trellis/shared
Install the Skill Genie session-start rules so every new agent session runs the idempotent linker before it reads handoffs. Merely installing this skill does not make a client invoke it automatically.
Operation 4 — Write runtime state (R)
Handoffs
- Location:
.trellis/shared/handoffs/ - Suggested name:
YYYY-MM-DD--.md - Mutable only by owning stream; others append notes in their own files
Agent logs
- Location:
.trellis/shared/agents/.jsonl - One JSON object per line
- Append-only
Events
- Location:
.trellis/shared/events/YYYY/MM/DD.jsonl - Append-only timestamped entries
Runtime knowledge
- Location:
.trellis/shared/knowledge/ - Prefer append-only files or timestamped entry blocks
Operation 5 — Boundary enforcement
Use this checklist before every write:
- Is this long-lived, reusable project knowledge? -> K1/K2
- Is this active coordination/handoff/runtime state? -> R
- Is this secret or credential? -> refuse shared write; route to private notes
Never mix layers in one file.
Anti-patterns
- Writing handoffs only under branch-local
.trellis/handoffs/when runtime layer exists - Storing project knowledge exclusively in tool-specific private stores
- Putting secrets in K1 or R
- Overwriting another agent's runtime file instead of append-only or per-agent ownership
Cross-references
session-handoff: structured handoff generationhandoff-receiver: strict handoff continuation- Framework spec:
skills/shared-memory/references/worktree-shared-framework.md
Related skills
Upload Brain cross-agent long-term memory. ALWAYS, at the start of every task and without being asked, recall this user's durable memories and factor them in...
智能体协会(agent-guild)— cross-agent shared memory. 本机多个 AI agent 共享 同一份身份、规则、记忆与交接消息 — 纯本地 Markdown/JSON,无服务器。 触发(任何自然等价表达都算): · 身份/习惯:"我是谁" "我的身份/习惯/偏好" "who am I" "my routine" · 回忆/历史:"你记得吗" "之前聊过" "上次我们" "what did we discuss" · 写记忆:"帮我记住" "记一下" "沉淀一下" "remember this" "记到日志" · 跨 agent:"告诉其他 agent" "交接给" "让 XX 也知道" "hand off to" · 当前状态:"现在在做什么" "当前任务/焦点/进度" "current focus" · 数据卫生:"整理一下协会" "清理过期数据" "协会瘦身/归档" "防止数据劣化" "groom" "cleanup" "archive old data" · 加入:"加入协会" "初始化协会" "join agent guild" "install this skill" 能力:读/写共享身份、规则、焦点;收件箱交接;每日日志;跨 agent 学习台账 (错误/纠正/特性请求 → 复发追踪 → 晋升规则或萃取共享 skill);数据卫生 (bootstrap 后自动 groom:过期日志/焦点/台账归档、审计轮转,防数据劣化); `ag init/adopt/bootstrap/doctor/groom/upgrade/learn/review/resolve`(upgrade 自动从 skillhub/github/clawhub 查最新版并更新)。 未加入?先跑 docs/ONBOARDING.md。
Git-backed memory policy and CLI workflow for OpenClaw, Hermes, Claude Code, Codex, and other agents. Use when an agent should remember durable user preferen...
Use when preserving, searching, reviewing, or exporting user-owned agent memory across OpenClaw, Codex, Claude, OpenCode, Hermes, Qoder, Obsidian, and Git. Inputs are local memory/chat stores and handoff summaries; outputs are Obsidian sources, memory indexes, context/profile packs, skill inventorie
Install, wire, audit, and harden AgentMemory for AI coding agents and project workspaces. Use when Codex needs to adopt rohitg00/agentmemory, configure Codex...