Names the terminal tab your coding agent runs in from your first prompt: Claude Code, Codex, Cursor, Gemini CLI and opencode, across tmux, zellij, screen…

Names the terminal tab your coding agent runs in. Works with Claude Code, Codex, Cursor, Gemini CLI and opencode, plus any agent that can run a shell command.
Your first prompt of a session is turned into a 2–4 word title such as CSV Export Button, and the tab the agent is running in gets that name. Only that tab is renamed, never whichever tab happens to be focused, so ten agents in ten tabs stay easy to tell apart.
Pick whichever fits. They all use the same script.
Any agent, as a skill (skills.sh): the agent can rename its tab when you ask, and can set up automatic naming for you:
npx skills add mtami/terminal-tab-title
Automatic naming from the first prompt (a prompt hook per agent):
npx terminal-tab-title install codex cursor gemini opencode # or: install all
| Agent | What gets installed | Then |
|---|---|---|
| Codex | UserPromptSubmit hook in ~/.codex/hooks.json | Run /hooks once to review and trust it |
Cursor (editor agent and cursor-agent) | beforeSubmitPrompt hook in ~/.cursor/hooks.json | Restart Cursor |
| Gemini CLI | BeforeAgent hook in ~/.gemini/settings.json | Check /hooks shows it enabled |
| opencode | plugin in ~/.config/opencode/plugins/terminal-tab-title.js | Restart opencode |
| Claude Code | use the plugin below | – |
The installer copies the script to ~/.local/share/terminal-tab-title/. It merges its hook into the existing config, keeps a .bak of the old file, and never rewrites a file it can't parse. npx terminal-tab-title uninstall <agent> removes the hook.
Claude Code plugin (names the tab with Haiku and adds /tab-title):
/plugin install terminal-tab-title --marketplace mtami/terminal-tab-title
tab-title set "Release Notes" --agent codex # rename this tab now
tab-title detect --agent cursor # show which method this tab would use
tab-title install <agent...|all> # automatic naming
tab-title uninstall <agent...|all>
(npx terminal-tab-title … works without installing anything.)
When no model is configured, a keyword heuristic makes the title. It needs no network: can you add a delete button to my exports → Add Delete Button Exports.
If a model is available, it writes a better title. The first one that applies wins:
| Setting | Uses |
|---|---|
TAB_TITLE_LLM=off | Heuristic only, nothing leaves your machine |
TAB_TITLE_COMMAND="claude -p --model haiku" | Any command that reads the prompt on stdin and prints a title |
ANTHROPIC_API_KEY | claude-haiku-5-5 |
OPENAI_API_KEY | gpt-5-nano |
TAB_TITLE_MODEL overrides the model. With an API key set, the first prompt of each session is sent to that provider to make the title. Set TAB_TITLE_LLM=off if you'd rather it weren't.
Naming runs in a detached background process, so it never holds up your prompt. Results and errors go to a log file whose path tab-title detect prints.
Multiplexers are checked first, because they own the tab you see and the outer terminal's variables leak into them.
| Where the agent runs | How the tab is renamed | Needs |
|---|---|---|
| tmux (also byobu) | tmux rename-window -t $TMUX_PANE (also turns off automatic-rename for that window) | – |
| zellij ≥ 0.44 | zellij action list-panes --json → rename-tab --tab-id | Older zellij can only rename the focused tab, so it is skipped |
| GNU screen | screen -S $STY -p $WINDOW -X title | – |
| herdr | herdr tab rename $HERDR_TAB_ID | – |
| WezTerm | wezterm cli set-tab-title --pane-id $WEZTERM_PANE | Under WSL, forward WEZTERM_PANE through WSLENV |
| kitty | kitten @ --to $KITTY_LISTEN_ON set-tab-title --match window_id:… | allow_remote_control socket-only and listen_on unix:@kitty in kitty.conf |
| Konsole | D-Bus setTabTitleFormat (qdbus6/qdbus) | – |
| ConEmu / cmder | ConEmuC -GuiMacro Rename 0 … | – |
| iTerm2, Terminal.app, Windows Terminal, Ghostty, VS Code, GNOME Terminal, Warp, Alacritty, … | OSC title escape sequence written to the agent's terminal (OSC 1 on macOS terminals, OSC 30 on Konsole, OSC 0 elsewhere) | See below |
Claude Code, Codex and Gemini CLI write their own terminal title, which would overwrite an OSC title straight away. In a plain OSC terminal, terminal-tab-title therefore leaves the title to the agent unless you turn the agent's title off:
| Agent | Turn its own title off with |
|---|---|
| Claude Code | { "env": { "CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "1" } } in ~/.claude/settings.json |
| Codex | Codex's /title command, then TAB_TITLE_OSC=1 |
| Gemini CLI | "ui": { "hideWindowTitle": true } in ~/.gemini/settings.json |
Cursor and opencode get the OSC title by default. TAB_TITLE_OSC=1 or 0 forces it on or off for any agent. Multiplexers and the scriptable terminals above don't have this problem.
Some terminals need a setting before they show application titles. Windows Terminal profiles need suppressApplicationTitle left off, and VS Code needs ${sequence} in terminal.integrated.tabs.title. The OSC write needs ps, so on native Windows (outside WSL) only the command-based terminals work.
Reports and PRs are welcome.
bun run build # bundles src/ into skills/terminal-tab-title/scripts/tab-title.mjs (committed, so skills.sh installs work)
bun run test # CLI tests; the Claude Code plugin's tests in tests/*.test.ts run under Claude Code's plugin test kit
hooks/backends.ts holds the terminal detection, and both the Claude Code plugin (hooks/register.ts) and the CLI (src/) use it.
MIT
hooks/register.ts 132 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, PromptOrigin, Register } from 'claude-code'
3
4import { OSC_WRITER, cleanLabel, plan, zellijTabId } from './backends'
5import type { Attempt, Env } from './backends'
6
7const isNamed = atom({ plugin: 'terminal-tab-title', key: 'isNamed' } as const, false)
8
9const SYSTEM =
10 'You name terminal tabs. Reply with a 2-4 word title (Title Case, no quotes, ' +
11 'no trailing punctuation) summarising the task in the user message. Reply with the title only.'
12
13const TIMEOUT = { timeoutMs: 5000 }
14
15// The engine stamps every session prompt; an unstamped one (the test kit) counts as typed.
16function isFromPerson(origin: PromptOrigin | undefined): boolean {
17 return (
18 origin === undefined ||
19 origin.kind === 'composer' ||
20 origin.kind === 'bridge' ||
21 (origin.kind === 'plugin' && 'asUser' in origin && origin.asUser === true)
22 )
23}
24
25async function readEnv($: EngineInterface): Promise<Env> {
26 const [
27 HERDR_TAB_ID, HERDR_BIN_PATH, TMUX, TMUX_PANE, ZELLIJ, ZELLIJ_PANE_ID, STY, WINDOW,
28 WEZTERM_PANE, KITTY_WINDOW_ID, KITTY_LISTEN_ON, KONSOLE_DBUS_SERVICE, KONSOLE_DBUS_SESSION,
29 ConEmuPID, TERM_PROGRAM, TERM, WT_SESSION, WSL_DISTRO_NAME, CLAUDE_CODE_DISABLE_TERMINAL_TITLE,
30 ] = await Promise.all([
31 $.env.get('HERDR_TAB_ID'), $.env.get('HERDR_BIN_PATH'), $.env.get('TMUX'), $.env.get('TMUX_PANE'),
32 $.env.get('ZELLIJ'), $.env.get('ZELLIJ_PANE_ID'), $.env.get('STY'), $.env.get('WINDOW'),
33 $.env.get('WEZTERM_PANE'), $.env.get('KITTY_WINDOW_ID'), $.env.get('KITTY_LISTEN_ON'),
34 $.env.get('KONSOLE_DBUS_SERVICE'), $.env.get('KONSOLE_DBUS_SESSION'), $.env.get('ConEmuPID'),
35 $.env.get('TERM_PROGRAM'), $.env.get('TERM'), $.env.get('WT_SESSION'), $.env.get('WSL_DISTRO_NAME'),
36 $.env.get('CLAUDE_CODE_DISABLE_TERMINAL_TITLE'),
37 ])
38
39 return {
40 HERDR_TAB_ID, HERDR_BIN_PATH, TMUX, TMUX_PANE, ZELLIJ, ZELLIJ_PANE_ID, STY, WINDOW,
41 WEZTERM_PANE, KITTY_WINDOW_ID, KITTY_LISTEN_ON, KONSOLE_DBUS_SERVICE, KONSOLE_DBUS_SESSION,
42 ConEmuPID, TERM_PROGRAM, TERM, WT_SESSION, WSL_DISTRO_NAME, CLAUDE_CODE_DISABLE_TERMINAL_TITLE,
43 }
44}
45
46async function tryAttempt($: EngineInterface, attempt: Attempt, label: string): Promise<boolean> {
47 if ('run' in attempt) {
48 const ran = await $.process.run(attempt.run, TIMEOUT)
49
50 return ran.exitCode === 0
51 }
52 if ('zellijPane' in attempt) {
53 const listed = await $.process.run(['zellij', 'action', 'list-panes', '--json', '--tab'], TIMEOUT)
54 // Before 0.44 there is no list-panes and rename-tab only hits the focused tab: leave it alone.
55 const tabId = listed.exitCode === 0 ? zellijTabId(listed.stdout, attempt.zellijPane) : undefined
56 if (tabId === undefined) return false
57 const ran = await $.process.run(['zellij', 'action', 'rename-tab', '--tab-id', String(tabId), label], TIMEOUT)
58
59 return ran.exitCode === 0
60 }
61 const ran = await $.process.run(['sh', '-c', OSC_WRITER, 'terminal-tab-title', attempt.osc], TIMEOUT)
62
63 return ran.exitCode === 0
64}
65
66// Resolves the backend that renamed the tab, or why none did.
67async function renameTab($: EngineInterface, label: string): Promise<{ backend?: string; reason?: string }> {
68 const { attempts, note } = plan(await readEnv($), label)
69 const tried: string[] = []
70 for (const attempt of attempts) {
71 const isDone = await tryAttempt($, attempt, label).catch(() => false)
72 if (isDone) return { backend: attempt.backend }
73 tried.push(attempt.backend)
74 }
75
76 return { reason: note ?? (tried.length > 0 ? `${[...new Set(tried)].join(', ')} refused it` : 'no supported terminal found') }
77}
78
79async function nameFromPrompt($: EngineInterface, text: string): Promise<void> {
80 const reply = await $.model.complete({ model: 'haiku', system: SYSTEM, prompt: text.slice(0, 4000), maxTokens: 30 })
81 const label = reply.isAnswered ? cleanLabel(reply.text) : ''
82 if (!label) {
83 await update($, isNamed, () => false)
84 return
85 }
86
87 const result = await renameTab($, label)
88 if (!result.backend) {
89 // Nothing here to rename; stay quiet and don't ask the model again this session.
90 $.ui.log(`Could not rename the tab: ${result.reason}.`)
91 }
92}
93
94export const register: Register = on => {
95 on('session.start', async ($, e, next) => {
96 await $.command.register({
97 name: 'tab-title',
98 description: 'Rename this terminal tab (/tab-title <name>), or show how it would be renamed',
99 })
100
101 return next(e)
102 })
103
104 on('command.run', { command: 'tab-title' }, async ($, e) => {
105 const label = cleanLabel(e.args)
106 if (!label) {
107 const { attempts, note } = plan(await readEnv($), 'Example')
108 const backends = [...new Set(attempts.map(one => one.backend))]
109
110 return { text: backends.length > 0 ? `Would rename via ${backends.join(' → ')}.` : `${note ?? 'No supported terminal found'}.` }
111 }
112
113 await update($, isNamed, () => true)
114 const result = await renameTab($, label)
115
116 return { text: result.backend ? `Tab renamed to “${label}” via ${result.backend}.` : `Could not rename the tab: ${result.reason}.` }
117 })
118
119 on('prompt.submit', async ($, e, next) => {
120 const result = await next(e)
121
122 const text = e.text.trim()
123 const isCandidate = isFromPerson(e.origin) && text !== '' && !text.startsWith('/')
124 if (!isCandidate || (await read($, isNamed))) return result
125
126 await update($, isNamed, () => true)
127 nameFromPrompt($, text).catch(() => update($, isNamed, () => false))
128
129 return result
130 }).catch(($, e, next) => next(e))
131}
132hooks/backends.ts 150 lines1// Works out how to rename the tab this process runs in, from its environment alone.
2// Pure: no `$`, so every terminal's detection is covered by plain tests.
3
4export type Env = {
5 HERDR_TAB_ID?: string
6 HERDR_BIN_PATH?: string
7 TMUX?: string
8 TMUX_PANE?: string
9 ZELLIJ?: string
10 ZELLIJ_PANE_ID?: string
11 STY?: string
12 WINDOW?: string
13 WEZTERM_PANE?: string
14 KITTY_WINDOW_ID?: string
15 KITTY_LISTEN_ON?: string
16 KONSOLE_DBUS_SERVICE?: string
17 KONSOLE_DBUS_SESSION?: string
18 ConEmuPID?: string
19 TERM_PROGRAM?: string
20 TERM?: string
21 WT_SESSION?: string
22 WSL_DISTRO_NAME?: string
23 CLAUDE_CODE_DISABLE_TERMINAL_TITLE?: string
24}
25
26// One way to rename the tab; the runner tries a plan's attempts in order until one succeeds.
27export type Attempt =
28 | { backend: string; run: string[] }
29 | { backend: 'zellij'; zellijPane: number }
30 | { backend: string; osc: string }
31
32export type Plan = { attempts: Attempt[]; note?: string }
33
34const ESC = '\u001b'
35const BEL = '\u0007'
36
37export function cleanLabel(raw: string): string {
38 return (raw.split('\n')[0] ?? '')
39 .replace(/[\u0000-\u001f\u007f]/g, '')
40 .replace(/["'`*_#%]/g, '')
41 .replace(/[.:;!?]+$/, '')
42 .trim()
43 .slice(0, 32)
44 .trim()
45}
46
47export function oscSequence(code: 0 | 1 | 2 | 30, label: string): string {
48 return `${ESC}]${code};${label}${BEL}`
49}
50
51// OSC 1 is the tab (not window) title on macOS terminals; Konsole's tab title is OSC 30.
52function oscCodeFor(env: Env): 0 | 1 | 30 {
53 if (env.TERM_PROGRAM === 'iTerm.app' || env.TERM_PROGRAM === 'Apple_Terminal') return 1
54 if (env.KONSOLE_DBUS_SESSION) return 30
55 return 0
56}
57
58function oscName(env: Env): string {
59 if (env.WT_SESSION) return 'windows-terminal'
60 if (env.TERM_PROGRAM) return env.TERM_PROGRAM.toLowerCase()
61 return 'osc'
62}
63
64export function isOn(value: string | undefined): boolean {
65 return value !== undefined && value !== '' && value !== '0' && value.toLowerCase() !== 'false'
66}
67
68// Whether an OSC title would last in this agent, and what to say when it wouldn't.
69export type OscPolicy = { isAllowed: boolean; note: string }
70
71const CLAUDE_OSC: (env: Env) => OscPolicy = env => ({
72 isAllowed: isOn(env.CLAUDE_CODE_DISABLE_TERMINAL_TITLE),
73 note: 'Claude Code already sets this terminal’s title; set CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1 to let this plugin name it instead',
74})
75
76export function plan(env: Env, label: string, osc: OscPolicy = CLAUDE_OSC(env)): Plan {
77 // Multiplexers first: they own the tab the person sees, and the outer terminal's variables leak into them.
78 if (env.HERDR_TAB_ID) {
79 return { attempts: [{ backend: 'herdr', run: [env.HERDR_BIN_PATH || 'herdr', 'tab', 'rename', env.HERDR_TAB_ID, label] }] }
80 }
81 if (env.TMUX && env.TMUX_PANE) {
82 // rename-window also turns automatic-rename off for that window, so the name sticks.
83 return { attempts: [{ backend: 'tmux', run: ['tmux', 'rename-window', '-t', env.TMUX_PANE, label] }] }
84 }
85 if (env.ZELLIJ !== undefined && env.ZELLIJ_PANE_ID && /^\d+$/.test(env.ZELLIJ_PANE_ID)) {
86 return { attempts: [{ backend: 'zellij', zellijPane: Number(env.ZELLIJ_PANE_ID) }] }
87 }
88 if (env.STY) {
89 return { attempts: [{ backend: 'screen', run: ['screen', '-S', env.STY, '-p', env.WINDOW || '0', '-X', 'title', label] }] }
90 }
91
92 const attempts: Attempt[] = []
93 if (env.WEZTERM_PANE) {
94 const wezterm = env.WSL_DISTRO_NAME ? 'wezterm.exe' : 'wezterm'
95 attempts.push({ backend: 'wezterm', run: [wezterm, 'cli', 'set-tab-title', '--pane-id', env.WEZTERM_PANE, label] })
96 }
97 if (env.KITTY_WINDOW_ID && env.KITTY_LISTEN_ON) {
98 const match = `window_id:${env.KITTY_WINDOW_ID}`
99 attempts.push({ backend: 'kitty', run: ['kitten', '@', '--to', env.KITTY_LISTEN_ON, 'set-tab-title', '--match', match, label] })
100 attempts.push({ backend: 'kitty', run: ['kitty', '@', '--to', env.KITTY_LISTEN_ON, 'set-tab-title', '--match', match, label] })
101 }
102 if (env.KONSOLE_DBUS_SERVICE && env.KONSOLE_DBUS_SESSION) {
103 for (const qdbus of ['qdbus6', 'qdbus']) {
104 const target = [qdbus, env.KONSOLE_DBUS_SERVICE, env.KONSOLE_DBUS_SESSION, 'org.kde.konsole.Session.setTabTitleFormat']
105 attempts.push({ backend: 'konsole', run: [...target, '0', label] })
106 }
107 }
108 if (env.ConEmuPID) {
109 attempts.push({ backend: 'conemu', run: ['ConEmuC', '-GuiMacro', 'Rename', '0', label] })
110 }
111
112 // Agents that write their own OSC title would overwrite ours, so it only lasts once the agent stops.
113 if (osc.isAllowed) {
114 attempts.push({ backend: oscName(env), osc: oscSequence(oscCodeFor(env), label) })
115 return { attempts }
116 }
117
118 return { attempts, note: attempts.length > 0 ? undefined : osc.note }
119}
120
121type ZellijPane = { id?: unknown; is_plugin?: unknown; tab_id?: unknown }
122
123// `zellij action list-panes --json --tab` (0.44+): plugin and terminal panes share ids, so skip plugins.
124export function zellijTabId(listJson: string, paneId: number): number | undefined {
125 let panes: unknown
126 try {
127 panes = JSON.parse(listJson)
128 } catch {
129 return undefined
130 }
131 if (!Array.isArray(panes)) return undefined
132 const pane = (panes as ZellijPane[]).find(one => one.id === paneId && one.is_plugin === false)
133
134 return typeof pane?.tab_id === 'number' ? pane.tab_id : undefined
135}
136
137// Children of Claude Code have no controlling tty, so walk up to the first ancestor that has one
138// (Claude Code itself) and write the sequence to that device. POSIX sh + ps: Linux, macOS, WSL.
139export const OSC_WRITER = [
140 'p=$PPID',
141 'while [ -n "$p" ] && [ "$p" -gt 1 ]; do',
142 ' t=$(ps -o tty= -p "$p" 2>/dev/null | tr -d " ")',
143 ' case "$t" in',
144 ' ""|"?"|"??") p=$(ps -o ppid= -p "$p" 2>/dev/null | tr -d " ") ;;',
145 ' *) printf "%s" "$1" > "/dev/$t"; exit $? ;;',
146 ' esac',
147 'done',
148 'exit 3',
149].join('\n')
150types/index.d.ts 8 lines1export type TabTitleBackend = string
2
3declare module 'claude-code' {
4 interface PluginState {
5 'terminal-tab-title': { isNamed: boolean }
6 }
7}
8