[BUG] Claude Code Session Model Cache Breaks Env Var Overrides
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I have noticed that after Claude v2.1.143, with the Claude Code VSCode extension (and some others have noticed with the binary), the models used in a session are cached and re-selected upon switching sessions. This is an issue, however, with the model overrides that get set for each default model as it sets the model to the base name in the selection.
For example, if I have an env var model override for sonnet that is the equivalent AWS Bedrock model, if I leave the session and go back, the model that is selected and sent to my provider is the original sonnet model name. This then causes Claude Code to hang and bring up the login screen. In my enterprise, this is an issue as this then leads users to go log in to their Anthropic account, mess up their pre-configured API keys, and lead to toil to resolve.
I noticed that the chat history caches the model name (the anthropic model name) with the message sent. I assume that the last message, upon returning to a chat, is what's used to set the model for that session.
I will also note that this happens upon reloading the VSCode window as well, when using the extensions.
What Should Happen?
When returning to an old session, the selected model for that session should be set to the relevant override, not the Anthropic model name itself.
Error Messages/Logs
My proxy says that a model is sent through that is not allowed.
Steps to Reproduce
In VSCode Extension.
For reference, we use LiteLLM with Bedrock Models.
- Set default model env vars to Bedrock Models
- Open a new chat
- Type any message
- Wait for response
- Open a new chat
- Click the session history button and open the old session (don't just click on the old tab, but select the session from the old one)
- Send prompt
- Track what model gets sent through to your proxy
Claude Model
Not sure / Multiple models
Is this a regression?
Yes, this worked in a previous version
Last Working Version
v2.1.143
Claude Code Version
2.1.158
Platform
Other
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
I am using a LiteLLM Proxy in front of Bedrock Models. LiteLLM throws the error saying a model is sent through that wasn't allowed. All model override defaults are set to Bedrock Models.