Overview
Mengram integrates with Claude Code hooks to create a full memory loop that survives/clear, auto-compaction, machine switches, and team handoffs — the SessionStart hook fires after every compact and re-injects your context:
- Session context — loads your cognitive profile when a session starts, so Claude knows who you are
- Auto-recall — searches relevant memories on every prompt and injects them as context
- Auto-save — captures conversations in the background to build up memory over time
- Policy gate — before a workflow-shaped Bash command runs, checks it against the workflows memory has learned; if the match has a weak record, Claude has to ask you first
Quick Setup
Option A — plugin from the marketplace (recommended)
~/.mengram/config.json (an exported MENGRAM_API_KEY env var wins if set).
First-run self-check: until the plugin verifies one successful API round-trip, failures show a one-line message telling you exactly what’s broken. After the first success, failures are silent — an outage never spams you or blocks Claude Code.
Option B — CLI hooks
Skip the cold start — import your history
Your past Claude Code sessions are already on disk. Feed them in and memory starts full, not empty:How It Works
1. Session Start — Profile Loaded
When you open Claude Code (or after context compaction), theSessionStart hook fires:
2. Every Prompt — Relevant Memories Recalled
When you type a prompt, theUserPromptSubmit hook fires before Claude responds:
3. After Response — Conversation Saved
After Claude responds, theStop hook fires asynchronously in the background:
4. Before a Bash command — the policy gate
Outcome history should change what the agent is allowed to do, not only how results rank. When Claude is about to run a command that looks like a workflow (git push, deploy, migrate, kubectl, terraform, rm -rf …), the PreToolUse hook fires:
[settings], with the reason: “Mengram: learned workflow ‘deploy to Railway’ has never been run. Review the plan before it runs.” Claude receives the workflow’s steps, preconditions and last failure as context, so if you decline it can show you the plan instead of guessing.
The gate never denies. Memory can ask; it does not get to forbid. Commands that are not workflow-shaped (ls, cat, grep) never trigger a lookup, so the hook costs nothing on ordinary work.
Why the record fills itself here and not offline. The gate is only as good as the counts behind it. With the cloud, auto-save extracts workflows from your sessions, a failed run records the violated assumption on a new version, and every procedure carries success_count / fail_count / last_failure without you writing anything. The same gate runs fully offline against a memfmt folder (MENGRAM_MEMORY_DIR=./memory), but there the counts are whatever you typed.
Full Loop
Commands
mengram hook install
Installs all 4 hooks into~/.claude/settings.json.
mengram hook status
Check status of all hooks.mengram hook uninstall
Remove all Mengram hooks.Configuration
Environment Variables
Filtering
Auto-save skips:- Short responses (< 100 characters) — trivial confirmations
- Interrupted requests
- Responses when no API key is set
- Very short prompts (< 10 characters)
- Slash commands (
/help,/clear, etc.) - Simple confirmations (
yes,no,ok)
- Any tool other than
Bash - Commands that are not workflow-shaped (
ls,cat,grep,python -c …) — no lookup, no cost - Matches whose record is at or above the bar — the command runs untouched
- Semantic near-misses: a matched workflow must share at least one real word with the command before it can interrupt you
Quota Limits
When you hit your monthly plan limits, each hook surfaces a clear warning instead of failing silently:
All messages include an upgrade link. Claude Code is never blocked — hooks continue gracefully.
Non-quota errors (network timeouts, transient failures) are silently swallowed so they never interrupt your workflow.
To check your current usage:
mengram stats or visit mengram.io/dashboard.
Debugging: verbose markers and heartbeat
Verbose markers (CLI hooks): add--verbose to any hook command in your hooks config and every exit path emits a one-line status marker — [mengram:auto-recall] found 3 memories, [mengram:auto-save] throttled (2/3). Answers “is it working?” in one session restart. Off by default (byte-for-byte silent).
Heartbeat (plugin): set MENGRAM_HEARTBEAT=25 (env) or "heartbeat": 25 in ~/.mengram/config.json and every 25th successful save shows one line: [mengram] heartbeat: 150 conversations saved to memory so far. With the heartbeat on, silence means something is wrong.
Troubleshooting
Hooks not firing?- Restart Claude Code after installing
- Check
mengram hook statusto verify all 4 hooks are installed - Keys are read from
MENGRAM_API_KEYenv or~/.mengram/config.json(env wins) — checkcat ~/.mengram/config.json
- Auto-save processes in the background — check after ~30 seconds
- Verify API connectivity:
mengram hook status - Check your memories at mengram.io/dashboard
- Auto-recall has a 10-second timeout — if the API is slow, it’s skipped gracefully
- Claude Code continues normally even if a hook fails
- You’ve hit your monthly plan limit — memory is disabled until the limit resets or you upgrade
- Run
mengram statsto check usage - Upgrade at mengram.io/dashboard