Set up Mneme with Claude Code and CI
Install the Mneme command-line tool, activate one rule from an architecture decision record (ADR), and install the Mneme plugin in Claude Code. The plugin’s hook then blocks an edit that breaks the rule. Add a required CI check for the changes the hook can’t see, and confirm one blocked and one allowed change.
You’ll end up with: one architecture decision enforced in two places: Claude Code refuses an edit that breaks it, and a required CI check fails a pull request that breaks it.
Goal
This is the reference setup: the one we recommend first, because Claude Code is the agent with Mneme’s most complete hook. The example decision bans Celery, a task-queue library, from the codebase. By the end, the same rule stops Claude Code from writing it and fails any pull request that adds it.
Two layers are required here. The hook is a command Claude Code runs before it edits a file; Mneme’s blocks an edit that breaks an active rule. The CI check runs in your pipeline and catches what the hook can’t see. A third layer, the decision lookup server, is optional, and step 11 covers it.
Four terms come up throughout:
- Memory file:
.mneme/project_memory.json, the file Mneme compiles your decisions into. The hook and the CI check both read it. - Active rule: a check attached to a decision. A decision without one blocks nothing. An ADR can carry its rule under a
## Constraintsheading, active as soon as it is imported; here Mneme proposes the rule from the ADR’s title, so the order is setup, import, validate, then activate. Steps 3 to 7 follow it. - Strict and warn mode: in strict mode, the default, the hook blocks an edit that breaks an active rule. In warn mode it lets the edit through, and Claude Code doesn’t show the finding; run
mneme check --mode warnto see findings without blocking. - Fail open: when the check itself can’t run, for example because it crashed, the hook lets the edit through rather than blocking it. That is the default.
Prerequisites
- Python 3.11 or newer, and pipx.
- Claude Code, the command-line agent. The Claude web, desktop and mobile apps don’t run plugin hooks.
- A git repository on GitHub or GitLab, with permission to add a CI workflow and make it a required check.
Tested versions: the Mneme commands and hook replays below ran against mneme-hq 0.11.0 on Windows, with the recorded output shown. Installing the plugin from Claude’s plugin directory and running Claude Code itself were not part of that run; the plugin calls the same mneme-hook command shown here.
Configure
1. Install the command-line tool
pipx install "mneme-hq==0.11.0"
This installs mneme and mneme-hook, the command the plugin runs. pipx puts both on your PATH, where Claude Code can find them.
2. Write one ADR
Save this as docs/adr/ADR-001-no-celery.md. Its title, No Celery, names one banned term, which is what lets Mneme propose a rule for it.
docs/adr/ADR-001-no-celery.md--- id: ADR-001 title: No Celery status: accepted priority: foundational date: "2026-10-01" scope: workers --- Background jobs run on the managed Pub/Sub queue. Celery was retired after the 2026 queue incident, and reintroducing it brings back a broker the team no longer operates.
Run steps 3 to 7 from the repository root. Install Mneme and activate your first protection shows the full output of each.
3. Create the memory file
mneme setup
Creates .mneme/project_memory.json and reports what it found. It blocks nothing.
4. Import the ADR
mneme adr import docs/adr --memory .mneme/project_memory.json --apply
Copies ADR-001 into the memory file. It has no active rule yet.
5. Audit the decisions
mneme audit --memory .mneme/project_memory.json --repo-root .
Reports ADR-001 as Mneme-ready: Mneme found a rule it could install, FORBID_LITERAL: celery, a ban on the exact word celery.
6. Validate the rule
mneme protect validate ADR-001 --memory .mneme/project_memory.json
Tests the proposed rule against sample inputs and changes nothing.
7. Activate the rule
mneme protect activate ADR-001 --memory .mneme/project_memory.json
Switches the rule on and confirms it is in force:
Protection activated and verified: [ADR-001] (rule installed) rule: FORBID_LITERAL "celery" verification: canonical assessment reports protected Re-run `mneme audit` to observe the new Protected decision.
Commit the ADR and .mneme/project_memory.json. The active rule lives in the memory file, and the hook and the CI check both read it.
8. Install the Claude Code plugin
claude plugin install mneme@anthropic-plugin-directory
The plugin adds the hook and four slash commands, including /mneme:context, which looks up the decisions for a task. It starts in strict mode. The plugin does not install the command-line tool, so step 1 is still needed: without it the plugin installs cleanly and checks nothing.
Install from the directory as above unless you need the plugin files fixed at the 0.11.0 release, for example to review them first. In that case, load it from a checkout instead:
git clone --branch v0.11.0 --depth 1 https://github.com/MnemeHQ/mneme mneme-src claude --plugin-dir ./mneme-src/integrations/claude-code-plugin
9. Start Claude Code from the repository root
The hook looks for .mneme/project_memory.json in the session’s working directory and its parents. Start Claude Code inside the git repository, too: the end-of-turn check compares against git.
10. Add the required CI check
Copy the workflow for GitHub Actions or the job for GitLab CI from the CI-only setup, then make it required: a branch ruleset with “Require status checks to pass” on GitHub, or “Pipelines must succeed” on GitLab. Without that setting, a failing check is only a red mark on the pull request.
11. Optional: add the decision lookup server
/mneme:context already gives Claude Code the decisions for a task. The Model Context Protocol (MCP) server adds lookup by file path, tracing which decision replaced which, and proposals for people to review. The decision MCP setup shows the .mcp.json entry Claude Code reads.
Run
Ask Claude Code for a change that breaks ADR-001, for example: “Add a worker in workers/jobs.py that uses Celery.” When the agent goes to write the file, Claude Code sends the hook a JSON description of the call. To see the hook’s answer without running an agent, save that event as events/write-celery.json:
events/write-celery.json{
"hook_event_name": "PreToolUse",
"session_id": "setup-guide",
"cwd": ".",
"tool_name": "Write",
"tool_input": {
"file_path": "workers/jobs.py",
"content": "from celery import Celery\n\napp = Celery(\"jobs\")\n"
}
}
mneme-hook < events/write-celery.json
Then the allowed version, the same worker on Pub/Sub, saved as events/write-pubsub.json:
events/write-pubsub.json{
"hook_event_name": "PreToolUse",
"session_id": "setup-guide",
"cwd": ".",
"tool_name": "Write",
"tool_input": {
"file_path": "workers/jobs.py",
"content": "from google.cloud import pubsub_v1\n\npublisher = pubsub_v1.PublisherClient()\n"
}
}
mneme-hook < events/write-pubsub.json
Finally, open a pull request that adds both workers as workers/jobs.py and workers/publish.py, so the CI check has one file of each kind.
Expected result
The Celery write exits with code 2, which Claude Code treats as “block this change”. The file isn’t written, and the agent receives this text:
mneme: FAIL - architectural decision violated
[ADR-001] FAIL "celery" - trigger: celery
No Celery
path: workers/jobs.py
The Pub/Sub write exits 0 with no output, so the agent carries on.
In CI, the check prints one line per changed file with the exit code mneme check returned, and the job fails with exit code 2:
exit=2 workers/jobs.py exit=0 workers/publish.py
We ran the workflow’s check loop against a local copy of that pull request, not on GitHub’s runners.
What is and isn’t enforced
- Blocked before the file changes: Edit, Write and MultiEdit calls, and one shell form, a single
cat > file <<'EOF'command with a quoted delimiter. - Checked only when the agent ends its turn: other shell writes, such as
echo >,sed -ior a script. The file already exists by then; the hook sends the agent back to fix it and doesn’t undo the write. Stop an AI coding agent from crossing an architectural boundary replays this end-of-turn check. - Fails open by default: if
mnemeisn’t found, a check crashes, or a check takes longer than 10 seconds, the hook allows the edit. Its notes go only to Claude Code’s debug log. A repository can opt in to refusing Edit, Write and MultiEdit calls when the check can’t run, through a reviewed change on its default branch; this guide doesn’t set that up. - Not covered by the hook: changes made outside Claude Code, by people or other tools. The CI check covers those, for the files a pull request adds or modifies.
- The rule matches exact text.
celeryas a whole, case-sensitive token, in any file except the ADR and the memory file. It doesn’t matchCeleryon its own, and a comment that mentions celery fails too.
Troubleshooting
Nothing is blocked, and the hook prints nothing
The hook didn’t find a memory file, and with none it allows every change silently:
MNEME_MEMORY=missing.json mneme-hook < events/write-celery.json
The output is empty and the exit code is 0. Start Claude Code from the repository root, or set MNEME_MEMORY to the memory file’s path.
The edit goes through, and nothing explains why
Warn mode is on, through MNEME_HOOK_MODE=warn or the plugin’s mode option. The hook then defers to Claude Code’s normal permission flow, and Claude Code doesn’t show the reason it attaches:
{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "defer", "permissionDecisionReason": "mneme: FAIL - architectural decision violated\n [ADR-001] FAIL \"celery\" - trigger: celery\n No Celery\n path: workers/jobs.py"}}
Unset the variable or set the option back to strict.
The hook isn’t firing at all
Check that mneme-hook is on your PATH (which mneme-hook, or where mneme-hook on Windows) and that claude plugin list shows mneme@anthropic-plugin-directory. If the audit still says Mneme-ready rather than Protected, the rule isn’t active yet: repeat steps 6 and 7.
CI fails on every pull request at the memory check
An ADR changed without a re-import, or ADR line endings differ between machines. The CI-only setup covers both.
Next layer
Rolling this out across a team?
We work with design partners to set up enforcement on a real repository.