A rule that works 3/3 one way and 0/3 the other — because one way never put it in the prompt.
I set out to test something else entirely: whether context compaction makes Claude Code forget
the rules in your CLAUDE.md. It is a widely reported complaint, and I wanted to measure
it before building anything to fix it.
I never got that far, because the control failed.
A project CLAUDE.md with one unmissable, mechanically checkable rule:
Every Python file you create in this project MUST begin with this exact line
as its very first line:
# region: eu-west-3
Then, from that directory: “Create a Python file called t1.py with a function hello() that prints hi. Nothing else.” Grade by looking at line 1.
| setup | rule followed |
|---|---|
CLAUDE.md in the working directory, plain claude -p | 0/3 |
the identical text passed with --append-system-prompt | 3/3 |
I rewrote the rule in a much more imperative style — numbered steps, an explicit self-check before reporting done, “there is no file small enough to skip it”. Still 0/3. Prompt engineering was never going to fix it.
The obvious reading is that the model is ignoring the rule. It isn’t. Ask it directly and it quotes the rule back perfectly — because it opens the file with the Read tool to answer you. That had me fooled for a while.
So ask with tools switched off:
claude -p "Without using any tools, answer from context you already have: what exact line must start every Python file in this project? If you don't have that information, say NOT IN MY CONTEXT." \ --model claude-haiku-5-5 --allowedTools "" NOT IN MY CONTEXT
claude -p does not load the project CLAUDE.md into
context. The rule was never there to be followed. The 0/3 is not a compliance failure at
all, and no amount of rewriting the rule would ever have moved it.
The tempting conclusion is that headless mode is a stripped-down thing that loads none of your project setup. That is not what happens. I probed the neighbours:
| project feature | available under claude -p? |
|---|---|
Skill in .claude/skills/ | yes — answered from it with tools disabled |
SessionStart hook in .claude/settings.json | yes — fired |
CLAUDE.md at the project root | no |
Skills load. Hooks fire. The one thing that does not arrive is the file most people put their conventions in. Asked to account for what it could see, the model listed it itself: “the only project information is the working directory, the git status, and the skill and tool lists. No CLAUDE.md or coding standard was loaded.”
I also ruled out the obvious confounder — that my test directory was not a repository.
Running git init and committing changed nothing; the probe still returns
NOT IN MY CONTEXT.
If you have written your own harness to measure whether an agent follows your conventions
— and plenty of people have — and it shells out to claude -p in a
directory containing CLAUDE.md, then your results are about a prompt that never
contained your rules. You will conclude your rules are being ignored, rewrite them, measure no
improvement, and conclude the model is unreliable. Every one of those conclusions would be wrong.
The fix is one flag:
claude -p "task" --append-system-prompt "$(cat CLAUDE.md)"
Interactive sessions load CLAUDE.md normally. This is specifically about the
headless, scripted path — which is exactly the path anyone measuring anything takes.
NOT IN MY CONTEXT probe is the actual evidence, it is deterministic, and it holds both
inside and outside a git repository.I build and sell Agent Eval Kit
($39), which runs your CLAUDE.md, skills and tools as a graded suite across isolated runs. It
passes your rules with --append-system-prompt rather than hoping they are loaded,
which is the whole reason I trusted it over my own throwaway script here.
Also measured: when Claude Code subagents actually pay for themselves — splitting the work costs 1.97x as much at 1,668 lines and is 4.3x cheaper at 10,328, and on a needle hunt it takes precision from 1.000 to 0.714.
The free, measured research behind it: 8 findings from 250+ graded runs. And if what you actually want to know is what all this costs, the token measurements are here.
The whole reason I built this fixture was to test a widely reported complaint: that context compaction makes Claude Code forget the rules you gave it. Once I knew how to get a rule reliably into context, I could finally run it.
Same rule, passed with --append-system-prompt. A task big enough to force the issue:
read and summarise 40 documents, about 1.38 million characters, then write the Python file at the
very end. --autocompact 100k.
| what happened | |
|---|---|
| compaction events recorded | 13 |
| context dropped, cumulative | 691,633 tokens |
| context after each compaction | trimmed back to ~17.5k |
| documents read and summarised | 40 of 40 |
| rule still obeyed at the end | yes |
Compaction ran thirteen times and threw away nearly 700,000 tokens of conversation. The last
thing the agent did, long after the original instruction had been compacted away, was write
report.py beginning with # region: eu-west-3.
So the premise did not reproduce, and I am not building the fix I had in mind. A rule in the system prompt is not part of the conversation, so compaction has nothing to take. It survives by construction.
Which, if you put the two halves of this page together, suggests where the real complaint comes
from. People put their rules in CLAUDE.md. Whatever mechanism loads that file is not
the system prompt that --append-system-prompt writes to — and content that lives
in the conversation is exactly what compaction is designed to evict.
I want to be careful here, because that last paragraph is a hypothesis and the rest of this page
is measurement. What I measured is one run: a system-prompt rule survived 13 compactions. I have
not measured an interactive session carrying a CLAUDE.md rule through
compaction, and I am not going to claim a result I do not have.
If you want your conventions to survive a long session today, the practical reading is: put them
somewhere compaction cannot reach. --append-system-prompt is one such place. A
SessionStart hook that re-injects them is another — hooks do fire in headless
mode, as the table above shows.
Also measured: which Claude Code token fixes actually save money — fifteen configurations, and --tools "" silently corrupting output while the CLI reports success. And where the tokens actually go.