SLOPSHOPPER

tab-tag

Names the iTerm2 tab with one or two uppercase words for what the session is about, and gives each session's tab a random colour.

commandpromptmodelprocesstimer
v0.2.0MITupdated 2026-10-09JCPetrelli/tab-tag
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · tab-tag
› fix the failing auth test and add an audit log call ⏺ Read(src/auth.ts) ⎿ Read 6 lines ⏺ Update(src/auth.ts) ⎿ Added 2 lines, removed 1 line ⏺ Bash(bun test) ⎿ 3 pass, 1 fail ● Done. refresh now rejects expired claims and logs an audit event. ✻ Worked for 42s · done 4:20 PM › /tab ⎿ tab-tag: Tab named OK. ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts
README

tab-tag

license: MIT

A Claude Code mod that gives every session's iTerm2 tab its own colour and a one- or two-word name, so you can tell five open sessions apart without clicking through them.

Five identical tabs get a colour each, then a name from the first prompt

What it does

WhenWhat happens to the tab
A session startsIt gets a random colour from a palette of twelve, and the name of the folder you started in
You send the first promptIt is renamed to one or two uppercase words for what the prompt is about, for example CHECKOUT TESTS
The first prompt is a slash commandThe command's name becomes the tab name: /release-notes gives RELEASE NOTES
The first prompt is a GitHub link and nothing elseThe repository names the tab, with the issue or pull request number when there is room: BRICKWISE 42
The first prompt is any other link and nothing elseThe tab keeps the folder's name until the turn ends, then it is named from what Claude read behind the link
You run /tab HOTFIXThe tab is named HOTFIX
You run /tab with no wordsThe tab is named again from the last prompts of the conversation
You resume a sessionIt gets back the colour and the name it had
You run /clearThe colour stays, and the next prompt names the tab again
The session endsThe tab goes back to iTerm2's default colour and title

A tab is named once. Later prompts do not rename it, so the name does not change while you work. Use /tab when the subject changes.

Requirements

  • macOS with iTerm2. In any other terminal the mod does nothing.
  • A Claude Code version with mods (plugins of function hooks). Tested with 2.1.294.

Install

claude plugin marketplace add JCPetrelli/tab-tag
claude plugin install tab-tag@tab-tag

Start a new session in iTerm2 and the tab is coloured.

To remove it:

claude plugin uninstall tab-tag@tab-tag
claude plugin marketplace remove tab-tag

Codex

The codex/ folder holds the same tool as a plugin for the Codex CLI. It needs Node.js. It is new: the tests run the hook script, but not yet a full Codex session.

codex plugin marketplace add JCPetrelli/tab-tag
codex plugin add tab-tag@tab-tag

Then start codex in iTerm2, run /hooks and trust the four tab-tag hooks. Codex does not run a plugin's hooks before you trust them.

The Codex plugin makes no model call: the name is the first two telling words of your first prompt. A link to anywhere but GitHub leaves the name to the next prompt. There is no /tab command.

The naming model

The name comes from one small model call per session: the first 1,500 characters of your first prompt go to the model, and the reply is limited to 16 tokens. The default model is claude-haiku-5-5.

You can change the model with /plugin configure tab-tag@tab-tag, option Naming model. If you leave that option empty, the mod makes no model call and uses the first two telling words of the prompt (i want to find slow queries in the search page gives SLOW QUERIES).

The mod uses the same fallback when the model does not answer.

How it works

FileJob
hooks/register.tsThe hooks: colour and name at session.start, naming at prompt.submit, the /tab command, reset at session.end
hooks/words.tsThe palette, and the rules that turn text into a title
bin/tab.shWrites iTerm2's escape sequences for tab title and tab colour to the session's terminal
tests/tab.test.tsTests for the title rules and for a full session
codex/hooks/tab-tag.mjsThe Codex plugin: one script for Codex's SessionStart, UserPromptSubmit, Stop and SessionEnd hooks

