Skip to content

fix(bin): treat Claude Code's default external-imports flags as never asked, not declined - #4387

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
Rangezi:fix/claude-trust-default-import-flags
Sep 14, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
Rangezi:fix/claude-trust-default-import-flags

Conversation

@Rangezi

@Rangezi Rangezi commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Intent

Upstream fix for #4378, which the maintainer's triage bot confirmed and labeled ready-for-pr (patch in the issue is evidence, not a merge). bin/fm-claude-trust.sh refuses the whole Claude trust registration when the project-root entry in ~/.claude.json has hasClaudeMdExternalIncludesApproved === false, assuming Claude Code writes false only on an explicit 'No, disable'. In Claude Code 2.1.270 the default project entry carries Approved and WarningShown both false before the dialog is ever shown, and the dialog writes WarningShown: true for either answer; on the reporter's machine this refused spawns in 7 of 10 registered projects. Deliberate decision: only Approved === false together with WarningShown === true is a decline; false/false (never asked) must behave exactly like an absent flag — trust registered, no import consent manufactured, so a CLAUDE.md that really imports external files still stops on the dialog. Scope is intentionally narrow: correct the decline predicate and its comment block only, no new trust surface, no change to worktree-mode import-flag handling. The new test test_project_root_entry_default_import_flags_are_not_a_decline seeds Claude Code's default entry shape and expects exit 0 with trust only; it fails on b182d0f with the refusal and passes with the fix, and the existing decline fixture (false/true shape) must stay green. tests/fm-claude-trust.test.sh passes 31/31 locally and bin/fm-lint.sh is clean with pinned ShellCheck 0.11.0 and actionlint 1.7.12. The PR should close #4378.

What Changed

  • bin/fm-claude-trust.sh: declinedExternalImports now counts a decline only when hasClaudeMdExternalIncludesApproved === false and hasClaudeMdExternalIncludesWarningShown === true. Claude Code's default project entry has both flags set to false, and the script used to read that as a decline and refuse registration. That false/false shape now behaves like an absent flag: trust gets registered, no import consent is written, and the import dialog still shows. The header comment and the inline comments now describe the new rule.
  • tests/fm-claude-trust.test.sh: new test test_project_root_entry_default_import_flags_are_not_a_decline. It seeds Claude Code's default project entry shape and expects exit 0, with trust but no import consent on both the worktree entry and the project-root entry. The comment on the existing decline test now names the false/true pair.
  • .agents/skills/harness-adapters/references/harness/claude.md: the harness doc now uses the same two-flag decline rule and says that both flags false means the project was never asked.

Closes #4378

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change only narrows a single refusal predicate, from Approved===false to Approved===false && WarningShown===true, and it can never manufacture import consent. I checked the new predicate against the installed Claude Code 2.1.270 binary. There the default project entry DX sets both flags to !1 (false), and the dialog handler zmt writes {Approved:f, WarningShown:!0} for either answer. The show-dialog check edr skips the dialog only when Approved or WarningShown is truthy, so false/false and false/absent both mean never asked. The new test seeds the exact DX shape and would fail against the old predicate. The existing false/true decline fixture is unchanged, and the pipeline-authored doc fix at claude.md:28-29 states the corrected predicate accurately without going beyond the requested sentences.

Testing

