Set up Mneme in CI only
Commit your decisions and the memory file, then add a CI job that runs mneme check on each file a pull request adds or modifies. Make the job a required check, and a change that breaks a decision with an activated rule can’t merge, whether Copilot, Cursor, another agent or a person wrote it.
You’ll end up with: a required check that fails any pull request or merge request adding a file that breaks a decision with an activated rule, whichever tool wrote it.
Goal
CI is the one layer that works for every agent. It doesn’t need a hook inside the tool, so it covers agents and editors that have none, such as GitHub Copilot, Cursor and JetBrains IDEs, and changes people make by hand. The cost is timing: it finds a violation after the file is written, when the pull request runs.
The example decision is ADR-001, an architecture decision record (ADR) that bans the Celery library. Each guide in this section uses it.
Prerequisites
- A decision with an activated rule, committed in
.mneme/project_memory.json, the memory file Mneme compiles your decisions into. A decision imported without any rule blocks nothing. Steps 1 to 7 of the Claude Code setup do this for ADR-001 with no agent involved; Install Mneme and activate your first protection explains each command. - Your ADRs in
docs/adr/, committed with Unix (LF) line endings: adddocs/adr/*.md text eol=lfto.gitattributes. The memory file records a hash of each ADR’s bytes. - Permission to add a workflow and to require it before merge.
Tested versions: mneme-hq 0.11.0. We ran each job’s check script against a local copy of a pull request (bash for GitHub Actions, sh -e for GitLab CI), not on hosted runners.
GitHub Actions
Save this as .github/workflows/mneme-decisions.yml. Fail a pull request that breaks an ADR explains it line by line.
.github/workflows/mneme-decisions.ymlname: Architecture decisions
on:
pull_request:
branches: [main]
permissions:
contents: read
jobs:
mneme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Mneme
run: python -m pip install "mneme-hq==0.11.0"
- name: Check the memory file matches the ADRs
run: |
mneme adr import docs/adr --memory .mneme/project_memory.json --apply --update-existing
git diff --exit-code -- .mneme/project_memory.json
- name: Check changed files against decisions
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
run: |
set -uo pipefail
# Added and modified files, one per line as "added<TAB>deleted<TAB>path".
# Binary files show "-" counts; mneme check reads text only.
changes=$(git diff --numstat --no-renames --diff-filter=AM "origin/$BASE_REF...HEAD") || exit 2
worst=0
mkdir -p mneme-results
while IFS=$'\t' read -r added _ f; do
[ -n "$f" ] || continue
if [ "$added" = "-" ]; then echo "skip $f (binary)"; continue; fi
out="mneme-results/$(printf '%s' "$f" | tr '/' '_').json"
# GitHub runs this shell with -e; "|| code=$?" records a failing
# check instead of ending the step at the first violation
code=0
mneme check --memory .mneme/project_memory.json \
--input "$f" --target-path "$f" \
--query "PR change: $f" --json > "$out" || code=$?
echo "exit=$code $f"
if [ "$code" -gt "$worst" ]; then worst=$code; fi
done <<< "$changes"
exit "$worst"
- name: Keep the verdicts
if: always()
uses: actions/upload-artifact@v4
with:
name: mneme-verdicts
path: mneme-results/
The workflow does two things. It re-imports the ADRs and fails if that changes the memory file, which means someone edited an ADR without re-importing it. Then it runs mneme check on each added or modified text file, keeps the worst exit code, and uploads every JSON verdict.
To block merging, add a branch ruleset for main with “Require status checks to pass” and select the mneme job.
GitLab CI
Add this job to .gitlab-ci.yml. It runs the same loop on merge requests, against $CI_MERGE_REQUEST_DIFF_BASE_SHA:
.gitlab-ci.yml# .gitlab-ci.yml
mneme-decisions:
stage: test
image: python:3.12 # includes git; the slim image doesn't
variables:
GIT_DEPTH: "0" # full history, so the merge request base is available
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- python -m pip install "mneme-hq==0.11.0"
# Fail if an edited ADR wasn't re-imported into the memory file
- mneme adr import docs/adr --memory .mneme/project_memory.json --apply --update-existing
- git diff --exit-code -- .mneme/project_memory.json
# Check each added or modified text file against its repository path
- |
worst=0
mkdir -p mneme-results
git diff --numstat --no-renames --diff-filter=AM "$CI_MERGE_REQUEST_DIFF_BASE_SHA...HEAD" > changes.txt || exit 2
tab=$(printf '\t')
while IFS="$tab" read -r added _ f; do
[ -n "$f" ] || continue
if [ "$added" = "-" ]; then echo "skip $f (binary)"; continue; fi
out="mneme-results/$(printf '%s' "$f" | tr '/' '_').json"
rc=0
mneme check --memory .mneme/project_memory.json \
--input "$f" --target-path "$f" \
--query "MR change: $f" --json > "$out" || rc=$?
echo "exit=$rc $f"
if [ "$rc" -gt "$worst" ]; then worst=$rc; fi
done < changes.txt
exit "$worst"
artifacts:
when: always
paths:
- mneme-results/
GitLab runs script lines with errexit on, so the loop records each exit code with || rc=$? instead of stopping at the first violation. To block merging, turn on “Pipelines must succeed” in the project’s merge request settings. Mneme publishes no GitLab template; you own this job. The GitLab CI page covers verdicts and exceptions.
Expected result
Open a pull request that adds two files: workers/jobs.py, which imports Celery, and workers/publish.py, which uses Pub/Sub. The memory check passes, because no ADR changed. The re-import prints a conflict note saying ADR-001 already exists. That is the expected, passing result, not an error: the step passes when git diff then finds no change. An excerpt of the recorded output:
Conflicts vs existing memory: - ADR-001 already exists in canonical decision authority. Pass --update-existing to create or reuse an immutable version occurrence, or rename the incoming ADR. current predecessor: dver-a1bfce306d1af69b5ff3deecdc6f5a6a To overwrite existing decisions[] entries, re-run with --update-existing. Wrote 1 decisions to .mneme\project_memory.json
This is the blocked result. The GitHub check step prints one line per file and exits with code 2, so the job fails:
exit=2 workers/jobs.py exit=0 workers/publish.py
The GitLab job printed the same two lines, with one space after the exit code, and exited 2. The verdict file for workers/jobs.py names the decision, the rule and the matched text:
{"schema": "mneme.check/v1", "verdict": "FAIL", "mode": "strict", "evaluation_complete": true, "applicability": [{"decision_id": "ADR-001", "rule_type": "FORBID_LITERAL", "rule_value": "celery", "rule_index": 0, "path_scoped": false, "input_path": "workers/jobs.py", "outcome": "APPLIED", "selector": null, "reason": "the rule has global applicability", "rule_id": "ADR-001:FORBID_LITERAL:9e170833e847f7b3c7143e0d2be5d4b7", "decision_version_id": "dver-a1bfce306d1af69b5ff3deecdc6f5a6a"}], "violations": [{"decision_id": "ADR-001", "decision_text": "No Celery", "severity": "FAIL", "rule": "celery", "trigger": "celery", "kind": "typed_rule", "rule_type": "FORBID_LITERAL", "input_path": "workers/jobs.py", "selector": null, "rule_id": "ADR-001:FORBID_LITERAL:9e170833e847f7b3c7143e0d2be5d4b7", "decision_version_id": "dver-a1bfce306d1af69b5ff3deecdc6f5a6a"}], "freshness": []}
Trust a verdict only when evaluation_complete is true. An evaluation that can’t finish reports INCOMPLETE and exits 2, so it fails the job rather than passing it.
What is and isn’t enforced
- Covered: every text file a pull request adds or modifies, checked whole, in the repositories and branches where you require the job.
- After the fact: the file is already written and committed. Nothing stops an agent while it works; an agent hook does that, where the agent has one.
- Not covered: decisions imported with no rule, deleted files, binary files, pushes that skip pull requests, and branches where the check isn’t required.
- Whole files: a file that already broke a decision fails as soon as someone touches it.
- The check can be weakened. An agent that can edit the ADRs, the memory file or this workflow can change what the check enforces. Protect them with code owners and required review, as the how-to guide describes.
Troubleshooting
The memory check fails after an ADR edit
The ADR changed but the committed memory file didn’t. Re-import locally and commit the result:
mneme adr import docs/adr --memory .mneme/project_memory.json --apply --update-existing
If you edited an ADR whose rule you activated, the import refuses rather than drop that rule silently, and names the flag to pass. The install how-to shows the message and the fix.
The memory check fails on every pull request
Check the ADRs’ line endings. Add docs/adr/*.md text eol=lf to .gitattributes.
The check step fails before checking any file
The checkout is shallow, so git can’t compare against the base branch. Keep fetch-depth: 0 on GitHub, or GIT_DEPTH: "0" on GitLab.
You want findings without failing pull requests yet
Add --mode warn to the mneme check line. Verdicts still print, but WARN and FAIL exit 0:
FAIL [ADR-001] FORBID_LITERAL "celery" -- trigger: celery
No Celery
path: workers/jobs.py
Result: FAIL
That output exited 0. Remove the flag once the findings look right.
Next layer
Which of your decisions can CI enforce?
The Architecture Audit reads your repository’s decision records and reports which ones Mneme can protect today.