Two details:

  • Claude Code writes its own tab title when a turn starts and when it ends. The mod writes its title again at those moments, and once more 1.5 seconds later.
  • A title contains only the letters A to Z, the digits and spaces. A prompt or a model reply cannot put an escape sequence into your terminal through the tab name.

Colour and name are saved per session ID in the mod's own store. The mod keeps the last 300 sessions.

Limits

  • iTerm2 only. Other terminals have different escape sequences for tab colour, or none.
  • The colour is random, so two sessions can get the same one.
  • Another tool that sets the tab colour or title for the same session (for example TabChroma, which colours the tab by Claude's state) will overwrite this one, or be overwritten by it.

Development

git clone https://github.com/JCPetrelli/tab-tag
cd tab-tag
claude plugin validate .   # manifest and hooks, as the engine reads them
claude plugin test .       # tests/*.test.ts
node --test codex/tests/tab-tag.test.mjs   # the Codex plugin

To try your copy in a session, add the folder as a marketplace (claude plugin marketplace add ./tab-tag) and install from it. After an edit, run /reload-plugins in the session.

The animation

The demo is a three.js scene in one file, docs/animation/index.html. Open the file in a browser to see it loop. To render the video and the GIF again (needs Google Chrome and ffmpeg):

cd docs/animation
npm install
node render.mjs

Licence

MIT

Source 3 files
hooks/register.ts 188 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { TabColor } from '../types'
5import {
6  isLinkOnly,
7  lastSegment,
8  pickColor,
9  titleFromCommand,
10  titleFromLink,
11  titleFromWords,
12  toTitle,
13} from './words'
14
15const title = atom({ plugin: 'tab-tag', key: 'title' } as const, '')
16const color = atom({ plugin: 'tab-tag', key: 'color' } as const, null)
17const isNamed = atom({ plugin: 'tab-tag', key: 'isNamed' } as const, false)
18const isLinkWaiting = atom({ plugin: 'tab-tag', key: 'isLinkWaiting' } as const, false)
19
20const SYSTEM =
21  'You label terminal tabs. Reply with ONE or TWO words, uppercase, naming the project or topic of the request. No punctuation, no explanation.'
22const MAX_SAVED = 300
23
24type Saved = { title: string; color: TabColor; isNamed: boolean }
25
26async function tab($: EngineInterface, args: readonly string[]) {
27  const script = `${$.plugin.root}/bin/tab.sh`
28  await $.process.run(['sh', script, ...args], { timeoutMs: 5000 }).catch(() => undefined)
29}
30
31// Claude Code writes its own title as a turn starts and ends, so the tab's is
32// written again at those moments.
33async function paint($: EngineInterface) {
34  const text = await read($, title)
35
36  if (text !== '') {
37    await tab($, ['title', text])
38  }
39}
40
41async function save($: EngineInterface) {
42  const tint = await read($, color)
43
44  if (tint === null) {
45    return
46  }
47
48  const saved: Saved = {
49    title: await read($, title),
50    color: tint,
51    isNamed: await read($, isNamed),
52  }
53  await $.store.set(`tab:${await $.session.id()}`, saved)
54  const keys = (await $.store.keys()).filter(key => key.startsWith('tab:'))
55
56  for (const key of keys.slice(0, Math.max(0, keys.length - MAX_SAVED))) {
57    await $.store.delete(key)
58  }
59}
60
61async function rename($: EngineInterface, text: string) {
62  if (text === '') {
63    return
64  }
65
66  await update($, title, () => text)
67  await update($, isNamed, () => true)
68  await paint($)
69  await save($)
70}
71
72// The last messages of the conversation, as text for a title.
73async function conversation($: EngineInterface, roles: readonly string[]) {
74  return (await $.session.messages())
75    .filter(message => roles.includes(message.role) && message.text !== '' && !message.text.startsWith('/'))
76    .slice(-6)
77    .map(message => message.text.slice(0, 300))
78    .join('\n')
79}
80
81// `words` is the text the fallback reads when no model answers.
82async function summarize($: EngineInterface, prompt: string, model: string, words = prompt) {
83  let text = ''
84
85  if (model !== '') {
86    const reply = await $.model.complete({
87      model,
88      system: SYSTEM,
89      prompt: prompt.slice(0, 1500),
90      maxTokens: 16,
91    })
92    text = reply.isAnswered ? toTitle(reply.text) : ''
93  }
94
95  await rename($, text === '' ? titleFromWords(words) : text)
96}
97
98export const register: Register = (on, options) => {
99  const model = String(options.model ?? '')
100
101  on('session.start', async ($, e, next) => {
102    if (!e.isInteractive) {
103      return next(e)
104    }
105
106    await $.command.register({
107      name: 'tab',
108      description: 'Rename this iTerm2 tab: /tab TWO WORDS, or /tab alone to name it again from the conversation',
109      argumentHint: '[words]',
110    })
111    const found = (await $.store.get(`tab:${await $.session.id()}`)) as Saved | undefined
112    const tint = found?.color ?? pickColor(Math.random())
113    const text = found?.title ?? toTitle(lastSegment(e.cwd))
114    await update($, color, () => tint)
115    await update($, title, () => text)
116    await update($, isNamed, () => found?.isNamed ?? false)
117    await tab($, ['color', String(tint.red), String(tint.green), String(tint.blue)])
118    await paint($)
119
120    return next(e)
121  })
122
123  on('prompt.submit', async ($, e, next) => {
124    const entered = await next(e)
125    const isPerson = e.origin.kind === 'composer'
126
127    if (isPerson && !(await read($, isNamed))) {
128      const fromCommand = titleFromCommand(e.text)
129
130      if (fromCommand === null && isLinkOnly(e.text)) {
131        // A link alone: GitHub's address names the repository. Any other link
132        // is named when the turn ends, from what Claude read behind it.
133        const fromLink = titleFromLink(e.text)
134        await update($, isLinkWaiting, () => fromLink === '')
135        await rename($, fromLink)
136      } else if (fromCommand === null) {
137        $.clock.after(0, () => summarize($, e.text, model))
138      } else {
139        await rename($, fromCommand)
140      }
141    }
142
143    $.clock.after(1500, () => paint($))
144
145    return entered
146  }).catch(($, e, next) => next(e))
147
148  on('turn.complete', async ($, e, next) => {
149    const done = await next(e)
150
151    if (e.agentId === undefined) {
152      if ((await read($, isLinkWaiting)) && !(await read($, isNamed))) {
153        await summarize($, await conversation($, ['user', 'assistant']), model, await conversation($, ['user']))
154      }
155
156      await update($, isLinkWaiting, () => false)
157      await paint($)
158      $.clock.after(1500, () => paint($))
159    }
160
161    return done
162  })
163
164  on('command.run', { command: 'tab' }, async ($, e) => {
165    const asked = toTitle(e.args)
166
167    if (asked !== '') {
168      await rename($, asked)
169
170      return { text: `Tab named ${asked}.` }
171    }
172
173    await summarize($, await conversation($, ['user']), model)
174
175    return { text: `Tab named ${await read($, title)}.` }
176  })
177
178  on('session.end', async ($, e, next) => {
179    if (e.reason === 'clear') {
180      await update($, isNamed, () => false)
181    } else {
182      await tab($, ['reset'])
183    }
184
185    return next(e)
186  })
187}
188
hooks/words.ts 105 lines
1import type { TabColor } from '../types'
2
3const MAX_WORDS = 2
4const MAX_LENGTH = 24
5
6// Commands that say nothing about what the session is for.
7const SILENT_COMMANDS = new Set([
8  'clear', 'compact', 'model', 'config', 'help', 'resume', 'tab', 'fast',
9  'loop', 'status', 'usage', 'context', 'cost', 'init', 'login', 'doctor',
10])
11
12const STOP_WORDS = new Set([
13  'THE', 'AND', 'FOR', 'WITH', 'THAT', 'THIS', 'FROM', 'INTO', 'HAVE', 'WANT',
14  'WOULD', 'COULD', 'SHOULD', 'PLEASE', 'MAKE', 'LETS', 'WHAT', 'WHEN', 'WHERE',
15  'ABOUT', 'SOME', 'YOUR', 'JUST', 'LIKE', 'NEED', 'CAN', 'YOU', 'HOW', 'ARE',
16  'USE', 'ALSO', 'THEN', 'THERE', 'WILL', 'ONLINE', 'FIND', 'CHECK', 'SEARCH',
17])
18
19const URL = /https?:\/\/\S+/i
20const GITHUB = /https?:\/\/(?:www\.)?github\.com\/[\w.-]+\/([\w.-]+)(?:\/(?:issues|pull|discussions)\/(\d+))?/i
21
22export const PALETTE: readonly TabColor[] = [
23  { red: 231, green: 76, blue: 60 },
24  { red: 230, green: 126, blue: 34 },
25  { red: 241, green: 196, blue: 15 },
26  { red: 46, green: 204, blue: 113 },
27  { red: 26, green: 188, blue: 156 },
28  { red: 52, green: 152, blue: 219 },
29  { red: 91, green: 110, blue: 225 },
30  { red: 155, green: 89, blue: 182 },
31  { red: 232, green: 67, blue: 147 },
32  { red: 149, green: 165, blue: 166 },
33  { red: 0, green: 184, blue: 212 },
34  { red: 139, green: 195, blue: 74 },
35]
36
37export const pickColor = (random: number): TabColor =>
38  PALETTE[Math.floor(random * PALETTE.length) % PALETTE.length] ?? { red: 52, green: 152, blue: 219 }
39
40// One or two uppercase words of letters and digits: nothing that could carry
41// an escape sequence into the terminal.
42export const toTitle = (text: string): string => {
43  const words = text
44    .toUpperCase()
45    .replace(/[^A-Z0-9]+/g, ' ')
46    .trim()
47    .split(' ')
48    .filter(Boolean)
49    .slice(0, MAX_WORDS)
50  let title = words.join(' ')
51
52  if (title.length > MAX_LENGTH) {
53    title = (words[0] ?? '').slice(0, MAX_LENGTH)
54  }
55
56  return title
57}
58
59// The slash command a prompt runs, when it names what the session is for.
60export const titleFromCommand = (prompt: string): string | null => {
61  const found = /^\s*\/([\w:-]+)/.exec(prompt)
62
63  if (found === null) {
64    return null
65  }
66
67  const name = (found[1] ?? '').split(':').at(-1) ?? ''
68
69  return SILENT_COMMANDS.has(name) ? '' : toTitle(name)
70}
71
72// The fallback when no model answers: the prompt's first two telling words.
73export const titleFromWords = (prompt: string): string => {
74  const words = prompt
75    .toUpperCase()
76    .replace(/HTTPS?:\S+/g, ' ')
77    .replace(/[^A-Z0-9]+/g, ' ')
78    .split(' ')
79    .filter(word => word.length > 2 && !STOP_WORDS.has(word))
80
81  return toTitle(words.slice(0, MAX_WORDS).join(' '))
82}
83
84// A prompt that is a link and no telling word: the link's address says little
85// about the subject, so the tab is named later.
86export const isLinkOnly = (prompt: string): boolean => URL.test(prompt) && titleFromWords(prompt) === ''
87
88// A GitHub link names its repository, and its issue or pull request when the
89// repository's name leaves room for the number.
90export const titleFromLink = (prompt: string): string => {
91  const found = GITHUB.exec(prompt)
92
93  if (found === null) {
94    return ''
95  }
96
97  const repo = toTitle((found[1] ?? '').replace(/\.git$/, ''))
98  const number = found[2] ?? ''
99
100  return number !== '' && !repo.includes(' ') ? toTitle(`${repo} ${number}`) : repo
101}
102
103export const lastSegment = (path: string): string =>
104  path.split('/').filter(Boolean).at(-1) ?? path
105
types/index.d.ts 8 lines
1export type TabColor = { red: number; green: number; blue: number }
2
3declare module 'claude-code' {
4  interface PluginState {
5    'tab-tag': { title: string; color: TabColor | null; isNamed: boolean; isLinkWaiting: boolean }
6  }
7}
8