Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

feat(auth): surface which Claude credential source is actually active - #10

Merged
yjuyjuy merged 4 commits into
masterfrom
fm/surface-credential-source
Aug 13, 2026
Merged

yjuyjuy merged 4 commits into
masterfrom
fm/surface-credential-source

Conversation

@yjuyjuy

@yjuyjuy yjuyjuy commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Problem

jcode's Anthropic auth resolution (load_credentials, crates/jcode-base/src/auth/claude.rs) returns the first non-expired source in strict priority: Claude Code file, then CLAUDE_CODE_OAUTH_TOKEN env, then jcode's own auth.json accounts, then OpenCode. An imported external source therefore shadows jcode's own numbered accounts.

Root cause of the 2026-08-11 work-box incident: a trusted Claude Code import (~/.claude/.credentials.json) won resolution, so /account switch (which only edits auth.json, below the import) was a silent dead control. When the imported token went bad, every session 429'd and every switch did nothing, with no user-visible signal.

Fix

Make the active credential source observable, and warn on the shadow condition:

  • Refactor load_credentials onto one resolve_active_credential resolver, so load_credentials and the new introspection cannot drift on source priority.
  • active_credential_source() returns the resolved source, its location, a masked non-secret token prefix, the mapped jcode account label (for jcode accounts), and expiry state.
  • external_import_shadowing_accounts() detects when a trusted external import wins while auth.json has configured accounts that are therefore never reached.
  • Surface the active source in /auth status, in the /usage card header, and log it once per process at the first session-start auth probe. Each warns when an external import is shadowing configured accounts.
  • Warn right after /account switch when the switch cannot take effect because an import shadows auth.json, instead of silently reporting success.

Verification

  • Verified against upstream v0.75.3: the load_credentials strict-priority order is unchanged there, so this diagnosis and fix apply directly.
  • New unit tests in claude_tests.rs: token masking, source classification, jcode-account resolution, and the external-import-shadows-accounts case.
  • cargo build + cargo test -p jcode-base auth::claude (33 pass) + cargo clippy clean for jcode-base (0 warnings) and jcode-tui (only pre-existing warnings in untouched files).

Token prefixes are capped at 12 chars; no full secret is ever printed or logged.

1jehuang and others added 4 commits August 11, 2026 18:24
jcode's auth resolution silently prefers an imported external credential
(Claude Code file/env, OpenCode) over its own auth.json accounts. When such
an import is trusted, `/account switch` becomes a dead control: it only edits
auth.json, which sits below the import in resolution order, so every switch
appears to succeed while the live credential never changes. A bad imported
token then 429s every session with no user signal.

Make the active source observable and warn on the shadow condition:

- Refactor `load_credentials` onto a single `resolve_active_credential`
  resolver so `load_credentials` and the new introspection can never drift on
  source priority.
- Add `active_credential_source()` returning the resolved source, its
  location, a masked non-secret token prefix, the mapped jcode account label
  (for jcode accounts), and expiry state.
- Add `external_import_shadowing_accounts()` detecting when a trusted external
  import wins while auth.json has configured accounts that are therefore never
  reached.
- Surface the active source in `/auth` status, in the `/usage` card header,
  and log it once per process at the first session-start auth probe, each
  warning when an external import is shadowing configured accounts.
- Warn right after `/account switch` when the switch cannot take effect because
  an import shadows auth.json, instead of silently reporting success.

Verified against upstream v0.75.3 (load_credentials strict-priority order is
unchanged there). cargo build+test+clippy clean for jcode-base and jcode-tui.
The bare /account account-center overlay listed each provider's Saved auth
entry with only state, method, and validation. It did not surface which
credential source jcode actually resolves for Claude, so an imported external
source shadowing auth.json (which makes /account switch a silent no-op) was
invisible in the overlay the ticket named.

Enrich the Claude Saved auth entry detail with the active source and token
identity prefix, and append the shadow warning when an external import is
shadowing the numbered auth.json accounts, matching the wording already used
in /auth status and the /usage card.
@yjuyjuy
yjuyjuy merged commit 3fd37d3 into master Aug 13, 2026
10 of 11 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants