Log every Claude Code model change
A save button switched the model back and nobody saw it for two months. This guide logs every change and pins the model in git.
The fix: pin the model in git
Put the model in .claude/settings.json. A model set there is applied again at every launch, over what you saved with /model. An alias like opus moves to newer versions over time, so pin the full model name. Use the one you want.
{
"model": "claude-opus-5-5"
}Commit it
Every later change is now a commit with an author and a date.
git add .claude/settings.json
git commit -m "Pin model to claude-opus-5-5: needed for X"
# who changed it, and when:
git log -p -- .claude/settings.jsonLog every switch
A PostModelSwitch hook runs after the model changes, including automatic fallbacks and the model restored when you resume a session. It gets the old and new model as JSON on stdin. This one appends one line to a log: time, old model, new model, and why (command, picker, sdk, auto or resume). It needs jq and Claude Code 2.1.251 or later. Put it in ~/.claude/settings.json.
{
"hooks": {
"PostModelSwitch": [{
"hooks": [{
"type": "command",
"command": "jq -c '[(now|todate),.from_model,.to_model,.source]' >> ~/.claude/model.log"
}]
}]
}
}Check it worked
Restart claude, run /model, pick another model and press s, so only this session changes. Then read the log. /status shows the model in use, and a status line keeps it on screen all the time.
/model
/status
/statusline show model name
tail -n 3 ~/.claude/model.logPro tip: log edits to the settings files too
A ConfigChange hook fires when a settings file changes during a session. The input names the source (user_settings, project_settings, local_settings) and the file path.
{
"hooks": {
"ConfigChange": [{
"hooks": [{
"type": "command",
"command": "jq -c '[(now|todate),.source,.file_path]' >> ~/.claude/config.log"
}]
}]
}
}Common mistake
Treating /model as a temporary switch. Pressing Enter in the picker, or typing /model <name>, saves the choice as your default in user settings. Press s in the picker to switch for this session only. A model set in project or managed settings is applied again at every launch, and the startup header names the file.
Official docs
One fix of twenty: the whole Claude Code survival kit.
Follow @whyshouldaicareA new disaster and its fix every day. Comment the word under a reel to get its guide.