Turn Infrastructure Decisions into Text Rules for AI-Written Terraform and Kubernetes Files
Write the decision once, as an Architecture Decision Record (ADR). Mneme fails a Terraform or Kubernetes change that adds the exact text the decision forbids, before Claude Code’s Edit, Write or MultiEdit tool writes it to disk, and checks the whole file again in CI. It matches text, not infrastructure meaning.
A coding agent opens the port your ADR keeps closed.
Your platform team has already made the calls. Security groups name a known address range. Databases stay in private subnets. Buckets carry no public access control list (ACL). Application pods run unprivileged on the cluster network. Those decisions sit in ADRs, a wiki page or a senior engineer’s head.
A coding agent asked to open Secure Shell (SSH) access to the bastion host works from the files in front of it. The shortest working answer is a security group rule with cidr_blocks = ["0.0.0.0/0"]. A reviewer may catch it, and a policy engine in the pipeline may catch it later. Mneme can fail it as the agent writes the file.
type = "ingress"
from_port = 22
cidr_blocks = ["0.0.0.0/0"]
...
}
No ingress open to the whole internet
path: infra/network/bastion_sg.tf via infra/**
Result: FAIL
What each layer inspects, and what Mneme adds.
Conftest or Checkov, cloud and cluster controls and code review each answer a different question.
| Layer | What it inspects | What Mneme adds |
|---|---|---|
| Conftest and Checkov | Parsed configuration. Conftest runs Rego policies against formats including HCL and YAML. Checkov scans infrastructure as code for misconfigurations, including Terraform plans and Kubernetes manifests. | A narrower, earlier check: exact text your team chose, before Claude Code writes the file and on the pull request. No parsing and no resource model. |
| Cloud and cluster controls | What the account or cluster allows when a change is applied and while it runs. | Nothing at apply time or runtime. Mneme never reads an account, a cluster or Terraform state. |
| Code review | The diff, with a person judging what a change exposes. Coverage depends on the reviewer knowing each decision. | Exact-text rules on every checked change: before a Claude Code Edit, Write or MultiEdit, and on the pull request in CI. |
Mneme matches text you name, and each failure names the ADR that forbids it. Conftest evaluates the parsed configuration, and cloud and cluster controls decide what runs. Keep all three.
From an infrastructure ADR to a failing check.
Install the Python package and command-line interface (CLI) with pipx install "mneme-hq==0.11.0", as the quickstart shows. Set up Mneme with Claude Code to add the hook.
Write the decision as an ADR with a Constraints section
An ADR here is a Markdown file with YAML frontmatter. Under ## Constraints, name the exact text to forbid and the paths where the ban applies. Put the value in single quotes when it contains a colon or double quotes, as 'privileged: true' and '"public-read"' do. Scope names take lowercase letters, digits and underscores, separated by dots: the importer accepts infrastructure.network_ingress and refuses infrastructure.network-ingress.
Compile it with mneme adr import
Create the memory file once with mneme init --path .mneme/project_memory.json, then run mneme adr import docs/adr --memory .mneme/project_memory.json --apply. Keep the file at exactly that path, with .mneme/ at the repository root: path-scoped rules resolve paths such as infra/** against the folder that holds .mneme/.
Check agent writes in the Claude Code hook
The hook runs before Claude Code’s Edit, Write and MultiEdit tools change a file. In strict mode, its default, it refuses a write that produces WARN or FAIL. Its pre-write check sees only the text an edit adds, while CI checks whole files. A forbidden string already in a file therefore passes the hook on an unrelated edit and fails in CI.
Gate the pull request in CI
Run mneme check --memory .mneme/project_memory.json --input <file> --query "<change>" --mode strict on each changed .tf, .tfvars and manifest file. --query is a short description of the change that Mneme uses to pick which decisions to retrieve. Path-scoped literal rules run whatever it says, so a fixed description such as “infrastructure changes” will do.
Strict mode exits 0 on PASS, 1 on WARN and 2 on FAIL, so a violation fails the job. Warn mode exits 0 on PASS, WARN and FAIL, including a printed Result: FAIL, but still exits 2 on Result: INCOMPLETE or an error. If the same memory file also holds a FORBID_NUMERIC_ABOVE rule, an --input check without --target-path, or one whose target falls inside that rule’s paths, is reported as incomplete and exits 2, even in warn mode. The CI how-to guide has a workflow.
Infrastructure rules, run on mneme-hq 0.11.0.
Everything below comes from mneme-hq 0.11.0, run in a clean virtual environment on 1 December 2026, against a small repository with Terraform under infra/ and Kubernetes manifests under k8s/. We shortened the path to the mneme executable and dropped the working-directory prefix and output separators. Path-scoped literal rules ignore the --query text: the ingress violation below also fails with --query "update the readme".
1. No ingress open to the whole internet
ADR-301 forbids the text 0.0.0.0/0, and only under infra/.
--- id: ADR-301 title: No ingress open to the whole internet status: accepted priority: foundational date: 2026-12-01 scope: infrastructure.network_ingress supersedes: [] --- Security group rules in Terraform name a known CIDR range. Public entry goes through the load balancer module, which the platform team owns. ## Constraints - FORBID_LITERAL: value: '0.0.0.0/0' include_paths: - "infra/**"
$ mneme check --memory .mneme/project_memory.json --input infra/network/bastion_sg.tf --query "terraform security group ingress for the bastion" --mode strict FAIL [ADR-301] FORBID_LITERAL "0.0.0.0/0" -- trigger: 0.0.0.0/0 No ingress open to the whole internet path: infra/network/bastion_sg.tf via infra/** PATH APPLIED [ADR-301] infra/network/bastion_sg.tf via infra/** -- an include selector matched PATH APPLIED [ADR-302] infra/network/bastion_sg.tf via infra/** -- an include selector matched PATH APPLIED [ADR-303] infra/network/bastion_sg.tf via infra/** -- an include selector matched PATH EXCLUDED [ADR-304] infra/network/bastion_sg.tf -- no include selector matched PATH EXCLUDED [ADR-305] infra/network/bastion_sg.tf -- no include selector matched Result: FAIL
PATH APPLIED means the file’s path matched the rule’s include_paths, so Mneme evaluated the rule. PATH EXCLUDED means it did not, so Mneme skipped the rule. The same rule with ["10.20.0.0/16"] passes, and a runbook under docs/ that quotes 0.0.0.0/0 passes with every path-scoped rule excluded. In warn mode the failing file still prints Result: FAIL, but the command exits 0.
This is exact text matching, and Terraform offers many ways to reach the same address. In the same run, each of these passed:
cidr_blocks = [var.ssh_ingress_cidr], with"0.0.0.0/0"set inenvs/prod.tfvars, a path outsideinfra/**- the IPv6 form,
ipv6_cidr_blocks = ["::/0"] - a module input built with
join("/", ["0.0.0.0", "0"])
Add envs/** to the rule’s paths and a second constraint for ::/0 to cover the first two. Nothing in Mneme follows a function or a module, so no Mneme rule catches the third.
2. No public-read buckets, and why spaces matter
ADR-303 first forbade acl = "public-read" under infra/. It failed a bucket ACL written with one space. It passed the same resource in the layout terraform fmt produces, which pads the space before = so a block lines up: acl = "public-read".
$ mneme check --memory .mneme/project_memory.json --input infra/storage/assets_bucket_fmt.tf --query "s3 bucket acl for static assets" PATH APPLIED [ADR-303] infra/storage/assets_bucket_fmt.tf via infra/** -- an include selector matched PATH APPLIED [ADR-301] infra/storage/assets_bucket_fmt.tf via infra/** -- an include selector matched PATH APPLIED [ADR-302] infra/storage/assets_bucket_fmt.tf via infra/** -- an include selector matched PATH EXCLUDED [ADR-304] infra/storage/assets_bucket_fmt.tf -- no include selector matched PATH EXCLUDED [ADR-305] infra/storage/assets_bucket_fmt.tf -- no include selector matched Result: PASS
Rewritten to forbid "public-read", quotes included and no spaces, the rule failed both layouts:
$ mneme check --memory .mneme/project_memory.json --input infra/storage/assets_bucket_fmt.tf --query "s3 bucket acl" FAIL [ADR-303] FORBID_LITERAL ""public-read"" -- trigger: "public-read" No public-read bucket ACLs path: infra/storage/assets_bucket_fmt.tf via infra/** PATH APPLIED [ADR-303] infra/storage/assets_bucket_fmt.tf via infra/** -- an include selector matched Result: FAIL
Pick a value with no spaces in it whenever the forbidden setting allows one. Some do not. A rule for publicly_accessible = true failed a database instance where that key was the longest in its block, so terraform fmt left one space, and passed one where a longer key padded it. = true on its own appears everywhere, so there is no safe spaceless version. A rule like that catches a setting written with one space before the = and misses it once terraform fmt pads the line.
3. No privileged containers in Kubernetes manifests
ADR-304 forbids privileged: true under k8s/, and ADR-305 forbids hostNetwork: true there. Each failed a manifest that set it in the usual block style. The ADR-304 run:
$ mneme check --memory .mneme/project_memory.json --input k8s/apps/worker.yaml --query "kubernetes deployment for the worker" --mode strict FAIL [ADR-304] FORBID_LITERAL "privileged: true" -- trigger: privileged: true No privileged containers path: k8s/apps/worker.yaml via k8s/** PATH EXCLUDED [ADR-301] k8s/apps/worker.yaml -- no include selector matched PATH EXCLUDED [ADR-302] k8s/apps/worker.yaml -- no include selector matched PATH EXCLUDED [ADR-303] k8s/apps/worker.yaml -- no include selector matched PATH APPLIED [ADR-304] k8s/apps/worker.yaml via k8s/** -- an include selector matched PATH APPLIED [ADR-305] k8s/apps/worker.yaml via k8s/** -- an include selector matched Result: FAIL
YAML flow style, securityContext: {privileged: true}, also failed, because the same text is in the file. These passed: privileged: true with two spaces, a quoted key "privileged": true, the same container written as a JSON Pod manifest, and a Helm template that sets privileged: {{ .Values.worker.privileged }}. The identical manifest under platform/ passed with every path-scoped rule excluded, which is how a platform team keeps its own node agents out of an application rule.
4. The Claude Code hook blocks the write
We sent the hook the Write events Claude Code would send. It blocked a new security group rule with ["0.0.0.0/0"] and exited 2, so the file was never written:
mneme: FAIL - architectural decision violated
[ADR-301] FAIL "0.0.0.0/0" - trigger: 0.0.0.0/0
No ingress open to the whole internet
path: infra/network/edge_sg.tf via infra/**
It blocked the privileged Deployment written to k8s/apps/batch.yaml the same way. The compliant security group rule, the same Deployment written to platform/node-agents/, and a database instance with a padded publicly_accessible = true all went through with exit code 0.
5. Provider names and numeric limits
A FORBID_DEPENDENCY constraint for digitalocean/digitalocean imported as a plain constraint, no digitalocean/digitalocean. It returned WARN, strict exit 1, on a required_providers block that lists the provider, with the trigger digitalocean. It also warned on a Markdown note under docs/ that mentions the word, because this rule kind has no path scope, and it passed the provider block when the query was “update the readme”. The hook blocked the provider block on its WARN. Use it as a broad word flag.
FORBID_NUMERIC_ABOVE cannot read Terraform. The importer refused language: hcl (“must be exactly 'python'”), and --source-file refused a .tf file. A numeric rule scoped to infra/** made an --input check of a .tf file return Result: INCOMPLETE with exit code 2, in strict and warn mode alike. Scoping the rule elsewhere is not enough: while the memory file holds any numeric rule, an --input check without --target-path is reported as incomplete and exits 2 too. Keep numeric rules on Python paths, and when you check infrastructure files pass --target-path with the file’s path.
What Mneme checks, and what it does not.
| Concern | mneme-hq 0.11.0 | Detail |
|---|---|---|
| Exact text in named paths (FORBID_LITERAL) | Checked: FAIL | Case-sensitive match in a .tf, .tfvars, .yaml or other text file, limited to the paths the rule lists |
| Where checks run | Command line, Claude Code hook, CI | On code changes: mneme check by hand or as a CI step; the hook covers Claude Code’s Edit, Write and MultiEdit tools |
| HCL and YAML meaning | Not checked | No parsing. Spacing, quoted keys, JSON manifests and Helm templates change the text and pass |
| Variables, modules, functions | Not checked | A value set through var., a module input or join() is never resolved |
| Terraform plans and state | Not checked | Mneme reads files in the repository, not plan output or state |
| Infrastructure and network policy | Not enforced | Mneme does not enforce infrastructure or network policy. Use cloud and cluster controls |
| Policy-engine coverage | Not provided | No resource model; keep Conftest, Checkov or another policy tool |
| Provider or package name (FORBID_DEPENDENCY) | Checked: WARN | Word match on any part of the name, no path scope; a name of several words runs only when retrieval selects the decision |
| Numeric limits (FORBID_NUMERIC_ABOVE) | Not for IaC | Python files only, in CI with --source-file; a .tf file is refused |
| Audit log of violations | Not kept | mneme check prints and exits; keep its --json output in CI if you need a record |
The full list of policy shapes, and which need richer rule types, is on governance policies enforced today.
Common questions.
Does Mneme understand Terraform or Kubernetes?
.tf or .yaml file as text and looks for the exact string a rule names. It does not know what a security group, a bucket or a pod is, and it does not follow a variable, a module or a function call to the value it produces.Does Mneme replace Conftest, Checkov or Open Policy Agent?
Does Mneme stop an insecure change from being applied?
terraform apply or kubectl apply, read cloud accounts or clusters, or enforce infrastructure or network policy.Why does terraform fmt matter for these rules?
terraform fmt pads the space before = so the values in a block line up. A rule for acl = "public-read" with one space passed a file that had acl = "public-read". Forbid a string with no spaces in it, such as "public-read" or 0.0.0.0/0, and the layout stops mattering for that rule. Some settings have no safe spaceless form: publicly_accessible = true is one.Can Mneme cap a number in a Terraform file?
.tf file given to --source-file is refused, and while the memory file holds any numeric rule, an --input check of a Terraform file is reported as incomplete and exits 2, even in warn mode, unless --target-path names the file and the rule’s paths do not cover it. Keep numeric rules on Python paths and pass --target-path in CI.