A Claude Code plugin that enforces the GitMem institutional memory lifecycle through hooks. Ships inside the gitmem-mcp npm package.
| Hook | Event | Behavior |
|---|---|---|
| Session Start | SessionStart |
Detects gitmem MCP, tells Claude to auto-call session_start |
| Recall Check | PreToolUse |
Reminds Claude to call recall before consequential actions |
| Audit Trail | PostToolUse |
Logs LOOKED/ACTION events to append-only JSONL |
| Close Check | Stop |
Blocks session end if session_close wasn't called |
npx gitmem-mcp install-hooksThis copies the hooks plugin to ~/.claude/plugins/gitmem-hooks/. Restart Claude Code to activate.
npx gitmem-mcp uninstall-hooksRemoves the plugin, cleans up settings and temp state.
- gitmem MCP server configured in
.mcp.jsonor via--mcp-config bash(scripts are pure bash — no Python dependency)
On every new Claude Code session:
- Checks
.mcp.jsonfor agitmemorgitmem-mcpserver entry - If found: injects instruction telling Claude to call
session_start - If not found: outputs a graceful "not detected" message — no errors
- Creates session state in
/tmp/gitmem-hooks-{session_id}/
Before consequential actions:
- Bash:
git push,git tag,npm publish, deploy commands - Linear: state changes to Done/Complete
- Write/Edit:
.sqlmigrations,.envfiles
Two enforcement mechanisms:
- Confirmation gate (hard block): If
recall()surfaced scars butconfirm_scars()wasn't called - Recall nag (soft reminder): If recall hasn't been called AND >3 tool calls
Logs events to /tmp/gitmem-hooks-{session_id}/audit.jsonl:
- LOOKED events: After
recall,search,semantic_search - ACTION events: After
git push, Linear Done transitions,.sql/.envwrites
When Claude tries to stop:
- Trivial sessions (< 5 tool calls, < 5 minutes) → skip enforcement
- Meaningful sessions with active session → block with reminder
- Properly closed sessions → allow
- Infinite loop guard: if hook already blocked once, always allows on retry
Tracked in /tmp/gitmem-hooks-{session_id}/:
| File | Purpose |
|---|---|
start_time |
Unix epoch of session start |
tool_call_count |
Counter incremented by recall-check |
last_nag_time |
Cooldown tracking for recall reminders |
stop_hook_active |
Guard flag to prevent infinite blocking |
audit.jsonl |
Append-only audit trail |
Cleaned up automatically when session closes properly.
If gitmem MCP is not configured:
- Session start outputs informational message (no error)
- All other hooks become silent no-ops
- No errors, no blocking
hooks/
├── .claude-plugin/
│ └── plugin.json # Plugin metadata
├── hooks/
│ └── hooks.json # Hook registrations (4 hooks)
├── scripts/
│ ├── session-start.sh # SessionStart → auto-call session_start
│ ├── recall-check.sh # PreToolUse → recall reminder + confirmation gate
│ ├── session-close-check.sh # Stop → enforce session_close
│ └── post-tool-use.sh # PostToolUse → audit trail
├── tests/
│ └── test-hooks.sh # Bash test suite (41 tests)
└── README.md