engram-hook) that integrates with Claude Code hooks to automate memory capture across your coding sessions. The binary has five subcommands — briefing, capture, precheck, sync, and verify — and replaces the retired bash hook scripts. For end-of-session debriefs, use the /debrief prompt template.
Hook scripts are specific to Claude Code. Other MCP clients (Claude Desktop, Cursor, ChatGPT) don’t support hooks, use prompt templates instead.
Quick start
-
Install the
engram-hookbinary so it lands on yourPATH. From a clone of the repo:Pre-built binaries are also published as Go release artifacts via.github/workflows/go-hooks.yml(linux/darwin × amd64/arm64). -
Copy the
hooksblock fromscripts/hooks/hooks.example.jsoninto your Claude Code settings (~/.claude/settings.jsonor project.claude/settings.json): -
Set two environment variables:
Generate an API key from the 3ngram app at Settings → API Keys, or via
POST /api/keys.
Hook reference
SessionStart: Briefing
Command:engram-hook briefing (Go binary).
Fetches your open commitments, blockers, overdue items, stale work (past configurable staleness threshold), and recent decisions from the 3ngram REST API. Renders a token-budgeted briefing block injected into the session context.
All four API calls run in parallel for speed. Falls back to a reminder message if the server is unreachable. Suppressed in secondary git worktrees to avoid duplicate briefings.
PostToolUse: Capture
Command:engram-hook capture (Go binary).
Filters every tool-use event against rules in capture-filter.json. By default, only git commit commands and Claude Code plan-file writes are captured. Each captured event is persisted as a memory via the REST API (POST /api/memories).
The hook automatically:
- Derives the project name from the git remote URL
- Extracts conventional commit tags (
feat,fix, etc.) for memory tagging - Classifies
feat/refactorcommits as decisions, everything else as notes - Persists Claude Code plans (written to
~/.claude/plans/) as commitments so they surface in future briefings - Strips
<private>tags from content before sending - Skips 3ngram’s own MCP tool calls to prevent circular capture
Optional: SessionEnd memory sync
Command:engram-hook sync --both (Go).
Performs a bidirectional sync of Claude Code’s ~/.claude/projects/*/memory/ directory with 3ngram at session end. To add it manually, append the SessionEnd block from the Quick start section above.
Requires ENGRAM_API_KEY (separate from MCP OAuth). Skips silently if the key is not set.
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
ENGRAM_API_BASE | No | https://api.3ngram.ai | REST API endpoint (preferred) |
ENGRAM_API_URL | No | (none) | Legacy fallback when ENGRAM_API_BASE is unset |
ENGRAM_API_KEY | Yes | (none) | API key for X-API-Key auth |
ENGRAM_SCOPE | No | (none) | Scope tag for multi-tenant setups |
ENGRAM_HOOK_DEBUG | No | 0 | Set to 1 to dump raw payloads to /tmp/3ngram-hook-debug/ |
BRIEFING_FULL_COUNT | No | 5 | Number of items shown with full content in briefings |
BRIEFING_MAX_TOKENS | No | 2000 | Token budget cap for briefing output |
Capture filter rules
The filescripts/hooks/capture-filter.json controls which tool events get captured. Default config captures only git commits:
tool: Tool name (e.g.Bash,Write)command_pattern: Substring match against the command (Bash tool)path_pattern: Substring match against the file path (Write tool)capture: Whether to persist the event as a memorytopic_template: Memory topic, supports{project}and{filename}placeholderscontent_fields: Which fields from the tool input/response to include (single-field rules use the raw value without a label prefix)memory_type: Override memory type for matched events (default:note). Usecommitmentfor items that should surface in briefings.tags: JSON array of tags to apply (e.g.["plan"]). Overrides the default tag extraction from commit messages.
defaults.capture to true to capture all events (noisy, not recommended).
Troubleshooting
SetENGRAM_HOOK_DEBUG=1 to dump raw payloads to /tmp/3ngram-hook-debug/. Check capture-*.json for PostToolUse events. Disable debug mode after troubleshooting, especially on shared systems, as payloads may contain session content.
Common issues:
- “hook error” on every tool use: The Go binary is self-contained — if it’s not on your
PATH, installengram-hookwithgo installor pointENGRAM_HOOK_BINat the binary. - Briefing shows fallback message: API server unreachable or
ENGRAM_API_KEYunset.