Running into this?

My CLAUDE.md has grown to hundreds of lines; I don't know which lines still change what the agent does, and I'm afraid to delete any

I don't keep a line on gut feeling: I write a short scene that asks for the move the line is supposed to change, run the same scene a few times with a context-free agent against the file with and without the line, and count the right moves. If the agent makes the same move without the line, the line goes; if the move drops without it, the line stays.

beforerule file loaded on every task: 181,567 bytes
after159,361 bytes · agent's right moves 32/32 → 32/32
before deleting a line from CLAUDE.md, run the same scene three times against a copy with the line and a copy without it; if the copy without it gets the same move, delete it
Text for your agent · 28 lines
Situation: your CLAUDE.md has grown to hundreds of lines. You don't know which lines still change what the agent does and which ones just repeat something the model already does; when a new model comes out, the same question comes back.

Why: CLAUDE.md is read in full at the start of every session; every line takes up context on every request and competes with the other lines for attention. A line that says something the model already does changes no move. Whether a line is needed also depends on the model reading it: you find out by counting with that model, not by guessing. In my setup (Nov 16), 129 quote lines came out of the rule file loaded on every task: 181,567 → 159,361 bytes, and the context-free reader's (Opus) right moves on four distinguishing scenes went 32/32 → 32/32. The same day, 3 of the 27 lines I meant to remove stayed: without them the right move dropped from 3/3 to 1/3.

Do (one line at a time; every claude -p is a model call, 6 calls per line):
1. Pick a single line and find its number (grep -n 'use only pnpm' CLAUDE.md). Don't cut the whole file at once.
2. Write a scene that asks for the move the line should change, force the answer onto one line, and write the start of the right move as a pattern. Example, for the line "use only pnpm to install packages":
   S='Add the lodash dependency to this project. Do not run any command or touch any file. Answer in one line: the command you would run, no explanation.'
   D='^`?pnpm add'
3. From the project root, set up two copies in an empty temp folder: one with the line, one without. N is the single number of the line to remove:
   N=7
   B=$(mktemp -d); mkdir "$B/with" "$B/without"
   cp CLAUDE.md "$B/with/CLAUDE.md"
   sed "${N}d" CLAUDE.md > "$B/without/CLAUDE.md"
   If CLAUDE.md imports other files with @, copy them to the same path in both folders. The diff below must print exactly two lines: "7d6" (for N=7) and under it "< " followed by the line you meant to remove; if it's empty or longer, N is wrong, don't go to step 4:
   diff "$B/with/CLAUDE.md" "$B/without/CLAUDE.md"
4. Run the same scene three times in each copy and count (S, D and B from steps 2 and 3 must be defined in the same shell):
   for d in with without; do for i in 1 2 3; do (cd "$B/$d" && claude -p "$S") > "$B/$d-$i.txt" 2>&1; done; done
   grep -H . "$B"/with-*.txt "$B"/without-*.txt; echo "with $(grep -lE "$D" "$B"/with-*.txt | wc -l | tr -d ' ') / 3 · without $(grep -lE "$D" "$B"/without-*.txt | wc -l | tr -d ' ') / 3"
5. First read the printed answers: if D misses a right answer or counts a wrong one, fix D and rerun only the last line of step 4. Then take the first rule from the top that matches:
   without 3/3 → delete it · with 0/3 or 1/3 → the line doesn't work as text: move it into a hook that denies the wrong command · any other count → keep it.
6. Once you've deleted a line, measure the next one against the file without it: whether a line is needed depends on the rest of the file (in my setup, with "Run `pnpm test` for tests." still in the file, the agent wrote pnpm add 3/3 after the pnpm line was deleted).

Check: first see the method tell a known line apart: under a new B=$(mktemp -d), write only "In this project, use only pnpm to install packages." into with/CLAUDE.md, leave without/CLAUDE.md empty, and run step 4 with the S and D from step 2 → with 3/3 · without 0/3 (in my setup on Claude Code 2.1.325); don't move on to real lines until you get it.

Don't:
- Don't cut the whole file at once and measure: you can't tell which line the dropped move came from (in my setup, removing 27 lines at once dropped the move in three scenes).
- Don't delete a line someone explicitly asked for on the count alone: ask that person first.