Release notes for a pending cs update, once per launch, with 1 to install it in place; /cs-update reopens the pane.

<img src="https://raw.githubusercontent.com/hex/claude-sessions/main/assets/banner.svg" width="100%" alt="cs: a session manager for Claude Code">
cs creates persistent workspaces for Claude Code, with session notes, conversation resume, and local git history.
Requires macOS or Linux, Bash 3.2+, git, jq, perl, Claude Code, and a UTF-8 locale. Remote control needs Claude Code 2.1.299+. Non-UTF-8 locales such as ja_JP.eucJP, ko_KR.eucKR, and zh_CN.eucCN cause syntax errors in cs and two of its hooks.
curl -fsSL https://github.com/hex/claude-sessions/releases/latest/download/install.sh | bash
From a checkout:
git clone https://github.com/hex/claude-sessions.git
cd claude-sessions
./install.sh
Review install.sh before running it. The piped command always installs the release, even inside a checkout. The installer puts the commands in ~/.local/bin/, registers hooks, and installs skills, mods, and Bash and Zsh completions. Updates and prebuilt picker downloads require ssh-keygen with -Y verify support to check the signed release manifest.
cs debug-api
One command, from any terminal: cs <name> creates the session the first time and resumes it every time after. It needs no project or git repository first.
cs debug-api. cs creates a workspace and opens Claude Code.Objective section and keeps notes under .cs/.cs debug-api again and accept the prompt to resume the recorded conversation.When you forget a name, a bare cs opens a picker of your sessions, and cs . reopens the one whose root you are in.
The statusline guide covers the quiet default layout, the band and the capsules, colors, thresholds, font setup, and agent rows.
| Feature | What it does | Details |
|---|---|---|
| Session records | Keeps objectives, per-actor narratives, memory, plans, checkpoints, and a timeline in .cs/. | Session layout |
| Crash recovery | Saves edits to shadow git refs without adding normal branch commits. | Autosave hook |
| Conversation rotation | Hands work to a fresh conversation through /rotate and /clear. | Rotation and queue hooks |
| Existing projects | cs -adopt <name> registers your project without moving it. | Adoption |
| Parallel worktrees | cs <base>@<feature> gives each feature its own checkout and session records. | Worktrees |
| Remote control | cs <name> --remote serves a session for the Claude app or web. | Remote control |
| Task queue | Runs confirmed tasks at turn boundaries, with failure, context, and quota breakers. | Queue behavior |
| Cross-session mail | Delivers local messages and wakes idle sessions for unread arrivals. | Mail wakes |
| Secrets | Uses the macOS keychain or encrypted files, with signed age exports for sync. | Secrets guide |
| Encrypted sessions | Keeps notes, transcripts, plans, and private state in a vault on macOS. | Encrypted sessions |
| Statusline | Shows session, git, model, context, queue, mail, and rate limits. | Statusline guide |
| Prompt grounding | Adds matching files, recent commits, changes, and clarification guidance to code-work prompts. | Scope hook |
| Prompt rewriting | Ctrl+G rewrites a draft in the composer for you to review before sending. | Prompt rewriter |
| Writing skills | Judges prose or drafts from a writing profile. | Skills |
| Session wrap | /wrap saves memory, summarizes the narrative, and archives completed tasks without committing. | Memory checks |
| Inline Mermaid | Draws supported flowcharts in replies, and a show-me skill answers "show me" with one. | Mermaid mod<br><img src="https://raw.githubusercontent.com/hex/claude-sessions/main/assets/mermaid.svg" width="260" alt="Reply prose, then the same prose with a drawn Mermaid chart"> |
| Chat feed | Folds each turn's tool calls into one line beside your messages and Claude's replies, off until you turn it on per session with the band's ctrl+x 3 or /feed on. | Feed mod |
| Release notes | Shows pending release notes in-session through /cs-update. | Update mod |
| Other front ends | Session hooks also work in desktop and IDE conversations opened in a .cs/ workspace. | Session resolution |
cs -uninstall
| Guide | Contents |
|---|---|
| Commands | Command reference, adoption, worktrees, queues, remote control, and completion. |
| Configuration | Every environment variable cs reads and the values it exports. |
| Session layout | Shared and local records, encryption, and merge policy. |
| Hooks | Hook behavior, prompt rewriting, and Claude Code mods. |
| Secrets | Storage backends, backups, and signed sync files. |
| Statusline | Segments, the quiet, band and capsule layouts, colors, thresholds, and agent rows. |
MIT. Contributions can start with an issue or pull request.
hooks/register.tsx 387 lines1/* @jsxRuntime classic */
2/* @jsx h */
3/* @jsxFrag Fragment */
4// ABOUTME: cs-update mod: when a cs launch found a newer release, one pane per load with its release notes, `1` to install it in place, Esc for later.
5// ABOUTME: Reads the launch's verdict from CS_UPDATE_AVAILABLE (a toast, not the pane, when CS_UPDATE_DECLINED names it), the cs path from CS_BIN, and the span cs cached; /cs-update reopens the pane; session.start writes a heartbeat for doctor.
6import type { On, EngineInterface, PluginOptions, RenderElement } from 'claude-code'
7
8declare const h: any
9declare const Fragment: any
10
11export const PANE = 'cs-update'
12// The /config row (`cs-update.showReleaseNotes`): off, the launch pane is
13// skipped and /cs-update still opens it.
14export const OPTION = 'showReleaseNotes'
15// Doctor observes the mod RUNNING, not merely installed (see the cs mod).
16export const HEARTBEAT = '.cs/local/cs-update.heartbeat'
17// The finished pane's outcome, written on a clean `cs -update` exit and read
18// back on the reloaded module's next render: installing the update rewrites
19// this mod's own deployed file, Claude Code reloads it and immediately
20// re-renders the open pane, and the reload drops the module state the `done`
21// pane was drawing from before this file existed. `session.start` does not
22// fire on a reload, only at load, so the restore cannot wait for it alone.
23export const DONE = '.cs/local/cs-update.done'
24// Where cs writes the id of the conversation it launched; a teammate claude
25// in the same directory has its own id and must not pop its own pane.
26export const STATE = '.cs/local/state'
27// KEEP IN SYNC with check_update_notify in lib/20-update.sh: the file cs
28// caches the pending release's changelog span in, keyed by that version.
29export const NOTES = (home: string, version: string) => `${home}/.cache/cs/update-notes-full-${version}`
30// How long `cs -update` may take: the download, the checksum, the signature.
31export const UPDATE_TIMEOUT_MS = 600000
32const VET_TIMEOUT_MS = 10000
33
34// Every line the mod hands the engine to draw on a surface of the engine's
35// own: its toasts, /cs-update's replies and its slash menu row, so the design
36// lab draws each from these words.
37export const TOASTS = {
38 declined: (version: string) => `cs ${version} is available · run cs -update to install it, or /cs-update for the notes`,
39 notRecorded: (err: string) => `could not record the finished update: ${err}`,
40} as const
41
42export const REPLIES = {
43 notLead: 'The release-notes pane belongs to the conversation cs launched.',
44 nothingPending: 'This launch found no newer cs; the check runs again at the next launch.',
45 notesOpen: 'Release notes are in the side pane.',
46} as const
47
48export const COMMANDS = {
49 'cs-update': { name: 'cs-update', description: 'Release notes for the pending cs update, with 1 to install it.' },
50} as const
51
52export type Section = { version: string; lines: string[] }
53
54// Links, bold and inline code, as _md_strip_inline strips them in bash: the
55// link text survives a replace, but every `**` and every backtick is removed
56// outright, paired or not, so the pane never shows raw markup.
57export function stripInline(s: string): string {
58 return s
59 .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
60 .replace(/\*\*/g, '')
61 .replace(/`/g, '')
62}
63
64// The span as check_update_notify caches it: `## X.Y.Z` opens a section; its
65// prose and bullets are kept in order with the marks stripped; `###` labels,
66// comments and blank lines are dropped. A continuation line keeps its indent.
67export function parseSpan(text: string): Section[] {
68 const sections: Section[] = []
69 for (const raw of text.split('\n')) {
70 const line = raw.replace(/\s+$/, '')
71 if (line.startsWith('## ')) { sections.push({ version: line.slice(3).trim(), lines: [] }); continue }
72 if (sections.length === 0) continue
73 if (line === '' || line.startsWith('#') || line.startsWith('<!--')) continue
74 sections[sections.length - 1].lines.push(stripInline(line))
75 }
76 return sections
77}
78
79// What the pane shows. Module state survives a /clear (as in the cs mod) and is
80// dropped on a reload, which is what "once per load" means. A finished update
81// is the one exception: the DONE marker survives the reload the update itself
82// causes, and the marker is redrawn from disk, either by session.start at the
83// next load or by the Pane render the reload triggers immediately, before
84// this state would otherwise sit empty.
85let version: string | undefined
86let sections: Section[] | undefined
87let accent: string | undefined
88let shown = false
89// The update key's life: idle until pressed, running while cs -update is,
90// then what happened. `failed` keeps the key, so a transient failure (a
91// download) gets another press; `done` retires it, since a second update
92// would install the same version again.
93export type Phase = 'idle' | 'running' | 'done' | 'failed'
94let phase: Phase = 'idle'
95let outcome = ''
96let registered = false
97
98export function register(on: On, options: PluginOptions) {
99 version = undefined; sections = undefined; accent = undefined; shown = false
100 phase = 'idle'; outcome = ''
101 registered = false
102 const wanted = options[OPTION] !== false
103
104 on('session.start', async ($, e, next) => {
105 if (!registered) {
106 registered = true
107 await $.command.register(COMMANDS['cs-update'])
108 }
109 if ((await $.fs.exists(`${e.cwd}/.cs/local`)) && (await mayWriteControlFiles($, e.cwd))) {
110 await $.fs.write(`${e.cwd}/${HEARTBEAT}`, `${new Date().toISOString()}\n`)
111 }
112 if (!shown && await isLead($, e.cwd)) {
113 if (!(await restoreDone($, e.cwd)) && wanted) {
114 const pending = await $.env.get('CS_UPDATE_AVAILABLE')
115 // The launch's own question was answered no for this version: one
116 // line says it is still there, and the pane waits for /cs-update.
117 const declined = await $.env.get('CS_UPDATE_DECLINED')
118 if (pending && declined === pending) {
119 shown = true
120 $.ui.toast(TOASTS.declined(pending))
121 } else if (pending) { shown = true; await openPane($, e.cwd, pending) }
122 }
123 }
124 return next(e)
125 })
126
127 on('ui.render', { component: 'Pane' }, async ($, e, next) => {
128 if (e.requestId !== PANE) return next(e)
129 // The engine re-renders the open pane the instant it reloads this
130 // module, before session.start (which does not fire on a reload) gets a
131 // chance to restore it, so a pane asked to draw with no module state
132 // tries the marker itself before giving up to the ordinary gate. It asks
133 // the lead gate first, as session.start does, so a directory the
134 // sessions root does not name gets no pane back.
135 if (version === undefined) {
136 const cwd = await $.session.cwd()
137 if (!(await isLead($, cwd)) || !(await restoreDone($, cwd))) return next(e)
138 }
139 const el = await $.ui.resolve(e)
140 // Every path here has set it: the launch's openPane, or restoreDone's.
141 if (version === undefined) throw new Error('cs-update: the pane drew with no pending version')
142 return drawPane({ version, sections, accent, phase, outcome }, el, () => runUpdate($))
143 })
144
145 // On demand: the same pane, whether or not the launch opened it (the
146 // option off, or dismissed). A registered command is answered with
147 // `{ text }` (the contract; an unanswered run prints "no hook answered"),
148 // so the pane carries the notes and the text just points at it. A launch
149 // that found nothing pending has nothing to show, and says so instead; a
150 // teammate (which inherits the exports) is refused as the launch pane
151 // refuses it.
152 on('command.run', { command: 'cs-update' }, async ($, e) => {
153 const cwd = await $.session.cwd()
154 if (!(await isLead($, cwd))) return { text: REPLIES.notLead }
155 const pending = await $.env.get('CS_UPDATE_AVAILABLE')
156 if (!pending) return { text: REPLIES.nothingPending }
157 // After a reload (which drops the module state, and fires no
158 // session.start) a pane dismissed before the update installed leaves
159 // nothing open for the render path to restore, so the command asks the
160 // marker itself before it offers an install that already finished.
161 if (version === undefined && (await restoreDone($, cwd))) return { text: REPLIES.notesOpen }
162 shown = true
163 await openPane($, cwd, pending)
164 return { text: REPLIES.notesOpen }
165 })
166}
167
168// What the pane is drawn from: the pending version, its notes, the session
169// colour as rgb, and where the update key's life stands.
170export type PaneView = { version: string; sections: Section[] | undefined; accent: string | undefined; phase: Phase; outcome: string }
171
172export function drawPane(v: PaneView, el: ReturnType<EngineInterface['ui']['resolve']>, update: () => void | Promise<void>): RenderElement {
173 const { Box, Text, Button } = el
174 const { version, sections, accent, phase, outcome } = v
175 // A lone pane draws no title of its own (the tab shows only with two or
176 // more), so the body opens with it. The pane does not scroll (measured
177 // live 2026-09-22 on Claude Code 2.1.278), and a long changelog span
178 // pushes anything below it off the bottom, so the keys sit right under
179 // the title, above the notes, where a long span can never hide them.
180 // Version headings take the session colour cs recorded, as the status
181 // bar's name does; a continuation line hangs under its bullet on the
182 // changelog's own indent, which parseSpan keeps in the line (as a bullet
183 // keeps its `- `), so the text is drawn verbatim and no margin doubles it.
184 return (
185 <Box flexDirection="column" paddingX={1}>
186 <Text bold>{`cs ${version} is available`}</Text>
187 <Box marginTop={1} flexDirection="column">
188 {phase === 'running' && <Text dimColor>{`updating… running cs -update ${version}`}</Text>}
189 {(phase === 'done' || phase === 'failed') && <Text>{outcome}</Text>}
190 {(phase === 'idle' || phase === 'failed') && (
191 <Box>
192 {/* a Button is a block: nested in a Text the engine refuses the whole tree (measured in the cs mod), so the keys stand in a Box */}
193 <Button key="cs-update-now" hotkey="1" plain label="update now" onPress={update} />
194 <Text dimColor>{' Esc: later'}</Text>
195 </Box>
196 )}
197 {phase === 'idle' && <Text dimColor>{'Installs in place; the new files take effect on your next launch.'}</Text>}
198 {phase === 'done' && <Text dimColor>{'Esc: close'}</Text>}
199 </Box>
200 {sections === undefined || sections.length === 0
201 ? <Box marginTop={1}><Text>{`Release notes could not be fetched at launch; the update is ${version}.`}</Text></Box>
202 : sections.map(s => (
203 <Box key={`v-${s.version}`} flexDirection="column" marginTop={1}>
204 <Text bold color={accent}>{s.version}</Text>
205 {s.lines.map((line, j) => (
206 <Box key={`l-${s.version}-${j}`}>
207 <Text>{line}</Text>
208 </Box>
209 ))}
210 </Box>
211 ))}
212 </Box>
213 )
214}
215
216// The conversation cs launched is the one whose id cs recorded before the
217// launch; a teammate in the same directory reads the same file and does not
218// match. A directory the sessions root does not name, or one without the
219// file, is not a cs session: no pane. The id may be quoted (KEEP IN SYNC with
220// ownsRotation in mods/cs).
221async function isLead($: EngineInterface, cwd: string): Promise<boolean> {
222 if (await $.fs.exists(`${cwd}/.cs/local/disabled`)) return false
223 if (!(await isCsSession($, cwd))) return false
224 let state: string
225 try { state = await $.fs.read(`${cwd}/${STATE}`) } catch { return false }
226 const lead = state.match(/^claude_session_id: *"?([^"\s]+)"?[ \t]*$/m)?.[1]
227 return lead !== undefined && lead === (await $.session.id())
228}
229
230// The /color palette as rgb, since the engine paints rgb(), #hex, ansi256(),
231// ansi: and theme keys but draws a bare name like `red` in the default ink. KEEP IN SYNC with _sgr in
232// bin/cs-statusline (tests/test_mod_rotate.sh pins every value here against it).
233const SESSION_PALETTE: Record<string, string> = {
234 red: '220,38,38', blue: '106,155,204', green: '22,163,74', yellow: '202,138,4',
235 purple: '130,125,189', orange: '217,119,87', pink: '196,102,134', cyan: '8,145,178',
236}
237
238// The session colour cs recorded, for the version headings; none, or a name
239// outside the palette, draws them in the default ink.
240async function sessionColor($: EngineInterface, cwd: string): Promise<string | undefined> {
241 try {
242 const state = await $.fs.read(`${cwd}/${STATE}`)
243 const name = state.match(/^claude_session_color: *"?([^"\s]+)"?[ \t]*$/m)?.[1]
244 return name !== undefined && Object.hasOwn(SESSION_PALETTE, name) ? `rgb(${SESSION_PALETTE[name]})` : undefined
245 } catch { return undefined }
246}
247
248async function openPane($: EngineInterface, cwd: string, pending: string) {
249 version = pending
250 accent = await sessionColor($, cwd)
251 const home = await $.env.get('HOME')
252 let text = ''
253 try { text = home ? await $.fs.read(NOTES(home, pending)) : '' } catch { text = '' }
254 sections = parseSpan(text)
255 // focus is a request the surface grants only over an idle, empty composer;
256 // without it the keys stay with the prompt and `1` does nothing.
257 await $.ui.open({ id: PANE, title: `cs ${pending} is available`, focus: true, closeOnEscape: true })
258}
259
260// Restores the finished pane from the DONE marker on a reload, since the
261// reload itself drops the module state the pane was showing. Answers whether
262// it restored anything: false leaves the caller to its own fallback (the
263// launch-pane gate in session.start, or the ordinary render in ui.render). A
264// marker naming a version that is no longer CS_UPDATE_AVAILABLE is stale (a
265// later launch, nothing pending, or something newer) and is cleared rather
266// than redrawn; `$.fs` has no delete, so an empty write is the tombstone and
267// empty text reads as absent.
268async function restoreDone($: EngineInterface, cwd: string): Promise<boolean> {
269 let text: string
270 try { text = await $.fs.read(`${cwd}/${DONE}`) } catch { return false }
271 const [doneVersion, line] = text.split('\n')
272 if (!doneVersion || line === undefined) return false
273 const pending = await $.env.get('CS_UPDATE_AVAILABLE')
274 if (pending !== doneVersion) {
275 if (await mayWriteControlFiles($, cwd)) await $.fs.write(`${cwd}/${DONE}`, '')
276 return false
277 }
278 shown = true; phase = 'done'; outcome = line
279 await openPane($, cwd, doneVersion)
280 return true
281}
282
283// Every write this mod makes into .cs/local asks this first: the sessions root
284// names the directory, and cs trusts its control files.
285async function mayWriteControlFiles($: EngineInterface, cwd: string): Promise<boolean> {
286 return (await isCsSession($, cwd)) && (await sessionVetted($, cwd))
287}
288
289// KEEP IN SYNC with isCsSession and resolvedPath in mods/cs (the two mods
290// deploy as separate plugins and share no module).
291// Whether directory `cwd` is a cs session. Nothing inside a directory can
292// prove it: a cloned repository may carry any file under .cs/, .cs/local
293// included. The sessions root ($CS_SESSIONS_ROOT, else ~/.claude-sessions) is
294// what a clone cannot carry: the directory is a session when the root's entry
295// under its own name, or under the session_name an adopted session's state
296// records, lands on the directory itself. The recorded name is only a
297// candidate, so it may not reach outside the root. Identity is by resolved
298// path, as the hooks compare by inode: a link at the root and a home reached
299// through a symlink each spell the same directory another way.
300async function isCsSession($: EngineInterface, cwd: string): Promise<boolean> {
301 const home = await $.env.get('HOME')
302 const root = (await $.env.get('CS_SESSIONS_ROOT')) || (home ? `${home}/.claude-sessions` : undefined)
303 if (root === undefined) return false
304 const here = await resolvedPath($, cwd)
305 if (here === undefined) return false
306 const dir = cwd.replace(/\/+$/, '')
307 const names = [dir.slice(dir.lastIndexOf('/') + 1)]
308 let state = ''
309 try {
310 state = await $.fs.read(`${cwd}/.cs/local/state`)
311 } catch {
312 // no state: only the directory's own name is a candidate
313 }
314 const recorded = state.match(/^session_name: *"?([^"\s/]+)"?[ \t]*$/m)?.[1]
315 if (recorded !== undefined && recorded !== '.' && recorded !== '..') names.push(recorded)
316 for (const name of names) {
317 if ((await resolvedPath($, `${root}/${name}`)) === here) return true
318 }
319 return false
320}
321
322// Where `path` lands once every link is followed; undefined when it leads
323// nowhere or cannot be read, which proves nothing about a session.
324async function resolvedPath($: EngineInterface, path: string): Promise<string | undefined> {
325 try {
326 return (await $.fs.stat(path, { resolve: true })).realPath
327 } catch {
328 return undefined
329 }
330}
331
332// Whether cs trusts this session's control files, by the rule the cs mod and
333// the hooks ask (cs -vet-session): while git tracks a file in .cs/local or
334// .cs/private, this mod writes nothing there. An answer cs cannot give is a
335// no. Nothing is said here: the cs mod toasts the same refusal once.
336async function sessionVetted($: EngineInterface, cwd: string): Promise<boolean> {
337 const bin = await $.env.get('CS_BIN')
338 if (!bin) return false
339 try {
340 const { exitCode } = await $.process.run([bin, '-vet-session', cwd], { timeoutMs: VET_TIMEOUT_MS })
341 return exitCode === 0
342 } catch {
343 // A spawn that fails is a refusal: the write it guards is skipped.
344 return false
345 }
346}
347
348// Runs the update cs would run from the shell, by the path launch exported
349// (no shell: `$.process.run` takes an argv, and the claude process's PATH is
350// not the launching shell's). The pane keeps the outcome until dismissed, so
351// it is read rather than flashed. The new files take effect on the next
352// launch for the rest of this claude, but Claude Code reloads this mod's own
353// file as soon as the update installs it, which is why a clean exit also
354// writes the DONE marker restoreDone reads back.
355async function runUpdate($: EngineInterface) {
356 // Claimed before the first await: two presses in one tick must not both
357 // pass the guard and start two installers.
358 if (phase === 'running' || phase === 'done') return
359 phase = 'running'; outcome = ''
360 $.ui.invalidate('ui.render')
361 try {
362 const bin = await $.env.get('CS_BIN')
363 if (!bin) {
364 phase = 'failed'; outcome = 'The launch did not say where cs is; run `cs -update` from a shell.'
365 $.ui.invalidate('ui.render'); return
366 }
367 const { exitCode, stderr } = await $.process.run([bin, '-update'], { timeoutMs: UPDATE_TIMEOUT_MS })
368 if (exitCode === 0) {
369 // Version-neutral: cs -update resolves the latest release when it runs,
370 // which may be newer than the one this launch saw.
371 phase = 'done'; outcome = 'Update finished. Takes effect on your next launch.'
372 try {
373 const cwd = await $.session.cwd()
374 if (await mayWriteControlFiles($, cwd)) await $.fs.write(`${cwd}/${DONE}`, `${version}\n${outcome}\n`)
375 } catch (err) {
376 $.ui.toast(TOASTS.notRecorded(String(err instanceof Error ? err.message : err)))
377 }
378 } else {
379 const tail = stderr.split('\n').filter(l => l.trim() !== '').slice(-5).join('\n')
380 phase = 'failed'; outcome = `cs -update exited ${exitCode}.\n${tail}`
381 }
382 } catch (err) {
383 phase = 'failed'; outcome = `cs -update did not run: ${String(err instanceof Error ? err.message : err)}`
384 }
385 $.ui.invalidate('ui.render')
386}
387