ToolingProjects

Model Shift — switch Claude Code models like a gear stick

A VS Code / Cursor extension that turns typing /model into shifting a gear stick: switch Claude Code models instantly, see the state visually, and mute task-done sounds with one switch. Built with vanilla JS + Bun, no npm dependencies, and no data leaves the machine.

11 min read

A VS Code / Cursor extension that takes typing /model out into a separate panel shaped like a car gear stick (H-pattern). Shift to switch models instantly while talking to Claude Code, with the real state synced from the transcript and one switch to mute or unmute task-done sounds.

VS Code Extension APIWebviewBun.servetmuxShell hooksTTSWeb AudioVanilla JS
Empathize · Define

The problem

Why is switching models back and forth while working with Claude Code more annoying than it should be?

Claude Code in a terminal, where the user has to type /model and the flag name mid-conversation
Before Model Shift: switching models meant typing /model and remembering the flag name mid-conversation (terminal mockup)

Claude Code can switch models with /model <name>, but you have to type it and remember the flag name (sonnet[1m], fable) every time. The list keeps growing (Haiku / Sonnet / Sonnet 1M / Opus / Fable), and I switch often to balance cost, quality and speed. Typing commands mid-conversation breaks the flow, and the state ("which model is active, how much context is left") is plain text with nothing visual.

— The starting brief, before building Model Shift

Typing /model every time is slow, and you have to remember flags

Flag names don't match the names you see (sonnet[1m], fable) and change between Claude Code versions. Get one wrong and the switch fails, so you type it again.

More models means more switching

Haiku / Sonnet / Sonnet 1M / Opus / Fable: light tasks get the cheap model, hard ones move up. Switching back and forth to balance cost and quality happens many times per session.

I wanted to switch from a separate panel, not the input area

Typing a command in the middle of a prompt breaks the flow. I wanted a control "outside" the TUI that switches with one click without leaving the conversation.

No visual state

Which model is active? Is the context almost full? It's all text. I wanted a car-dashboard readout you understand at a glance.

Task-done sounds are hard to silence in meetings

I set up sounds for when a task finishes, but they need to go quiet fast when a meeting starts. Editing config or restarting claude is too slow.


Ideate

The solution

Turn the typed command into a gear stick: one shift = one model switch, with the state shown visually like a car dashboard

