claude-code - 💡(How to fix) Fix [FEATURE] Persistent session context across model/provider switches within the same session [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46423Fetched 2026-04-11 06:20:41
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1

When a user switches models or API providers mid-session (by changing ANTHROPIC_MODEL or ANTHROPIC_BASE_URL mid-conversation), the conversation context and memory state are not preserved across the switch. The new model/provider starts with zero context.

Root Cause

Users on multi-provider setups (cost optimization, model routing, A/B testing) cannot switch models mid-session without losing all context. This forces artificial workflow constraints:

  • "Don't switch models until you're done with this task"
  • "Write everything to memory before switching or lose it"
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this has not been reported yet
  • This is a single feature request
  • I am using the latest version of Claude Code

Summary

When a user switches models or API providers mid-session (by changing ANTHROPIC_MODEL or ANTHROPIC_BASE_URL mid-conversation), the conversation context and memory state are not preserved across the switch. The new model/provider starts with zero context.

Feature Request

Add a session continuity mechanism that persists context across model/provider switches within the same running CLI session. Specifically:

  1. Memory file state should survive the switch — if .claude/learnings/ or MEMORY.md were loaded before the switch, they should remain accessible after
  2. Conversation history should be transferable — the message history from before the switch should be available to the new model/provider
  3. Optional opt-in via flag--preserve-context-on-switch to enable this behavior; off by default for users who want fresh starts

Why This Matters

Users on multi-provider setups (cost optimization, model routing, A/B testing) cannot switch models mid-session without losing all context. This forces artificial workflow constraints:

  • "Don't switch models until you're done with this task"
  • "Write everything to memory before switching or lose it"

Prior Art

  • Issue #46420 describes the context loss bug this feature would fix
  • The session storage layer already persists state across sessions — this feature would extend that to model switches within a session

Suggested Labels

enhancement, area:core, area:providers

extent analysis

TL;DR

Implement a session continuity mechanism to preserve conversation context and memory state when switching models or API providers mid-session.

Guidance

  • Investigate the current session storage layer to understand how state is persisted across sessions and determine how to extend this functionality to model switches within a session.
  • Design an opt-in flag (--preserve-context-on-switch) to enable this behavior, allowing users to choose between preserving context and starting fresh.
  • Develop a method to transfer conversation history from the previous model/provider to the new one, ensuring a seamless experience for users.
  • Consider the implications of preserving memory file state (e.g., .claude/learnings/ or MEMORY.md) across model switches and ensure that this does not introduce any security or data integrity issues.

Example

No code snippet is provided as the issue is a feature request and does not include specific implementation details.

Notes

The implementation of this feature will require careful consideration of the trade-offs between preserving context and starting with a fresh state. It is essential to ensure that the solution does not introduce any unintended consequences, such as data corruption or security vulnerabilities.

Recommendation

Apply a workaround by implementing the suggested session continuity mechanism, as this will provide a more seamless experience for users switching models or API providers mid-session. This approach will allow users to opt-in to preserving context, addressing the current limitations and workflow constraints.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING