Requires Node.js >= 18 and git.
npm install -g git-mem
cd your-repo
git-mem initThat's it. Every commit now includes AI metadata:
feat: add user authentication
AI-Agent: claude-code
AI-Model: claude-sonnet-4-5-20250929
AI-Decision: JWT over sessions — stateless API, scales horizontally
AI-Context: [pattern/middleware, entity/auth-module]
- Git hooks —
prepare-commit-msgandcommit-msgadd AI trailers to every commit - Config —
.git-mem/.git-mem.yamlwith settings - MCP server —
.mcp.jsonfor AI tool integration - Gitignore — keeps local config out of version control
Two bin commands are available after installation:
git-mem(also works asgit mem— git subcommand)git-mem-mcp(MCP server for AI tools)
git-mem stores knowledge in two ways:
When you remember on HEAD, git-mem also writes AI-* trailers directly into the commit message:
AI-Decision: JWT over sessions — stateless API, scales horizontally
AI-Confidence: high
AI-Memory-Id: 3bf31da6-86a6-43cc-a1db-2f99da187107
AI-Tags: auth, architecture
Trailers are:
- Natively queryable —
git log --grep-reflogorgit log --trailer - Visible — show up in
git log, GitHub, and code review tools - Only on new commits —
extractwrites notes only (no history rewrite)
Memories are stored as JSON in git notes on refs/notes/mem. Each commit can have a note containing an array of memory entities:
refs/notes/mem
└── <commit-sha> → { "memories": [{ id, content, type, confidence, tags, ... }] }
Notes are:
- Version controlled — visible in
git log --notes=refs/notes/mem - Shareable — push/pull with
git mem sync - Non-invasive — doesn't modify commits, branches, or working tree
git mem init
git mem init -yOptions:
-y, --yes— Accept defaults without prompting--hooks— Install prepare-commit-msg git hook--uninstall-hooks— Remove the prepare-commit-msg git hook
Store a memory attached to the current commit.
git mem remember "JWT chosen over sessions for stateless API" \
--type decision \
--tags "auth, architecture" \
--confidence highWrites to git notes and adds AI-* trailers to HEAD.
Options:
-c, --commit <sha>— Attach to specific commit (default: HEAD)-t, --type <type>—decision,gotcha,convention,fact(default:fact)--confidence <level>—verified,high,medium,low(default:high)--lifecycle <tier>—permanent,project,session(default:project)--tags <tags>— Comma-separated tags--no-trailers— Skip writing AI-* trailers to the commit message
Search stored memories.
git mem recall "authentication"
git mem recall --type decision --jsonOptions:
-n, --limit <n>— Max results (default: 10)-t, --type <type>— Filter by type--since <date>— Filter by date--json— Output as JSON
Scans commit history, scores commits by interest, and extract decisions/gotchas/conventions as memories for AI context.
git mem extract --since 2024-01-01 --dry-run
git mem extract --threshold 5 --commit-count 100
git mem extract --enrich --dry-run --commit-count 10Options:
--since <date>— Start date (default: 90 days ago)--commit-count <n>— Max commits to process--dry-run— Preview without writing--threshold <n>— Interest score threshold (default: 3)--enrich— Enable LLM enrichment (requires an LLM provider API key)
Show memories relevant to staged changes.
git add .
git mem contextOptions:
-n, --limit <n>— Max results (default: 10)--threshold <n>— Min relevance score 0-1 (default: 0.1)--json— Output as JSON
Push/pull memory refs to/from origin.
git mem sync # push + pull
git mem sync --push # push only
git mem sync --pull # pull onlyInspect AI-* trailers on commits.
git mem trailers # show trailers on HEAD
git mem trailers abc123 # show trailers on specific commit
git mem trailers --query AI-Decision # search across history
git mem trailers --keys # list all distinct AI-* trailer keysOptions:
--query <key>— Search for trailer key across history (e.g.AI-Decision)--since <date>— Filter commits after date--keys— List all distinct AI-* trailer keys in the repo-n, --limit <n>— Max commits to search--json— Output as JSON
If you use Claude Code, git-mem can do more than just add trailers & notes — it can give Claude persistent memory across sessions.
init also sets up Claude Code hooks in .claude/settings.json:
| Hook | What it does |
|---|---|
| SessionStart | Loads stored memories into Claude's context on startup |
| Stop | Extracts knowledge from commits made during the session |
| UserPromptSubmit | Surfaces relevant memories per prompt (disabled by default) |
| PostCommit | Records AI agent and model metadata on each commit |
| CommitMsg | Analyzes commit message and adds AI-* trailers (with optional LLM enrichment) |
These hooks read the AI trailers from your commits and build a searchable memory layer that Claude can query.
Settings are in .git-mem/.git-mem.yaml:
hooks:
enabled: true
sessionStart:
enabled: true
memoryLimit: 20
sessionStop:
enabled: true
autoExtract: true
threshold: 3
promptSubmit:
enabled: false
surfaceContext: true
commitMsg:
enabled: true
enrich: false # set true + provide LLM API key for enriched extraction
enrichTimeout: 8000
postCommit:
enabled: true| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY |
For Anthropic LLM | Anthropic (Claude) API key |
OPENAI_API_KEY |
For OpenAI LLM | OpenAI API key (requires npm install openai) |
GOOGLE_API_KEY / GEMINI_API_KEY |
For Gemini LLM | Google Gemini API key (requires npm install @google/generative-ai) |
OLLAMA_HOST |
For Ollama | Ollama server URL (default: http://localhost:11434) |
GIT_MEM_LLM_PROVIDER |
No | Force provider: anthropic, openai, gemini, ollama |
Only one provider is needed. If --enrich is used without any LLM API key, git-mem falls back to heuristic extraction with a warning.
You can also configure the LLM provider in .git-mem/.git-mem.yaml:
llm:
provider: openai # auto-detected from env vars if omitted
model: gpt-4o # uses provider default if omitted
intentModel: gpt-4o-mini
baseUrl: http://localhost:11434 # for ollama