The real Model Shift panel: 5H/7D quota bars, the current gear, a VU meter, a context gauge and the H-pattern gear stick
The real panel (rendered from the extension's webview): quota, current gear, context gauge and gear stick on one screen

An H-pattern gear stick in its own panel

A panel in the activity bar shaped like a 6-position car gear stick. Drag the knob or click a label to switch models instantly without interrupting your prompt.

Send /model straight into the terminal

Claude Code has no API for switching from outside, so the control sends terminal.sendText("/model opus") into the integrated terminal where claude is running (the web surface uses tmux send-keys)

Show the state visually

The current gear + a VU meter (model strength) + a fuel-style E→F context gauge: one glance tells you which model is active and whether the context is nearly full

Sync the real model from the transcript

Polls the session *.jsonl file, reads the actual message.model and quietly moves the gear to match, so the UI stays in sync even if the user types /model manually

One switch to mute sounds

The switch runs touch/rm on a .tts-muted flag file that the TTS hooks check. All sounds go quiet or come back at once, with no claude restart, in time for a meeting.


Prototype

How it works, in 4 steps

From opening the panel to the model actually switching in the conversation

A VS Code window with the Model Shift panel in the sidebar and a terminal receiving the /model opus command sent by the panel
Shift into gear 4 → the panel sends /model opus to the integrated terminal where claude runs (real panel · the VS Code window and terminal are a mockup)
1

Open the panel

Click the gear icon in the activity bar → the H-pattern gear stick panel appears in the sidebar

2

Shift gear

Drag the knob / click a label → sendText("/model opus") goes into the terminal, with a ka-chunk sound

3

Panel sync

Polls the transcript every 5 seconds, reads the real model and tokens → moves the gear and updates the context gauge

4

Flip the sound switch

touch/rm .tts-muted → task-done sounds mute or unmute instantly, no restart


Prototype

Tech Stack & Architecture

Two surfaces on the same mechanism: zero npm dependencies, no data leaves the machine

The localhost web version of Model Shift using Bun.serve and tmux send-keys
Surface 2: a localhost web page (Bun.serve) for people who run claude in a plain terminal, controlled via tmux send-keys
Claude Code user: shifts gear / flips the sound switch
Surface A: VS Code webview Surface B: Web panel H-pattern gear stick
↕
Extension core (extension.js + webview) — sendText / poll / fs
activeTerminal.sendText() poll *.jsonl GEARS[] injection guard
↕
Claude Code terminal + TTS hooks (Stop → speak-done.sh)
/model <name> tmux send-keys (B) tts-lib.sh gpt-4o-mini-tts / say
↕
~/.claude: transcript (read-only) + flag + cache
projects/*.jsonl hooks/.tts-muted .tts-cache/*.mp3
Why this stack?

VS Code Extension API puts the control genuinely "outside" the TUI, and sendText sends /model into the integrated terminal without needing an API Claude Code doesn't have · Bun.serve + tmux is a fallback surface for plain-terminal users — native, no express · A flag file (.tts-muted) mutes every hook from one place without a restart · Plain vanilla JS + zero npm dependencies — as a designer I can edit the UI in one file, with no build step


Prototype

What I built: 8 core capabilities

Everything from shifting gear and sending the command to the task-done sound

Panel header: 5-hour and 7-day quota bars, gear 2 Sonnet, a VU meter and a context gauge at 63%
A car-dashboard readout: 5H/7D quota bars, a VU meter for model strength and an E→F context gauge

H-Pattern Gear Shifter

A 6-position gear stick (1–5 + R). Drag the knob and it snaps to the nearest gear, or click a label directly. It feels like shifting a real car.

Model Switcher

Sends sendText("/model <name>") into the integrated terminal (surface B uses tmux send-keys), so you switch models without typing

Real-Model Sync

Polls *.jsonl every 5 seconds, reads the real message.model → quietly moves the gear to match, so the UI never drifts out of sync

Context Gauge

A fuel gauge E→F calculated from input + cache_read + cache_creation of the latest message against a 200K window

VU Meter

The bars show how "strong" the model is, based on an rpm value mapped to each gear, so you can tell whether you're on a light or heavy model

Ka-chunk Sound

The click when you change gear is generated live with Web Audio (clack()). No audio files, just the feel of a gear stick.

17 task-done voice personas

A Stop hook picks 1 of 17 personas at random each time a task finishes (news anchor / robot / butler, and so on) via TTS, with a say fallback

Mute Switch

A switch in the panel runs touch/rm on the .tts-muted file the hooks check, muting or unmuting every sound instantly without restarting claude


Prototype

The panel

Click the gear icon in the activity bar → see the current gear, context gauge and sound switch on one screen

Two panel states side by side: gear 1 Haiku with low context, and gear 4 Opus at 86% context with a red gauge and sound muted
Two real states: left, Haiku on a light task · right, Opus with the context nearly full, the gauge red and the sound switch muted
Model Shift
CONTEXT · TOKENS ×1000
/model opus
4OPUS
1HAIKU
3SONNET 1M
5FABLE
2SONNET
4OPUS
RDEFAULT
Task-done sounds ON

Test & Iterate

Hacking the problems

6 problems I had to solve myself: tooling limits and building commands safely

Two real code snippets: the regex that blocks injection before sendText, and the line in tts-lib.sh that checks the .tts-muted file
Real code from extension.js and tts-lib.sh: whitelisting model names before sending them to the terminal, and muting everything with a single flag file

Claude Code has no API for switching models from outside

I wanted a button to switch models, but there is no endpoint or SDK to call. How do you control it from a separate panel?

Fix: the control lives "outside" the TUI and sends /model <name> + Enter into the terminal where claude runs. The main surface uses VS Code's activeTerminal.sendText() (no tmux needed); the fallback surface uses tmux send-keys for plain-terminal users.

Sending model names into a shell/terminal risks injection

Values concatenated into a send-keys / sendText command could smuggle in other commands if they aren't checked first.

Fix: whitelist with the regex ^[\w\[\]-]+$ before every send (on both surfaces), allowing only a–z 0–9 [ ] -. The web side also uses Bun.$ interpolation, which escapes automatically and passes the value as a single arg.

The UI was one-way and didn't know the real model

It could set the model, but if the user typed /model in the conversation, the gear on the panel fell out of sync with reality.

Fix: every 5 seconds, poll the last 128KB of the most recently modified *.jsonl, read message.model → quietly move the gear (no repeat /model, no sound). After a manual shift, sync pauses for 30 seconds so a not-yet-updated transcript doesn't pull the gear back.

The gear stick had to feel real

A plain button would be no different from the built-in /model picker. It needed the "feel" of shifting gears.

Fix: drag the knob with the mouse and it snaps to the nearest gear by distance ((g.x-px)²+(g.y-py)²), with a ka-chunk sound generated live by Web Audio on each shift. The visual layer sits on top of the existing logic without touching the command mechanism.

Sound had to be quick to mute, without a restart

Task-done sounds come from several hooks that run separately. How do you silence all of them quickly for a meeting?

Fix: every hook sources a shared tts-lib.sh, with a guard [ -f ~/.claude/hooks/.tts-muted ] && return 0 at the top of the speak function. The switch only touches/removes the flag file, so everything mutes or unmutes at once without restarting claude.

Calling the TTS API every time was expensive and slow

Generating new audio each time a task finishes costs money, needs a connection and adds delay, and each persona played at a different volume.

Fix: a per-persona cache keyed by md5(voice+instructions+text). If the file exists, it just runs afplay (0 API calls, $0); if not, it generates once and saves. Every clip is normalized with ffmpeg loudnorm to -16 LUFS so they play at the same volume (without ffmpeg it skips this step and still works).

Define

Deliberate design decisions

What I chose not to build matters as much as what I built

A 5-speed H-pattern car gear knob with reverse
UI inspiration: the H-pattern gear stick, which everyone knows how to use without a manual · Photo: Alok Sharma / Unsplash

This tool does one job: switch models faster and show the state visually. It doesn't replace Claude Code's built-in /model picker (its value is "faster, visual, no flags to remember"), the sync only reads from the transcript and never writes back, and no data leaves the machine. A clear scope from the start meant a direct implementation that's easy to maintain.


Sends the command, doesn't replace the picker

Its value is speed and visibility, not filling a missing feature


Read-only sync

Reads the transcript for display, never writes back or touches the session


Mute = one flag file

Controls every hook with a single file, no restart needed


Zero npm dependency

Vanilla JS + Bun: edit the UI in one file, no build step


Level Up · Reflect

Knowledge domains that got stronger

5 areas where my skills actually moved up through this project

Sample structure of an assistant line in a Claude Code transcript jsonl file: model and usage tokens
What I had to learn to read: message.model and token usage in the *.jsonl transcript (sample values)
1. VS Code extension development: from "using extensions" to "writing one":

I learned activity bar view containers and webview providers, messaging between the extension host and the webview, using vscode.window.activeTerminal.sendText() to send commands to the terminal, reading and writing files with fs, and packaging a .vsix to install permanently in Cursor. From zero to a complete, working extension. Lesson: a webview is just HTML/JS, but you have to think the host↔view boundary through.

2. Terminal automation without an API: sending commands across boundaries:

I learned that when a tool has no API for outside control, you can still integrate by "typing" commands into the terminal. sendText (VS Code) and tmux send-keys are two patterns of the same idea. Lesson: automation doesn't always have to wait for an official API, but you have to accept that it's one-way and design a separate sync.

3. Claude Code internals: reading every field of the transcript:

I learned the structure of session *.jsonl files: message.model gives the actual model, token usage is split into input / cache_read / cache_creation, and the Stop hook fires when a task finishes. I used these for both the gear sync and the context gauge. Lesson: Claude Code's state can be read from files, if you know where to look.

4. Shell / audio pipeline: building a sound system with controlled cost:

I wrote bash hooks that source a shared library, connected OpenAI TTS (gpt-4o-mini-tts) with an offline fallback (say), cached by md5 hash to avoid repeat API calls, and normalized loudness with ffmpeg loudnorm → -16 LUFS. Lesson: caching plus a fallback lets a feature that depends on an external API degrade gracefully and cheaply.

5. Injection-safe command building: untrusted input must be sanitized:

I practiced whitelisting with regex before using values to build shell/terminal commands, and used Bun.$, which escapes automatically, instead of concatenating strings. Lesson: every place input flows into a command is a place to think about injection, and the right validate + escape pattern prevents it.

2
surface — VS Code extension + Web/tmux
6
Models on the gear stick (1–5 + R)
17
Task-done voice personas (random)
0
npm dependency

Tan · Natpakan Sirirat

Product Designer & AI Builder — designing user experiences and building AI tools that actually work.

0%