Kick off and wrap up working sessions with your start and end commands, and give each session a useful title

Small Claude Code mods: plugins of function hooks that change what Claude Code shows or does, in the terminal and in the desktop app's Code tab.
In a terminal Claude Code session:
/plugin install <mod> --marketplace enhki/claude-mods
Answer y to add the marketplace, then pick the user scope so the mod loads in every session, desktop ones included.
| Mod | What it does |
|---|---|
statusline-desktop | Draws your terminal status line above the prompt in the desktop app |
forgejo-issues | Browse, search and manage the current repo's Forgejo or Gitea issues in a pane |
work-session | Kicks off and wraps up working sessions with your own start and end commands, and titles each session |
walkthrough | A checklist pane for testing by hand: mark each step, add notes, send the results back in one message |
The desktop app doesn't run your statusLine command. This mod does: it picks the command the way Claude Code does (project .claude/settings.local.json, then .claude/settings.json, then ~/.claude/settings.json), pipes it the same JSON the terminal would (model, cwd, cost, context window, rate limits), and draws the first line it prints in the band above the prompt.
config-file) sets one; otherwise they map to the app's own theme colours.current_usage reads slightly lower than in the terminal (output tokens come through as 0)./issues opens a pane on the issues of the repo the session runs in. The forge and repo come from git remote get-url origin (ssh or https), so it works for any Forgejo or Gitea host, Codeberg included.
kind/bug sit under their scope, exclusive scopes pick one); a milestone picker.label:bug, -label:wontfix, label:kind/, milestone:"Some name", is:closed. Enter opens the top match.#N mentions as chips that open in the pane..claude/forgejo-issues.json in the folder you start Claude in, as {"repos": ["owner/repo"]} on the same forge. The pane then shows a button per repo (a picker past five), and /issues <repo> jumps to one by name or prefix. The last repo picked is remembered for that project.Token. The mod needs an API token with issue read/write and repository read. Put it in ~/.config/claude-mods/secrets/forgejo.env (folder 700, file 600), keyed by host so a token only ever goes to its own forge:
FORGEJO_TOKEN_CODEBERG_ORG=...
FORGEJO_TOKEN_GIT_EXAMPLE_COM=...
Without one, it falls back to fgj's config for that host. The mod also stops Claude's own file and shell tools from reading that secrets folder.
Settings (the plugin's options):
| Setting | Default | What it does |
|---|---|---|
apiUrl | empty | The API base when it isn't https://<remote host>/api/v1 |
requireCommentOnClose | on | Closing needs a comment, posted before the close |
requireMilestone | off | New issues need a milestone |
requireLabelFrom | empty | New issues need one of these comma-separated labels |
editorCommand | empty | Adds Open in editor: e.g. ghostty --gtk-single-instance=false --class=popup.editor -e nvim {file} |
Desktop notes. The desktop app currently drops Button and Markdown-link presses from plugin panes, so every control here is a small Client that posts a message instead; and it passes no paste into a Client, so for long or pasted text use Open in editor. The editor command must wait until you close the file; one that returns at once (a launcher that forks) leaves a Use editor text button to pull the file back by hand. Ghostty needs --gtk-single-instance=false for this, or it may hand the window to a running instance and return at once.
For projects where you start and end each working session with your own slash commands (a "continue working session" and an "end working session", say /cws and /ews), this mod offers them at the right moments and gives each session a title you can tell apart in the session list.
/clear, not a resume) in a project that has the start command, a band above the prompt offers it: press 1 to run it, 2 to skip, or just type something else. Set Kickoff to auto to run it straight away, or off.set_session_title tool and a line of context asking it to title the session once its focus is clear: <Project> S<n> · <focus> when the project numbers its sessions, else <Project> · <focus>. The title shows from your next message on. A /rename of your own wins: the mod stops setting it.Projects without the start command see nothing. In the desktop app the band draws above the desktop status line rather than in place of it.
Settings (the plugin's options):
| Setting | Default | What it does |
|---|---|---|
startCommand | cws | The command that kicks a session off, without the slash |
endCommand | ews | The command that wraps one up |
kickoff | band | band offers it, auto runs it at start, off never |
wrapAtPercent | 75 | Context fullness that brings up the wrap offer; 0 turns it off |
When Claude asks you to check something by hand (run a demo, resize a window, try a key), it publishes the steps to a Walkthrough pane instead of a list in chat, and you send the results back from there.
publish_walkthrough tool refuses a step that doesn't say what to expect. Publishing again replaces the list./walkthrough. The step you're on is drawn open: its command with Copy, what to expect, Pass / Fail / Skip and a note. Marking it opens the next one; done steps fold to one line you can click to reopen. Pressing a mark again takes it back.p pass, f fail, s skip, c copy, r send.Screenshots don't go through the pane: paste them in the prompt as usual. No settings.
A mod is a plugin of function hooks: a plugin.json, a hooks/hooks.json naming one TypeScript module, and that module's register(on, options). In a Claude Code session, the bundled plugin-authoring skill holds the full API (types, examples, the test kit); load it before writing one.
| Kind | Where | Loads |
|---|---|---|
| General, shareable | here, mods/<name>/ + an entry in .claude-plugin/marketplace.json | everywhere, once installed at user scope |
| Tied to one project, or naming private hosts | that project's .claude/skills/<name>/ | in that project's sessions only, watched for edits |
| Just for you, everywhere, private | ~/.claude/skills/<name>/ | every session, watched for edits |
Anything that names a private host, a person or a machine stays out of this public repo: make it a project mod, or read the value from a setting.
plugin-authoring skill gives a mods folder that hot-reloads when each turn ends: the quickest loop.mods/<name>/, list it in the marketplace file, and install it from this clone (below). From then on, edits are live after /reload-plugins.claude plugin validate mods/<name>, claude plugin test mods/<name>, and a type-check. Bump version in the mod's plugin.json when behaviour changes, so GitHub installs update.claude plugin test runs *.test.ts(x) against the engine itself; a test stands in for engine calls with on('<event>', () => ({ value: … })).userConfig (shown in the plugin's options); nothing personal is hard-coded.~/.config/claude-mods/secrets/<service>.env (folder 700, file 600), keyed by host where a token belongs to a host. A mod that reads one also keeps Claude's own tools out of that folder (see forgejo-issues/hooks/guard.ts).$.state) outlives reloads and upgrades: read and update it through helpers that fill in defaults, or a field a new version adds arrives undefined.ui_press not handled in ~/.config/Claude/logs/claude.ai-web.log). Input, Select and Client messages do. Make each pressable control its own small Client that posts a message (forgejo-issues/hooks/pill.tsx).Client's pointer and key listeners once, on its first draw. Each set is a message to the page, and many Clients re-setting them on every redraw get unmounted for flooding it.Client per clickable item makes hit-testing unnecessary.Client, and the native Input is one line at a fixed width. For long text, hand off to an external editor (forgejo-issues's Open in editor).<mod>: <event> hook skipped: threw … names the handler that did.Clone, then add the clone itself as your marketplace so edits are live after /reload-plugins with no reinstall:
claude plugin marketplace add ~/repos/claude-mods
claude plugin install <mod>@claude-mods --scope user
Check a mod before committing:
claude plugin validate mods/<mod>
claude plugin test mods/<mod>hooks/register.tsx 270 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface as $, Register } from 'claude-code'
3
4import type { Kickoff, Title, Wrap } from '../types'
5import {
6 cleanTitle,
7 commandFiles,
8 commandName,
9 hasCommand,
10 isFreshStart,
11 isStartPrompt,
12 kickoffMode,
13 startContext,
14 TITLE_NUDGES,
15 TITLE_TOOL_DESCRIPTION,
16 titleNudge,
17 wrapReason,
18} from './session'
19import type { KickoffMode } from './session'
20
21const PLUGIN = 'work-session'
22const TOOL = 'set_session_title'
23// The desktop app keeps its own session titles and ignores a hook's sessionTitle.
24const APP_TITLE_TOOL = 'mcp__ccd_session_mgmt__set_session_title'
25// Press ids carry the plugin's name: the band is shared with other plugins' Clients.
26const P = {
27 kickoff: `${PLUGIN}:kickoff`,
28 skip: `${PLUGIN}:skip`,
29 wrap: `${PLUGIN}:wrap`,
30 later: `${PLUGIN}:later`,
31} as const
32
33const EMPTY_KICKOFF: Kickoff = { phase: 'none', command: '', told: false, nudges: 0 }
34const EMPTY_WRAP: Wrap = { phase: 'none', reason: '' }
35const EMPTY_TITLE: Title = { applied: null }
36
37const kickoff = atom({ plugin: 'work-session', key: 'kickoff' } as const, EMPTY_KICKOFF)
38const wrap = atom({ plugin: 'work-session', key: 'wrap' } as const, EMPTY_WRAP)
39const title = atom({ plugin: 'work-session', key: 'title' } as const, EMPTY_TITLE)
40
41let start = 'cws'
42let end = 'ews'
43let mode: KickoffMode = 'band'
44let wrapAt = 75
45
46// Saved state from an older version lacks newer fields: fill defaults on reads and updates.
47const readKickoff = async ($: $): Promise<Kickoff> => ({ ...EMPTY_KICKOFF, ...(await read($, kickoff)) })
48const readWrap = async ($: $): Promise<Wrap> => ({ ...EMPTY_WRAP, ...(await read($, wrap)) })
49const readTitle = async ($: $): Promise<Title> => ({ ...EMPTY_TITLE, ...(await read($, title)) })
50const setKickoff = ($: $, fn: (k: Kickoff) => Kickoff) => update($, kickoff, (x): Kickoff => fn({ ...EMPTY_KICKOFF, ...x }))
51const setWrap = ($: $, fn: (w: Wrap) => Wrap) => update($, wrap, (x): Wrap => fn({ ...EMPTY_WRAP, ...x }))
52const setTitle = ($: $, fn: (t: Title) => Title) => update($, title, (x): Title => fn({ ...EMPTY_TITLE, ...x }))
53
54async function runCommand($: $, name: string): Promise<void> {
55 try {
56 await $.command.run({ command: name, args: '' })
57 } catch (err) {
58 $.ui.log(`${PLUGIN}: could not run /${name}: ${err instanceof Error ? err.message : String(err)}`)
59 }
60}
61
62// The engine lists commands only once the session is bound, never at SessionStart.
63// Null while it cannot; with `files`, the project's own command and skill files answer instead.
64async function commandExists($: $, name: string, files: boolean): Promise<boolean | null> {
65 try {
66 return hasCommand(await $.command.list(), name)
67 } catch {
68 if (!files) return null
69 const found = await Promise.all(commandFiles(await $.session.cwd(), name).map(p => $.fs.exists(p).catch(() => false)))
70 return found.some(Boolean)
71 }
72}
73
74/**
75 * Settles a pending kickoff into an offer, an auto run or nothing; the first caller wins.
76 * Without `files` it leaves the kickoff pending while the commands cannot be listed.
77 */
78async function resolveKickoff($: $, files: boolean): Promise<Kickoff> {
79 const k = await readKickoff($)
80 if (k.phase !== 'pending') return k
81 const exists = await commandExists($, start, files)
82 if (exists === null) return k
83 if (!exists) {
84 await setKickoff($, x => (x.phase === 'pending' ? { ...x, phase: 'none' } : x))
85 return readKickoff($)
86 }
87 const phase = mode === 'auto' ? 'started' : 'offered'
88 await setKickoff($, x => (x.phase === 'pending' ? { ...x, phase } : x))
89 if (mode === 'auto') void runCommand($, start)
90 return readKickoff($)
91}
92
93// Retried until the session is bound (the terminal mounts within a few hundred ms),
94// the last try reading the project's files instead.
95const SETTLE_TRIES = 20
96const SETTLE_MS = 250
97
98function settleSoon($: $, tries: number): void {
99 $.clock.after(SETTLE_MS, async () => {
100 const k = await resolveKickoff($, tries <= 1)
101 if (k.phase === 'pending' && tries > 1) settleSoon($, tries - 1)
102 })
103}
104
105async function setAppTitle($: $, t: string): Promise<string> {
106 try {
107 if (!(await $.tool.list()).some(x => x.name === APP_TITLE_TOOL)) return ''
108 const r = await $.tool.call({ tool: APP_TITLE_TOOL, session_id: 'self', title: t } as never)
109 return (r as { isError?: boolean }).isError ? ` The app refused the rename: ${(r as { text?: string }).text ?? ''}` : ''
110 } catch (err) {
111 return ` The app could not rename it: ${err instanceof Error ? err.message : String(err)}`
112 }
113}
114
115async function press($: $, id: string): Promise<void> {
116 if (id === P.kickoff) {
117 await setKickoff($, k => ({ ...k, phase: 'started' }))
118 // Not awaited: the command runs once the session is idle, after this press returns.
119 void runCommand($, start)
120 } else if (id === P.skip) {
121 await setKickoff($, k => ({ ...k, phase: 'skipped' }))
122 } else if (id === P.wrap) {
123 await setWrap($, w => ({ ...w, phase: 'started' }))
124 void runCommand($, end)
125 } else if (id === P.later) {
126 await setWrap($, w => ({ ...w, phase: 'dismissed' }))
127 }
128}
129
130export const register: Register = (on, options) => {
131 start = commandName(options?.startCommand, 'cws')
132 end = commandName(options?.endCommand, 'ews')
133 mode = kickoffMode(options?.kickoff)
134 wrapAt = typeof options?.wrapAtPercent === 'number' ? options.wrapAtPercent : 75
135
136 on('session.start', async ($, e, next) => {
137 const result = await next(e)
138 await $.tool.register({
139 name: TOOL,
140 description: TITLE_TOOL_DESCRIPTION,
141 inputSchema: {
142 type: 'object',
143 properties: { title: { type: 'string', description: 'The session title, e.g. "Atlas S12 · Search filters"' } },
144 required: ['title'],
145 },
146 isDeferred: false,
147 })
148 return result
149 })
150
151 // The classic event carries the start's source: only a fresh session is kicked off.
152 // The commands cannot be listed yet, so the kickoff waits as pending: the
153 // terminal settles it at the first draw of the band, the desktop (which starts
154 // the session with the first message) at the first prompt.
155 on('classic.SessionStart', async ($, e, next) => {
156 const result = await next(e)
157 if (!isFreshStart(e.source)) return result
158 await Promise.all([
159 setKickoff($, () => (mode === 'off' ? EMPTY_KICKOFF : { ...EMPTY_KICKOFF, phase: 'pending', command: start })),
160 setWrap($, () => EMPTY_WRAP),
161 setTitle($, () => EMPTY_TITLE),
162 ])
163 if (mode !== 'off') settleSoon($, SETTLE_TRIES)
164 return result
165 })
166
167 // The start context rides the first prompt of a kicked-off session; the title
168 // is re-sent with every prompt, so the session keeps it.
169 on('classic.UserPromptSubmit', async ($, e, next) => {
170 const result = await next(e)
171 const k = await resolveKickoff($, true)
172 const context = [...(result.additionalContext ?? [])]
173 const t = await readTitle($)
174 if (k.phase !== 'none' && !k.told) {
175 await setKickoff($, x => ({ ...x, told: true }))
176 context.push(startContext(start))
177 } else if (k.phase === 'started' && !t.applied && k.nudges < TITLE_NUDGES && !isStartPrompt(e.prompt, start)) {
178 // The message after the kickoff usually picks the focus: the moment to title it.
179 await setKickoff($, x => ({ ...x, nudges: x.nudges + 1 }))
180 context.push(titleNudge(start))
181 }
182 return {
183 ...result,
184 ...(context.length ? { additionalContext: context } : {}),
185 ...(t.applied ? { sessionTitle: t.applied } : {}),
186 }
187 })
188
189 on('tool.call', { tool: 'mcp__work-session__set_session_title' }, async ($, e) => {
190 const cleaned = cleanTitle((e as unknown as { title?: unknown }).title)
191 if ('error' in cleaned) return { deny: `${TOOL}: ${cleaned.error}` }
192 await setTitle($, () => ({ applied: cleaned.title }))
193 const app = await setAppTitle($, cleaned.title)
194 return { result: `Session title set to "${cleaned.title}"; it shows from the user's next message.${app}` }
195 })
196
197 // Anything the person types instead of pressing 1 means this session needs no kickoff.
198 on('prompt.submit', async ($, e, next) => {
199 if (e.origin?.kind === 'composer' && (await readKickoff($)).phase === 'offered') {
200 await setKickoff($, k => ({ ...k, phase: 'skipped' }))
201 }
202 return next(e)
203 })
204
205 on('command.run', async ($, e, next) => {
206 if (e.command === start) await setKickoff($, k => ({ ...k, phase: 'started' }))
207 if (e.command === end) await setWrap($, w => ({ ...w, phase: 'started' }))
208 // A /rename by hand wins: stop re-sending this mod's title.
209 if (e.command === 'rename') await setTitle($, () => EMPTY_TITLE)
210 return next(e)
211 })
212
213 on('turn.complete', async ($, e, next) => {
214 const result = await next(e)
215 if (e.agentId) return result
216 if ((await readWrap($)).phase !== 'none') return result
217 const reason = wrapReason(await $.session.usage(), wrapAt)
218 if (reason && hasCommand(await $.command.list(), end)) {
219 await setWrap($, () => ({ phase: 'offered', reason }))
220 }
221 return result
222 })
223
224 on('ui.message', { component: 'AbovePrompt' }, async ($, e, next) => {
225 const id = (e.data as { press?: unknown } | null)?.press
226 if (typeof id !== 'string' || !id.startsWith(`${PLUGIN}:`)) return next(e)
227 await press($, id)
228 return {}
229 })
230
231 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
232 // The band's controls need a terminal (Buttons) or the desktop (Clients).
233 if (e.props.hasSurvey || e.props.isWorking) return next(e)
234 if (e.surface !== 'terminal' && e.surface !== 'desktop') return next(e)
235 const [k, w] = await Promise.all([readKickoff($), readWrap($)])
236 const offer =
237 k.phase === 'offered'
238 ? { glyph: '▸', text: `Kick off this session with /${start}`, yes: P.kickoff, yesLabel: `Run /${start}`, no: P.skip, noLabel: 'Skip' }
239 : w.phase === 'offered'
240 ? { glyph: '◐', text: `Time to wrap? ${w.reason}`, yes: P.wrap, yesLabel: `Run /${end}`, no: P.later, noLabel: 'Later' }
241 : null
242 if (!offer) return next(e)
243 const { Box, Text, Button, Client } = $.ui.resolve({ ...e, surface: e.surface })
244 // The terminal draws Buttons for their digit hotkeys; the desktop drops Button
245 // presses from plugin UI, so it gets Client pills posting { press }.
246 const control = (id: string, label: string, hotkey: string) =>
247 e.surface === 'terminal' ? (
248 <Button key={id} label={label} hotkey={hotkey} plain onPress={() => press($, id)} />
249 ) : (
250 <Client key={id} module="./pill.tsx" props={{ id, label, hotkey }} />
251 )
252 const row = (
253 <Box key={PLUGIN} flexDirection="row" gap={2} paddingX={1}>
254 <Text color="suggestion">{offer.glyph}</Text>
255 <Text>{offer.text}</Text>
256 {control(offer.yes, offer.yesLabel, '1')}
257 {control(offer.no, offer.noLabel, '2')}
258 </Box>
259 )
260 // Stacked over what the plugins beneath draw (a desktop status line), not instead of it.
261 const below = await next(e)
262 return (
263 <Box flexDirection="column">
264 {row}
265 {below}
266 </Box>
267 )
268 })
269}
270hooks/session.ts 101 lines1/** Pure decisions behind the hooks: what to offer, when, and what a title may be. */
2
3export type KickoffMode = 'band' | 'auto' | 'off'
4export type StartSource = 'startup' | 'resume' | 'clear' | 'compact' | 'fork'
5
6export const TITLE_MAX = 80
7// A rate limit this used up is worth wrapping before it runs out mid-task.
8export const RATE_LIMIT_WRAP = 90
9
10export function kickoffMode(raw: unknown): KickoffMode {
11 return raw === 'auto' || raw === 'off' ? raw : 'band'
12}
13
14/** A command name as typed in settings: no slash, no spaces; empty when unusable. */
15export function commandName(raw: unknown, fallback: string): string {
16 const name = (typeof raw === 'string' ? raw : fallback).trim().replace(/^\//, '')
17 return /^[\w:.-]+$/.test(name) ? name : ''
18}
19
20export function hasCommand(list: readonly { name: string }[], name: string): boolean {
21 return name !== '' && list.some(c => c.name === name)
22}
23
24/** Where a project keeps a slash command of its own, as a command file or a skill. */
25export function commandFiles(cwd: string, name: string): string[] {
26 const root = cwd.replace(/\/+$/, '')
27 return [`${root}/.claude/commands/${name}.md`, `${root}/.claude/skills/${name}/SKILL.md`]
28}
29
30/** A fresh working session starts at launch or after /clear; a resume or compact continues one. */
31export function isFreshStart(source: StartSource): boolean {
32 return source === 'startup' || source === 'clear'
33}
34
35/** The title as it will be shown, or why it is refused. */
36export function cleanTitle(raw: unknown): { title: string } | { error: string } {
37 if (typeof raw !== 'string') return { error: 'title must be a string' }
38 const title = raw.replace(/\s+/g, ' ').trim()
39 if (title === '') return { error: 'title is empty' }
40 if (title.length > TITLE_MAX) return { error: `title is ${title.length} characters; keep it under ${TITLE_MAX}` }
41 return { title }
42}
43
44type Usage = {
45 context: { percent?: number; tokens?: number; window: number }
46 rateLimits: readonly { kind: string; percentUsed: number }[]
47}
48
49export function contextPercent(usage: Usage): number | null {
50 const { percent, tokens, window } = usage.context
51 if (typeof percent === 'number') return Math.round(percent)
52 if (typeof tokens === 'number' && window > 0) return Math.round((tokens / window) * 100)
53 return null
54}
55
56/** Why a wrap is worth offering now, worded for the band; null when it is not. */
57export function wrapReason(usage: Usage, atPercent: number): string | null {
58 if (atPercent <= 0) return null
59 const limit = [...usage.rateLimits].sort((a, b) => b.percentUsed - a.percentUsed)[0]
60 if (limit && limit.percentUsed >= RATE_LIMIT_WRAP) return `${limit.kind} limit ${Math.round(limit.percentUsed)}% used`
61 const percent = contextPercent(usage)
62 if (percent !== null && percent >= atPercent) return `context ${percent}% full`
63 return null
64}
65
66/** What the model is told at a fresh start in a project that has the start command. */
67export function startContext(start: string): string {
68 return [
69 `This project kicks off working sessions with /${start}.`,
70 `Once a session's focus is known (after /${start} presents and the user picks what to work on,`,
71 'or once the task is clear), call the set_session_title tool with a short title:',
72 '"<Project> S<n> · <focus>" when the project numbers its sessions (e.g. "Atlas S12 · Search filters"),',
73 'else "<Project> · <focus>". Call it again when the focus changes.',
74 ].join(' ')
75}
76
77// Reminders after the start command, while the session has no title.
78export const TITLE_NUDGES = 2
79
80/** The prompt that is the start command itself, typed or run from the band. */
81export function isStartPrompt(prompt: unknown, start: string): boolean {
82 return typeof prompt === 'string' && new RegExp(`^/${start.replace(/[.]/g, '\\.')}(\\s|$)`).test(prompt.trim())
83}
84
85/** Said with the prompts that follow the start command until a title is set. */
86export function titleNudge(start: string): string {
87 return [
88 `/${start} has run and this session has no title yet.`,
89 'If this message settles what the session is about, call the set_session_title tool first,',
90 "before anything else, numbering it from the session /" + start + " reported.",
91 ].join(' ')
92}
93
94export const TITLE_TOOL_DESCRIPTION = [
95 "Sets this session's title, shown in the session list and the terminal tab, so the user can tell sessions apart.",
96 'Call it once the focus of the session is clear, and again when it changes.',
97 'Format: "<Project> S<n> · <focus>" when the project numbers its sessions (e.g. "Atlas S12 · Search filters"),',
98 `else "<Project> · <focus>". Under ${TITLE_MAX} characters.`,
99 'The title appears from the user\'s next message on.',
100].join(' ')
101hooks/pill.tsx 42 lines1import type { ClientModule } from 'claude-code'
2
3/**
4 * A pressable control drawn as a Client: a click, Enter or Space posts
5 * `{ press: id }` to the hooks module. The desktop app drops Button presses
6 * from plugin UI, while Client messages arrive (claude-mods' desktop rules);
7 * the terminal draws real Buttons instead, for their digit hotkeys.
8 */
9export type PillProps = { id: string; label: string; hotkey: string }
10
11type Local = { hover: boolean }
12
13const Pill: ClientModule<PillProps, Local> = (props, surface) => {
14 const { Box, Text } = surface.elements
15 const state = surface.state ?? { hover: false }
16 // Listeners are set once, on the first draw: each set is a message to the page.
17 if (surface.state === undefined) {
18 const id = props.id
19 surface.onPointer(e => {
20 const cur = surface.state ?? { hover: false }
21 if (e.type === 'leave') {
22 if (cur.hover) surface.setState({ hover: false })
23 } else if (!cur.hover) {
24 surface.setState({ hover: true })
25 }
26 if (e.type === 'down' && (e.button ?? 'left') === 'left') surface.post({ press: id })
27 })
28 surface.onKey(e => {
29 if (e.key === 'return' || e.key === ' ') surface.post({ press: id })
30 })
31 surface.setState(state)
32 }
33 return (
34 <Box flexDirection="row" borderStyle="round" borderColor={state.hover ? 'suggestion' : 'subtle'} paddingX={1}>
35 <Text color="suggestion">{props.hotkey}</Text>
36 <Text>: {props.label}</Text>
37 </Box>
38 )
39}
40
41export default Pill
42types/index.d.ts 19 lines1/** `pending`: a fresh start not yet checked for the start command (the engine lists commands only once the session is bound). */
2export type KickoffPhase = 'none' | 'pending' | 'offered' | 'started' | 'skipped'
3export type WrapPhase = 'none' | 'offered' | 'dismissed' | 'started'
4
5/**
6 * `told`: the model has had the start context (titling) in this session.
7 * `nudges`: title reminders sent after the start command ran, while no title is set.
8 */
9export type Kickoff = { phase: KickoffPhase; command: string; told: boolean; nudges: number }
10export type Wrap = { phase: WrapPhase; reason: string }
11/** `applied`: re-sent with every prompt so the session keeps it; null hands titling back to Claude Code. */
12export type Title = { applied: string | null }
13
14declare module 'claude-code' {
15 interface PluginState {
16 'work-session': { kickoff: Kickoff; wrap: Wrap; title: Title }
17 }
18}
19