
The Audit That Changed What It Measured
A check that shells out to the tool it audits can set off that tool's one-time migration, so measure before the first call that can write.
View companion repoMy audit deleted the key it was checking for
My setup audit ran claude plugin list --json, and that one call removed a key from ~/.claude/settings.json. The audit then ran diff.sh, saw the key missing, and scored gate G7 as FAIL. The agent that fixed it summed it up this way: "diff.sh then saw the key missing and G7 flipped to FAIL, so the audit was changing the thing it measures."
I had dispatched that agent with a brief that offered one explanation: the key might be obsolete, and the CLI might no longer recognise it. That was the wrong reading. The key was live in the Claude Code binary. The deletion was a one-time startup migration, and it fired only on a home whose ~/.claude.json had never been migrated. My real home was already migrated. The defect could only be seen in a fake home, and the first attempt to reproduce it there failed.
The repo is cc-setup, which holds my Claude Code configuration. install.sh writes ~/.claude/settings.json from a template. diff.sh compares what install would write with what is live, and exits 0 only when they match. bin/setup-audit scores the whole setup against goals G1 to G11. The G7 row is the diff check, and a passing row looks like this in the audit's own table:
| G7 | diff.sh exit 0 | exit 0 | PASS |
The template carries skipAutoPermissionPrompt: true and also sets "defaultMode": "acceptEdits". That combination turned out to matter.
It had already shown up once, as a guess
The first sighting was the day before, in a lane agent's report on the install and sync commands. The report had a section headed "ONE OBSERVATION, NOT REPRODUCED":
Between that fake-home install and the restore, ~/.claude/settings.json in the fake home lost the template key
skipAutoPermissionPrompt: true. The restore put it back.
It went on: "I ran both again by hand, and diff.sh stayed at exit 0 each time." Then it guessed at the mechanism, and the guess was right: "My guess is a first-run migration by the claude CLI in a fresh home. If Claude Code itself rewrites that key on a real start, G7 (diff.sh exit 0) would drift after P2. Worth one look in the P2 gate session."
That became one line in a runbook: "Also check whether Claude Code rewrote any settings key on start (diff.sh again; lane B saw skipAutoPermissionPrompt vanish once)." It was a to-do. In the sessions I read, the next appearance of the key came from a reviewer who was working on something else.
A reviewer tripped over it
I had asked that reviewer to judge a commit that moved some diff.sh output onto stderr. The concern I passed along was that "moving output off the measured channel keeps G7 green while live state really differs from the repo". The reviewer was checking my G7 for gaming. While running the audit in a scratch home, it saw G7 fail for a reason that had nothing to do with the commit:
G7 shows FAIL here because of an unrelated settings key (
skipAutoPermissionPrompt), not the stderr notes. I'll check whether the audit itself caused that drift:diff.shwas exit 0 just before.
The check was a before-and-after around a single CLI call in a fake home:
before exit=0
plugin list rc=0
~/.claude/settings.json: skipAutoPermissionPrompt: missing live (install adds it)
after exit=1
A clean home gave the same pair: key count 1 and exit 0 after install, key count 0 and exit 1 after the CLI call.
The reviewer's report put it in one paragraph: "Separate G7 hazard: in fake homes, claude plugin list --json (which setup-audit runs for G8) deleted skipAutoPermissionPrompt from settings.json. diff.sh then showed it as missing, so G7 went from exit 0 to exit 1. I did not test this against the real home."
The next brief carried that caveat forward and labeled the defect "UNVERIFIED on the real home".
The brief, and the reproduction that did not reproduce
I wrote the brief to the fix agent. Step 1 ended in a question: "Find the root cause: does the CLI drop the key because 2.1.310 no longer recognises it (look for its handling in the claude binary's strings or the settings schema at https://json.schemastore.org/claude-code-settings.json, and in claude --help/docs), or for another reason?"
Step 2 shows where I expected it to land: "If the key is obsolete or rewritten by the CLI, the template should match what the CLI keeps (say which, with evidence), so install and the CLI agree." Had the answer been "obsolete", the instruction was to change the template. I think that path ends with a passing audit and an unexplained migration still sitting in the binary.
The agent built a fake home under /private/tmp from copies of the live files, ran install, and checked the baseline: "Baseline is clean (diff.sh exit 0). Now reproducing: run setup-audit --quick, then diff.sh." The audit gave G7 PASS. Its next message: "Did not reproduce on the first try. Checking whether the CLI call actually ran and touched settings."
It compared the settings file before and after the audit. The output was settings unchanged followed by three empty lists, for keys removed, added and changed. "The audit left settings byte-identical here. Running the CLI directly and grepping the binary for the key."
The first search of the binary printed a regex error from the grep tool, and the output file had 0 lines. A count of 0 would read as the CLI having no handling for this key, which is the obsolete answer. That 0 was a tool failure, and the next search, with /usr/bin/grep -a, found 5 lines. The published schema did lack the key (in schema: False null), but the binary carried it twice that mattered, once in a list of settings paths and once in the settings shape:
{path:["skipAutoPermissionPrompt"],restrictive:!1}
skipAutoPermissionPrompt:M().optional().describe("Whether the user has accepted the auto mode opt-in dialog")
The agent's report later put the verdict plainly: "The key is not obsolete. 2.1.310 still reads skipAutoPermissionPrompt in its autoMode settings shape ("Whether the user has accepted the auto mode opt-in dialog") and in the auto-mode entry warning check. It is missing from the schemastore schema, but the binary is what decides."
Two gates stood between the CLI and the deletion
The binary also held the code that deletes the key. A reviewer later pulled the same function out independently, trimmed:
async function Ut(e){if(ue().hasResetAutoModeOptInForDefaultOffer)return!0;if(Ogo()!=="enabled")return!0;
try{let s=fe("userSettings");if(s?.skipAutoPermissionPrompt&&s?.permissions?.defaultMode!=="auto"){
...Un("userSettings",{skipAutoPermissionPrompt:void 0}...g("migration_reset_auto_mode_opt_in")}
Re(n=>...{...n,hasResetAutoModeOptInForDefaultOffer:!0})
In order: return early if the flag hasResetAutoModeOptInForDefaultOffer is already set in ~/.claude.json, return early unless a feature check says "enabled", and otherwise, if the key is truthy and defaultMode is not "auto", write the user settings with the key set to undefined. Then set the flag. The template uses acceptEdits, so a fresh home met the condition.
My real home did not. The agent read two values from its ~/.claude.json: migrationVersion: 14 and hasResetAutoModeOptInForDefaultOffer: True. That explained the failed reproduction. "The live ~/.claude.json already carries hasResetAutoModeOptInForDefaultOffer: true, which explains why my copy didn't fire. Removing that flag in the fake home to trigger the migration."
Removing the flag did nothing. Every probe command left the key in place. The agent's next message: "No command fired the migration with only the flag removed. The binary showed if(ue().migrationVersion===je)return, so migrations may also be gated by migrationVersion. Reading more of that code."
It removed migrationVersion as well and reran the same probes, resetting the fake home before each one:
version rc=0 settings.skipAutoPermissionPrompt=present claude.json.hasResetAutoModeOptInForDefaultOffer=None
help rc=0 settings.skipAutoPermissionPrompt=present claude.json.hasResetAutoModeOptInForDefaultOffer=None
plugin-list rc=0 settings.skipAutoPermissionPrompt=MISSING claude.json.hasResetAutoModeOptInForDefaultOffer=True
plugin-disable rc=0 settings.skipAutoPermissionPrompt=MISSING claude.json.hasResetAutoModeOptInForDefaultOffer=True
mcp-list rc=0 settings.skipAutoPermissionPrompt=MISSING claude.json.hasResetAutoModeOptInForDefaultOffer=True
mcp-get rc=0 settings.skipAutoPermissionPrompt=MISSING claude.json.hasResetAutoModeOptInForDefaultOffer=True
--version and --help left the key alone. Four commands that read like inspection, plugin list, plugin disable, mcp list and mcp get, each deleted it. Two controls closed the picture. With defaultMode set to auto, plugin list kept the key. And after one migrating run, putting the key back stuck: "second run: key present migrationVersion 14".
With that state, the failure reproduced through the audit itself, on the unfixed code:
pre-audit diff rc=0
audit rc=0
| G7 | diff.sh exit 1 | exit 0 | FAIL |
~/.claude/settings.json: skipAutoPermissionPrompt: missing live (install adds it)
diff.sh had exited 0 before the audit and reported the key missing after it.
The fix is a reorder, and it has a gap
setup-audit has exactly one claude call, plugin_list(). The fix moves run_diff() ahead of it. The diff adds two lines and removes one:
+ # Before any `claude` call: the CLI's first-run migration can delete settings keys that diff.sh checks.
+ code, diff_out, diff_note = run_diff()
plugins = plugin_list()
@@ -514,7 +516,6 @@ def build_report(args):
rows["G6"] = (f"cleanupPeriodDays {cleanup}", "365", verdict(cleanup == 365))
- code, diff_out, diff_note = run_diff()
if code is None:
The agent did not touch the template: "I left the template as is. The CLI keeps the key once a home is migrated, and the real home is migrated."
For proof it ran install, then setup-audit --quick, then diff.sh, in a fake home with no migrationVersion:
== S2 fresh ~/.claude.json (no migrationVersion), fixed code
s2-1 audit rc=0 | G7 | diff.sh exit 0 | exit 0 | PASS |
s2-1 diff rc=1
~/.claude/settings.json: skipAutoPermissionPrompt: missing live (install adds it)
s2-2 audit rc=0 | G7 | diff.sh exit 0 | exit 0 | PASS |
s2-2 diff rc=0
s2-3 audit rc=0 | G7 | diff.sh exit 0 | exit 0 | PASS |
s2-3 diff rc=0
Two more cycles used a copy of the real, migrated ~/.claude.json, and both read G7 PASS with diff.sh exit 0. That is five audit runs with G7 PASS, and four of them followed by a clean diff.sh.
The fifth is the first line of that block. The agent named it: "That first unmigrated cycle is the remaining gap. The audit itself is now correct, but its own plugin list still triggers the one-time migration after the measurement."
On the real home it ran only read-only checks, and the checksums of ~/.claude/settings.json and ~/.claude.json matched before and after. It also wrote: "I did not run setup-audit against the real home."
The agent's first report, with a table and the word "fixed" in it, was bounced by a Stop hook: "this turn changed files and claims "fixed" but cites no evidence from this run." The second message pasted the transcripts above and named what was still unverified: "no independent reviewer has looked at 3070d22 yet."
What the second reviewer added
A different agent reviewed the commit with four claims to check: the migration mechanism, which commands trigger it, the state of the real home, and whether the reorder changed anything else in the G7 row. It pulled the function from the binary itself, read only two key names from the real ~/.claude.json, and ran its own before-and-after in a fresh home. All four claims were confirmed. It added a caveat the fix agent had not reported, though the same Ogo()!=="enabled" check sits in the code above:
Caveat: the migration only runs when
Ogo()returns "enabled". That value comes from the server-side feature flagtengu_auto_mode_config.enabled, so it is remotely controlled.
It also noted: "It does mean the failure could vary by account or time." So the deletion depends on a state in ~/.claude.json and on a flag I do not control.
Its table matched the fix agent's, with one line I now treat as the main finding. In both the before and after runs, the audit's plugin list call removed the key and set migrationVersion=14. In the old code, G7 read FAIL. In the new code, G7 read PASS, and a diff.sh run afterwards still exited 1. The reviewer wrote: "The reorder doesn't prevent the deletion. It makes G7 read the state before the deletion."
Its judgment, outside the four claims, is the sentence I would have missed: "On an unmigrated home, G7 now reads PASS while the audit itself leaves the home without the key." And the warning that goes with it: "Anyone who reads G7 PASS as "home unchanged by the audit" would be wrong on an unmigrated home."
I merged the branch with the review verdict in the commit message, and added an item to my action list: "Claude Code drops skipAutoPermissionPrompt once, on a server flag (G7 note)." It ends with "Steps: none. Switching defaultMode to auto (decisions memo, item 8) also makes the migration a no-op on a fresh machine." The record I read leaves that switch as an option. It does not say whether I took it.
The rule
An audit that runs the tool it audits is part of the system under test. Before it runs the first command that could write, it takes every measurement that command could disturb. That includes commands that read as inspection. plugin list and mcp list look like reads, and on a fresh home they ran a migration.
A PASS from that order means the state before the audit looked right. It does not mean the audit left the state alone. Say which one the row proves. On the unmigrated home, the honest report is a G7 PASS plus a known drift afterwards, and that is what the record gave me.
Reproduce in the state the bug needs. The first fake home was a copy of a migrated one, so the migration never ran, and the audit passed. Two flags in a file the CLI owns decided whether the bug existed. Before a fix touches the template, the tool's own binary should answer whether the behavior is persistent or one-shot. That answer took a trimmed 4-line function and a before-and-after on a clean home.
Continue the series
- 83SeriesThe Scanner That Passed Its Own ExamA score on the corpus a detector was tuned against measures the tuning, so each review needs a corpus nobody has tuned against.
- 85SeriesThe Session That Edited Its Own HomeA builder that shares a config directory with the setup it rewrites is a tenant of that setup, and a check against an empty directory proves nothing.
- 82SeriesThe Anchor Taken After the CutA template matched across a content cut measures how alike two pieces of footage look, and only the confidence score says so.
- 86SeriesThe Normalizer That Ate Approved RowsA duplicate check must apply the same normalization as the code it is clearing, or approved rows stay hidden.