First ran the targeted trust test file: 31/31 at HEAD. The same file run against base b182d0f fails on the new test with the reported refusal, while the existing decline fixture stays green. Then I ran the trust script directly on real git worktrees with isolated Claude config stores, at HEAD and at base, across seven entry shapes. HEAD refuses only false/true. Base also refuses false/false and false/absent. Trust-only and consent-carry-forward results match base. Real Claude Code 2.1.270 in tmux showed three things: its default project entry is Approved=false, WarningShown=false even though the import dialog was never shown; "No, disable" writes false/true and "Yes, allow" writes true/true. After HEAD registers a false/false project, claude launched into the worktree skips the trust dialog and still stops on the external-imports dialog, so no consent is created. A real false/true decline written by Claude is still refused and the store is left unchanged. Finally, fm-spawn itself (with stubbed tmux and claude) launches the worker for false/false at HEAD and refuses at base, and refuses the decline at both. The unit-test comparison and the stubbed fm-spawn run were not live product runs, so those two scenarios are recorded as untested. All text transcripts are in the evidence directory; there is no UI surface, so no screenshots. The scratch directories, the tmux socket and the base archive were removed, and the worktree is clean.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Claude Code 2.1.270, opened once in a repo with no CLAUDE.md, writes a project entry with both external-imports flags false (the premise of the fix) ✅ pass live claude-2.1.270-default-project-entry.txt: the entry has hasTrustDialogAccepted=true, Approved=false, WarningShown=false; the import dialog was never shown
Spawn registration on a false/false entry that Claude itself wrote: HEAD exits 0 and records trust on the worktree and project root without adding import consent; base b182d0f refuses ✅ pass live live-claude-default-entry-then-decline.txt §1; cli-shape-matrix-head-vs-base.txt (default-false-false: HEAD exit=0, worktree import flags unset, project flags stay false; BASE exit=1)
After HEAD registers a false/false project whose CLAUDE.md imports an outside file, real claude launched in the worktree skips the trust dialog and still stops on the 'Allow external CLAUDE.md file im… ✅ pass live live-claude-fixture-shape-trust-skip-import-dialog.txt (project root trust was false before registration; first screen is the import dialog; choosing Yes goes straight to the REPL); live-claude-defaul…
Adversarial: a genuine 'No, disable' answered in real claude writes Approved=false, WarningShown=true, and HEAD still refuses the next worktree spawn without touching the store ✅ pass live live-claude-default-entry-then-decline.txt §3-4 (entry false/true; HEAD exit=1 'already declined external CLAUDE.md imports'; store sha256 unchanged)
Adversarial shapes that are not a decline (Approved=false with WarningShown absent, WarningShown=true with Approved absent, a non-boolean WarningShown) register trust and never set Approved=true ✅ pass live cli-shape-matrix-head-vs-base.txt (approved-false-warning-absent, warningshown-true-approved-absent, decline-string-true-not-boolean: HEAD exit=0, no import flag set to true on the worktree, project A…
Regression: standing 'Yes, allow' consent (true/true) is carried to a new worktree, and real claude launched there reaches the REPL with no dialog; an entry with no flags stays trust-only, same as bas… ✅ pass live live-claude-fixture-shape-trust-skip-import-dialog.txt (wt2 trust/Approved/WarningShown all true, REPL first screen); cli-shape-matrix-head-vs-base.txt (consent-true-true, flags-absent identical at HE…
The new test fails on base b182d0f with the refusal and passes at HEAD, and the existing decline fixture stays green on both ⏸️ untested no The earlier payload only ran the unit test file (tests/fm-claude-trust.test.sh) at HEAD and against a base archive. A unit test run is not a live product run, so it did not show a live result. The liv…
fm-spawn of a claude worker into a project with the default false/false entry launches the worker at HEAD (base refuses), and a false/true decline is refused at both ⏸️ untested no The earlier payload ran bin/fm-spawn.sh only with the test-fixture fake tmux backend and fake claude binary, so it did not show a live result. A live check needs fm-spawn run on a real tmux session wi…
Evidence: Targeted trust test file at HEAD (31 ok)

Source: Targeted trust test file at HEAD (31 ok)

ok - fm-claude-trust.sh: a fresh task worktree is trusted
ok - fm-claude-trust.sh: a fresh registration trusts the project root without manufacturing import consent
ok - fm-claude-trust.sh: carries forward a project's already-granted import consent to the worktree entry
ok - fm-claude-trust.sh: preserves unrelated keys on the project-root entry
ok - fm-claude-trust.sh: refuses to override a project's declined external-imports consent
ok - fm-claude-trust.sh: a never-asked default external-imports pair is not treated as a decline
ok - fm-claude-trust.sh: repeat registration is idempotent
ok - fm-claude-trust.sh: refuses the primary checkout
ok - fm-claude-trust.sh: an exported CDPATH cannot defeat the scope refusal
ok - fm-claude-trust.sh: inherited git environment overrides cannot defeat the scope refusal
ok - fm-claude-trust.sh: refuses a home directory the git checks would accept
ok - fm-claude-trust.sh: refuses the Claude config directory
ok - fm-claude-trust.sh: refuses a relative CLAUDE_CONFIG_DIR
ok - fm-claude-trust.sh: refuses a directory that is not a git worktree
ok - fm-claude-trust.sh: refuses a path that does not exist
ok - fm-claude-trust.sh: refuses a worktree belonging to another project
ok - fm-claude-trust.sh: refuses a subdirectory of the worktree
ok - fm-claude-trust.sh: a project argument that is itself a linked worktree resolves to the primary checkout
ok - fm-claude-trust.sh: preserves unrelated store content
ok - fm-claude-trust.sh: refuses a store symlinked to another user's file
ok - fm-claude-trust.sh: follows a store symlink to this user's own file and leaves the link intact
ok - fm-claude-trust.sh: refuses an unparseable store and leaves it untouched
ok - fm-claude-trust.sh: a missing node is refused rather than degraded
ok - fm-claude-trust.sh: a scope refusal stays fail-closed without node
ok - fm-spawn.sh: a claude spawn pre-trusts its worktree and launches with the brief
ok - fm-spawn.sh: a trust-refused claude spawn leaves no task state behind
ok - fm-spawn.sh: a claude secondmate spawn pre-trusts a standalone-clone home
ok - fm-spawn.sh: a claude secondmate spawn pre-trusts a leased worktree home
ok - fm-claude-trust.sh: home-level trust is refused for everything but a home seeded for this secondmate
ok - fm-claude-trust.sh: worktree mode still refuses a secondmate home
ok - fm-spawn.sh: a claude secondmate spawn refuses when home trust cannot be recorded
Evidence: HEAD's test file run against base b182d0f: new test fails with the refusal, decline fixture passes

Source: HEAD's test file run against base b182d0f: new test fails with the refusal, decline fixture passes