(feat) swap: settle Claude Code's stale plaintext credential fallback after each canonical write (issue #1540) #1541
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1541"
general
weight: 0.35
alexey-pelykh
Closes #1540.
On macOS, Claude Code writes
<config dir>/.credentials.jsononly when a keychain save fails. On 2.1.285 its per-request change check is file-first: while that file exists, a live session compares only the file's mtime and never re-reads the keychain. So once one stale fallback file is left behind, every swap is invisible to every running session. Issue #1540 has the field measurements and the decode.The change
FallbackSettlingStore(new,src/plaintext_fallback.rs) wraps the canonicalCredentialStore. After every successfulwrite, it settles the file according to a new[credential].plaintext_fallbackkey:| Mode | Effect |
|---|---|
|
touch(default) | bump its mtime, so live sessions re-read storage (keychain first) once; the file stays ||
remove| delete the file ||
off| leave it |Why
touchis the default (review finding 2; ADR-0039 § Context). The file is not always stale. Claude Code writes it when a keychain save fails (build/version-compat.md§ AC-6), so at that moment it holds a credential newer than the keychain item, and refresh tokens rotate on exchange (ADR-0007), so the keychain's copy may already be dead. The account being refreshed is the active one, which the next swap moves away from, andswap.rsre-stashes it from the keychain without seeing the file.removecould therefore delete the only working copy of that login.touchfixes the measured harm and deletes nothing;removeis the opt-in for an operator who would rather have that account need a freshloginthan keep a plaintext copy on disk.All four production writers of the canonical item (swap, adopt-target, activating
login, keep-warm promotion) go through three store construction sites: the daemon incli.rs,use, andlogin'sreconcile_login. Wrapping at those sites covers all four, plus any writer added later.Two source-inspection tests guard the wiring:
every_canonical_writer_settles_the_fallback_with_the_configured_modepins the three sites: the wrap is present, it wrapsRealCredentialStore::new(), its mode comes fromplaintext_fallback, and no bare store reaches the site ahead of the wrap.every_bare_store_construction_is_wrapped_or_registered_read_onlywalkssrc/and requires every other non-testRealCredentialStore::new()to be registered as read-only with a reason, keyed by file and enclosingfn, so a writer built on a fourth site cannot slip past the first test.Safety properties, each with a test:
fallback_applies_on(os)is a pure function ofstd::env::consts::OS, so the Linux and Windows arms are asserted on the macOS runner (the_settlement_applies_on_macos_and_nowhere_else). Elsewhere the file is the store (#26) and the wrapper passes straight through.CLAUDE_SECURESTORAGE_CONFIG_DIR(defined-empty means the default), then a non-emptyCLAUDE_CONFIG_DIR, then~/.claude. It must be absolute and ASCII.symlink_metadatafirst; a symlink or a directory isrefusedin every mode. Thetoucharm then opens withO_NOFOLLOW, so a link swapped in after the stat is refused by the kernel (the_re_stamp_open_refuses_a_link_on_its_own).the_default_mode_re_stamps_and_deletes_nothing).~/.claude.jsonco-write.event=plaintext_fallback action=removed|touched|ignored|refused|failed. It is registered inevery_event_variantand carries no path and no secret.The config key follows the
[migration].conflict_policypattern (ADR-0005): validated against its vocabulary, rendered with an inline comment, reported byconfig show --origin.origin_report_reports_every_key_render_writespins render and origin agreement.Docs
[credential]: a table row and a#### Claude Code's plaintext fallbacksubsection, including whyremoveis not the default and what a live session does while the file exists (it keeps the token it already holds in memory; no restart is needed).build/version-compat.md: a# Issue #1540entry recording the file-first change check, on CC 2.1.285, outside the verified range and not widening it. The measured removal is ✅; the predictedtouchpickup is its own ⚠️ finding, unmeasured. The "what would falsify this" list includes the newer-file window.maintook in #1527), plus its index row. § Context records the window, § Decision 3 the default, § Alternatives theremovedefault and the mtime-comparison variant.Follow-ups
1. The import version floor has moved — #1589, open.
[credential].plaintext_fallbackis rendered unconditionally, soCONFIG_BLOCK_VERSION_FLOORmust name this PR's merge commit, which exists only after the squash.a_build_at_the_current_floor_commit_still_rejects_a_current_renderwitnesses the gap until then; the constant's doc comment and the README point at #1589.2. A
status/ menubar warning while the file is present. It touches the status wire and the Swift fixtures, so it stays separate (as proposed in #1540).3. The mode is read once at daemon start-up, like the tunables. A roster reload does not re-read it.
4. The
toucharm is unmeasured live. The ledger entry says what would promote it.Gates
The diff touches
src/,README.md,build/, anddocs/, sotest,msrv,deny, anddoc-gatesare owed. No golden,apps/menubar/, or gate path is touched, so no rebaseline orGate-Change-Acknowledgedtrailer is owed.Run locally on the pickup commit, in the order
ci.ymlruns them, with the line each printed:The contributor's own CI run failed only on
deny: RUSTSEC-2026-0386 on tokio 1.52.3, whichmainfixed in c9ec668 and the rebase picks up.Provenance
This is the third cause behind the same "sessions don't follow swaps" symptom as #1535. Moving the file aside by hand put the same running sessions back on the swapped-to account on their next request, with no restart.
🤖 Generated with Claude Code