An overloaded model should not be the reason a long job stops halfway.
--fallback-model takes one model or a comma-separated list. When the primary model is overloaded or unavailable, for example a retired one, Claude Code tries the next in line.
claude --fallback-model sonnet,haiku
The list is tried in order, so put the one you would accept first. If you want this for every session, the fallbackModel setting stores the chain, and the flag overrides it for one run.
For unattended jobs that is the setting I would care about most. For a session where I am watching, I would rather see the error and choose myself.
A chain makes more sense than a single fallback because the second choice can fail too. It does not fix a bad prompt or a rate limit that applies to you, only the case where a model is not available right now.
The caveat is obvious but easy to forget: a fallback is a different model. A smaller one may answer the same prompt differently, so read the result before you trust it.
Further reading: CLI reference – Claude Code docs, Model configuration – Claude Code docs, On this site: claude -p lets you pipe text into Claude Code from a script, On this site: pipe a log straight into claude -p instead of pasting it