Skip to content

fix: use transcript model to correct cross-session model contamination#206

Open
AniAggarwal wants to merge 2 commits intosirmalloc:mainfrom
AniAggarwal:fix/model-from-transcript
Open

fix: use transcript model to correct cross-session model contamination#206
AniAggarwal wants to merge 2 commits intosirmalloc:mainfrom
AniAggarwal:fix/model-from-transcript

Conversation

@AniAggarwal
Copy link
Contributor

@AniAggarwal AniAggarwal commented Mar 7, 2026

Summary

Fixes the model display showing the wrong model when multiple Claude Code sessions are open and one changes models. The root cause is upstream (anthropics/claude-code#19570) — the model field in statusline JSON reads from global shared state instead of per-session state.

  • Extracts the model from the per-session transcript (which has the correct message.model on each assistant entry) inside getTokenMetrics — no extra file read
  • Overrides the stdin model in renderMultipleLines when the transcript model differs
  • When the last transcript entry is a user message (API call in progress), returns null to avoid showing a stale model — self-corrects once the response arrives

Trade-off

Brief window during API calls where cross-session contamination can still show. Acceptable vs permanently displaying the wrong model. This workaround can be removed when Claude Code fixes the upstream bug.

This is a pretty big patch for a bug in upstream, so feel free to reject. I was getting quite annoyed with the status line changing between chats so figured I'd make a PR.

Closes #190

Test plan

  • 3 new tests: model extraction, pending-user null, missing model null
  • All existing tests updated and passing (67 tests across 6 files)
  • tsc --noEmit clean
  • Manual test: two parallel sessions, change model in one, both show correct models

Read the model from per-session transcript data instead of relying on
the global shared state model, which can be contaminated across sessions
(anthropics/claude-code#19570, closes sirmalloc#190).

When the last transcript entry is a user message (API call in progress),
returns null to avoid showing a stale model. Self-corrects once the
response arrives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When running multiple worktrees on different models, status line defaults to the most recently changed worktree model for all worktrees

1 participant