claude-code - 💡(How to fix) Fix Feature request: programmatic model switch for a running session (control-plane API, not keystroke injection)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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)

  1. IPC / local control socket for a running session accepting a set-model <tier> command (ideally other slash-command equivalents too) — a documented "control" surface.
  2. A hook that can change the model — e.g. a UserPromptSubmit (or a new TurnStart) hook whose JSON output may set the model for the upcoming turn.
  3. 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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING