Feature request: programmatic model switch for a running session (control-plane API, not keystroke injection)
Summary
Please expose a control-plane way for an external tool to change the active model of an already-running, interactive Claude Code session — without simulating keystrokes into the terminal PTY.
Problem / motivation
I maintain a terminal emulator that hosts claude sessions and would like to auto-select the model tier per workload (e.g. drop to a cheaper tier during long mechanical stretches, return to a stronger tier when the work turns hard).
Today the only mechanism available to an external host is to inject /model <tier> + Enter as keystrokes into the PTY. That is fundamentally unsafe:
- Injecting while a tool/command is running cancels the in-flight command (the keystrokes land in the running process / interrupt the turn).
- Injecting between turns risks the confirm dialog + any continuation starting unrequested billable work — a real cost concern on metered plans.
- It depends on screen-scraping the TUI's "Switch model?" dialog text, which changes between releases and needs perpetual upkeep.
As far as I can tell there is no clean alternative today: hooks receive the model read-only; settings.json / ANTHROPIC_MODEL apply only at startup, not to a live session; the Agent SDK is one-shot (non-interactive); remote-control / channels can't invoke slash commands. Keystroke injection is the only path.
Proposed mechanisms (any one would suffice)
- IPC / local control socket for a running session accepting a
set-model <tier>command (ideally other slash-command equivalents too) — a documented "control" surface. - A hook that can change the model — e.g. a
UserPromptSubmit(or a newTurnStart) hook whose JSON output may set the model for the upcoming turn. - A watched session-scoped setting/file the CLI re-reads each turn, so an external tool can change the tier between turns.
Key requirement
The switch must apply at a safe boundary (between turns) and must never start new work on its own — changing the model should not imply "continue". An external tool needs to set the tier and have it take effect on the next user-initiated turn, with no side effects if the session is idle.
Why it matters
A clean API turns a fragile, billing-risky, TUI-scraping integration into a robust one — enabling terminal hosts and automation tools to do cost-aware model selection safely.
Prior art
Related external-control requests: #24947 (claude inject — send prompts to running sessions), #53049 (external message injection API for active sessions). This request is specifically about model switching for a live session.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