/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
- Copy the
hooksblock fromscripts/hooks/hooks.example.jsoninto your Claude Code settings (~/.claude/settings.jsonor project.claude/settings.json):
-
Replace
/path/to/3ngramwith the actual path to your 3ngram clone. - Set two environment variables:
POST /api/keys.
Hook reference
SessionStart: Briefing
Script:3ngram-briefing.sh
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
Script:3ngram-capture.sh
Filters every tool-use event against rules in capture-filter.json. By default, only git commit commands are captured. Each captured event is persisted as a memory via the REST API (POST /api/memories).
The script 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 context - 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
The 3ngram plugin also bundles3ngram-sync.sh, which performs bidirectional sync of Claude Code’s ~/.claude/projects/*/memory/ directory with 3ngram at session end. To add it manually:
ENGRAM_API_KEY (separate from the MCP token). Skips silently if the key is not set.
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
ENGRAM_API_URL | Yes | http://localhost:8000 | REST API endpoint |
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:context). 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: All scripts require
jq. Install it with your package manager. - Briefing shows fallback message: API server unreachable,
ENGRAM_API_KEYunset, orjqmissing.