Skip to main content
3ngram ships a single Go hook binary (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.
If you use the 3ngram Telegram or Discord bot, pair hooks with Claude Code Channels to route bot nudges directly into your coding session.

Quick start

  1. Install the engram-hook binary so it lands on your PATH. From a clone of the repo:
    cd cmd/engram-hook
    go install .
    # → ~/go/bin/engram-hook (make sure ~/go/bin or ~/.local/bin is on your PATH)
    
    Pre-built binaries are also published as Go release artifacts via .github/workflows/go-hooks.yml (linux/darwin × amd64/arm64).
  2. Copy the hooks block from scripts/hooks/hooks.example.json into your Claude Code settings (~/.claude/settings.json or project .claude/settings.json):
    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": "engram-hook briefing",
                "statusMessage": "3ngram: Loading session briefing..."
              }
            ]
          }
        ],
        "PostToolUse": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": "engram-hook capture"
              }
            ]
          }
        ],
        "SessionEnd": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": "engram-hook sync --both",
                "statusMessage": "3ngram: Syncing memories..."
              }
            ]
          }
        ]
      }
    }
    
  3. Set two environment variables:
    export ENGRAM_API_BASE="https://api.3ngram.ai"  # or http://localhost:8000
    export ENGRAM_API_KEY="your-api-key"
    
    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/refactor commits 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

VariableRequiredDefaultDescription
ENGRAM_API_BASENohttps://api.3ngram.aiREST API endpoint (preferred)
ENGRAM_API_URLNo(none)Legacy fallback when ENGRAM_API_BASE is unset
ENGRAM_API_KEYYes(none)API key for X-API-Key auth
ENGRAM_SCOPENo(none)Scope tag for multi-tenant setups
ENGRAM_HOOK_DEBUGNo0Set to 1 to dump raw payloads to /tmp/3ngram-hook-debug/
BRIEFING_FULL_COUNTNo5Number of items shown with full content in briefings
BRIEFING_MAX_TOKENSNo2000Token budget cap for briefing output

Capture filter rules

The file scripts/hooks/capture-filter.json controls which tool events get captured. Default config captures only git commits:
{
  "rules": [
    {
      "tool": "Bash",
      "command_pattern": "git commit",
      "capture": true,
      "topic_template": "commit: {project}",
      "content_fields": ["command", "stdout"]
    }
  ],
  "defaults": {
    "capture": false
  }
}
Each rule matches on:
  • 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 memory
  • topic_template: Memory topic, supports {project} and {filename} placeholders
  • content_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). Use commitment for items that should surface in briefings.
  • tags: JSON array of tags to apply (e.g. ["plan"]). Overrides the default tag extraction from commit messages.
Set defaults.capture to true to capture all events (noisy, not recommended).

Troubleshooting

Set ENGRAM_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, install engram-hook with go install or point ENGRAM_HOOK_BIN at the binary.
  • Briefing shows fallback message: API server unreachable or ENGRAM_API_KEY unset.