Use git-as-memory as a durable, auditable memory layer for agents. It stores memory in a dedicated Git ref, not in the working tree.
Default ref:
bash
refs/git-as-memory/memory/v1
Supported agents: OpenClaw, Hermes, Claude Code, Codex, or any agent that can run shell commands.
Prefer gam if installed:
bash
command -v gam
If missing, install one of:
bash
npm install -g git-as-memory
pip install git-as-memory
No global install:
bash
npx git-as-memory --help
python -m git_as_memory.cli --help
All commands require a Git repo. If --repo is omitted, use the current working repo.
Initialize once per repo; it is idempotent:
bash
gam init --repo /path/to/repo
Write memory only for stable, reusable information.
Write when:
Do not write:
--type hypothesis.Before writing:
Search for related memory first: bash
gam search "<keywords>" --repo /path/to/repo
If a related memory exists, update the same stable id.
If not, create a concise new memory.
Always include --source explaining where the memory came from.
After writing, report the memory key:
text
<type>/<id>
Use a small, consistent type set:
entity: user, project, organization, tool, or other entity preference/profile.semantic: durable fact, rule, convention, decision, or technical lesson.episodic: compact summary of a task/session/event.working: short-lived task context that may be deleted later.hypothesis: unverified inference that should be confirmed before acting on strongly.Use stable kebab-case ids. Prefer names that future agents can guess.
Good:
text
user-preference-concise-answers
project-release-workflow
openclaw-memory-policy
git-as-memory-storage-layout
Avoid random ids unless there is no stable concept.
bash
gam write "User prefers concise technical answers with concrete commands." \
--repo /path/to/repo \
--type entity \
--id user-preference-concise-answers \
--tag user \
--tag preference \
--source "User corrected the agent for over-explaining and asked for practical output."
Multi-line:
bash
printf '%s\n' "Decision summary..." | gam write --stdin \
--repo /path/to/repo \
--type semantic \
--id project-decision-example \
--source "Summarized from the current implementation session."
Use read when you know the key:
bash
gam read entity/user-preference-concise-answers --repo /path/to/repo
show is equivalent when using id plus optional type:
bash
gam show user-preference-concise-answers --type entity --repo /path/to/repo
Use search for content lookup:
bash
gam search "release workflow" --repo /path/to/repo
gam search "concise answers" --repo /path/to/repo --json
Search is local substring matching over memory content, tags, metadata, and source text.
Use glob for memory key lookup, not arbitrary working-tree files. It matches <type>/<id> and bare ids:
bash
gam glob "entity/*" --repo /path/to/repo
gam glob "user-*" --repo /path/to/repo
gam glob "*release*" --repo /path/to/repo
Use --files only for debugging the underlying Git tree:
bash
gam glob "entity/*" --files --repo /path/to/repo
bash
gam list --repo /path/to/repo
gam list --repo /path/to/repo --json
bash
gam history user-preference-concise-answers --type entity --repo /path/to/repo
Direct Git inspection:
bash
git -C /path/to/repo log --oneline refs/git-as-memory/memory/v1
git -C /path/to/repo ls-tree -r --name-only refs/git-as-memory/memory/v1
Prefer soft delete:
bash
gam delete user-preference-concise-answers --type entity --repo /path/to/repo
Use purge only when the user explicitly asks to remove the current visible files:
bash
gam purge user-preference-concise-answers --type entity --repo /path/to/repo
When starting a task in a repo:
If memory may matter, run targeted search: bash
gam search "<project/tool/user keywords>" --repo /path/to/repo
Read only relevant matches.
Do not bulk-load all memory unless the user asks for an audit.
When a durable lesson appears:
When the user asks "what do you remember?":
gam list, gam glob, or gam search.gam read for relevant keys.gam history only if provenance or evolution matters.After a memory write, respond briefly:
text
Remembered: entity/user-preference-concise-answers
If you decide not to write memory, say why only when useful:
text
Not writing memory: this is a one-off task detail.