Original Reddit post

As someone who mostly runs Fable, I get really frustrated when I give a large prompt and it switches to Opus part-way through its work for seemingly no reason. So I made this hook that detects the moment the safeguards are triggered for any model so you can narrow down exactly what caused it to switch. If you just want to stop the silent switching entirely, set “switchModelsOnFlag”: false in ~/.claude/settings.json . Your session pauses on a flag instead of switching. (It defaults to on. It’s currently not in the published settings reference, so check your own /config → “Model & output”.) This will allow you to stay on Fable, but it requires you to babysit Claude while it works so you can restart it when it stops. Then the tool, for people who want to keep auto-switch on but know when it fires: A dependency-free PostToolUse hook. On any model change it writes a log entry with the old/new model, the tool call it happened after, and the trail of the last five calls that led up to it. Review with –report . It’s safe to leave on. The hook reads Claude Code’s session transcript to catch the switch, and since Anthropic says that internal format can change between versions, I made it so a future change just quietly stops the logging instead of breaking anything mid-session. The repo is at https://github.com/Meldh-LLC/claude-model-switch-detector and has an MIT license. This is just a simple tool I made for myself and figured everyone else could use it. I use this to isolate the root cause of the safeguard triggers in my projects so I can have Fable avoid those areas. Hopefully this can help ease some frustration. submitted by /u/MeldhLLC

Originally posted by u/MeldhLLC on r/ClaudeCode