Switching models without changing your default
Background
Claude Code, Anthropic’s coding agent, ships with a family of models: Sonnet, Opus, Fable, and Haiku. They differ in capability, speed, and cost, and it is normal to move between them depending on the task. Claude Code is available through several clients: a desktop app, a web app, IDE extensions, and the CLI, which is the one this post is written for.
Inside a session, the /model command handles the switch. It is worth knowing that the recommended time to set your model is at the start of a session: each model has its own prompt cache, so switching midway breaks it.
What I noticed is that running /model with a model name, /model sonnet for example, does more than switch the current session. It also updates the default model in my settings, so every future session starts on Sonnet too.
The problem
Sometimes that is what I want. Usually it is not: I want one session on a particular model, with my default left alone.
There is a way. Run /model with no argument to open the model picker, select a model with the up and down arrows, then press s. That switches the model for the current session only and does not touch the default. Confirming with enter instead behaves like naming the model directly: it switches and saves the default.
A more streamlined way
That works, but I wondered whether the extra step could be skipped entirely by starting the session on the desired model in the first place. It can, and effort can be set at the same time:
claude --model sonnet --effort medium
Exactly what I wanted, but a bit too wordy to type every time.
The shortcuts
So I asked Claude to generate a shortcut for each model, optionally accepting an effort level and defaulting to medium. It detected I was using zsh and produced this for my ~/.zshrc:
# claude model shortcuts: `sonnet [effort] [claude args...]` (effort defaults to medium)
_claude_model() {
local model="$1"; shift
local effort="medium"
if (( $# > 0 )); then
effort="$1"
shift
fi
claude --model "$model" --effort "$effort" "$@"
}
sonnet() { _claude_model sonnet "$@" }
opus() { _claude_model opus "$@" }
fable() { _claude_model fable "$@" }
haiku() { _claude_model haiku "$@" }
Now sonnet starts a Sonnet session at medium effort, opus high starts an Opus session at high effort, and anything after the effort is passed through to claude as normal. My default stays put. That’s good enough for me.
Not using zsh?
Copy the implementation above and ask your own Claude to generate an equivalent for your shell or preferred setup!
Get new posts straight to your inbox
Your email address will never be shared with anyone or used for anything other than receiving posts from this blog.