SLOPSHOPPER

turn-pulse

A band above the prompt summarizing the last turn: duration, files edited (edits outside the working folder flagged), tool results, and the turn's share of the…

bandguardcommandtoaststatusprompt
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · turn-pulse
› 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 › /pulse ⎿ turn-pulse: Turn pulse band hidden. ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts ⚠ turn-pulse: session: 5h +0%
README

claude-code-mods

Small mods for Claude Code, built on its function-hooks plugin API.

ModWhat it does
turn-pulseA band above the prompt summarizing the last turn, plus a live status line while Claude works.
notes/note saves chat text to a notes list shared across projects; /notes opens it in a side pane.
sessions/sessions opens a side pane listing the sessions running on this machine and whether each is working or idle.

Early access. The mod API these use is marked EARLY ACCESS and may change between Claude Code releases. Built and tested on Claude Code 2.1.293, on Windows, in the desktop app's Code tab.

Install

In a terminal, add the marketplace once:

claude plugin marketplace add ilya-paskhover/claude-code-mods

Then install one line per mod:

claude plugin install turn-pulse@claude-code-mods
claude plugin install notes@claude-code-mods
claude plugin install sessions@claude-code-mods

This installs in the user scope, so the mod loads in every new session, including sessions the desktop app starts. Inside an interactive claude session, /plugin marketplace add and /plugin install take the same arguments. /plugin is not available inside the desktop app's Code tab, so install from a terminal.

turn-pulse

turn-pulse: the last-turn band above the prompt and the session total in the status line

A band labeled ◆ last turn sits above the prompt after each turn:

  • Duration of the turn, in yellow past 2 minutes.
  • Files edited, in green. An edit outside the session's working folder shows in bold red, with a 15 second toast.
  • Tool results: ✓ N ok, and ✗ N failed (Tool ×n) when something failed.
  • Usage-limit cost of the turn, for example 5h +1% · week +0.3%.

The status line shows ▶ Tool · N ok · ✗ N failed live during a turn, and session: 5h +6% · week +2% between turns. A toast appears when a turn takes 60 seconds or more. /pulse hides or shows the band. In a cloud session /pulse prints the last turn and the session total as text instead, since the Claude app showing the session may not draw the band or the status line.

Limits:

  • Usage numbers are account-wide, so other sessions running at the same time count toward them.
  • Tracking starts when the mod loads, and the handling of a limit window resetting is heuristic.
  • Paths are compared case-insensitively. That is right on Windows but could misjudge an "outside" edit on a case-sensitive Linux file system.

notes

notes: the Notes side pane with an open note

  • /note <text> saves the typed text. With text selected in the transcript, /note <comment> saves the selection with the typed text as its comment.
  • Notes are kept in the mod's own store, shared across all sessions and projects.
  • /notes opens a Notes side pane: notes render as Markdown, long ones fold behind More/Less, and each has a ☐/☑ done toggle, Delete, and Jump (scroll to the message it came from; same session only). Show/Hide done and Clear done act on the whole list.
  • Text pasted into the prompt has its <pasted_content> wrapper stripped.

Limits:

  • In the desktop app the selection is not passed to mods, so /note there needs pasted or typed text, and Jump never appears. Selection is documented to work in the fullscreen terminal; I have not verified that. Tracked in #1.
  • Jump only scrolls within the session the note was taken in; mods can't open another session. Tracked in #4.

sessions

sessions: the Sessions side pane with two running sessions and a Switch button

/sessions opens a Sessions side pane listing every Claude Code session running on this machine, from any folder:

  • A count of running and working sessions, and a Refresh button.
  • One row per session: ● working (yellow) or ○ idle (green), the session's name, how long since its last activity, and "this session" on your own row.
  • A Switch button on each session the desktop app started opens that session in the app. Sessions started in a terminal have no button.
  • Working sessions sort first, then the most recently active.
  • The pane refreshes every 5 seconds while it is open and stops when you close it.
  • The pane opens by itself once per local session: at start in a terminal, or when the desktop app connects. It opens unfocused, so the prompt keeps the keyboard. Close it and it stays closed for that session, through reloads and desktop reconnects.

In a cloud session, where the container holds only that one session, /sessions lists your 10 most recent cloud sessions instead, from the claude-code-remote MCP server every cloud session has:

  • ● working, ◐ needs input with what the session is waiting on, ✗ failed, or ○ idle (finished or ready for review).
  • An Open link on each other session goes to its page on claude.ai.
  • The pane refreshes every 30 seconds, since each refresh is an API call.

Limits:

  • Opened by itself, the pane shows only in a window at least 144 columns wide, or 110 once you have opened it with /sessions. In a narrower one it waits until you run /sessions. Cloud sessions don't open it by themselves, since each refresh there is an API call; /sessions opens it.
  • The list comes from Claude Code's own files in ~/.claude/sessions/ (or $CLAUDE_CONFIG_DIR/sessions/), not from the mod API. That format is undocumented and could change in any release; if no file can be read, the pane says so instead of showing a wrong list.
  • Locally, only sessions running on this machine appear: closed sessions and cloud sessions do not. In a cloud session, only cloud sessions appear, not the ones on your computer.
  • The cloud list is the claude-code-remote server's list_sessions output, which is not a documented format either; if it can't be read, the pane says so. In a live cloud session the plugin loads and /sessions runs, but the pane does not appear; tracked in #14.
  • Switch works only for sessions the desktop app started, through an undocumented claude:// link, not a mod API (tracked in #4).
  • In the desktop app, a click on the pane first gives it focus, so a button may need two clicks: one to focus the pane, one to press. The pane opens focused, so the first click right after /sessions works; after you click elsewhere, click anywhere in the pane (or Refresh) first. Press Esc to give the keyboard back to the prompt.
  • Sessions and Notes open as tabs in the same side pane; mod panes can't be shown side by side. Tracked in #5.
  • A session that crashed can leave its file behind. The session file only changes when the status changes, so a "working" row shows dimmed as "working?" once it has been busy for 30 minutes: either a long turn or a crash. The pane can't tell which.

Developing

Each mod is a plugin folder under plugins/. To run a working copy instead of the installed one, name the folders in the env block of ~/.claude/settings.json (separated by ; on Windows, : elsewhere) and uninstall the marketplace copy so the mod does not load twice:

{
  "env": {
    "CLAUDE_CODE_PLUGIN_DIRS": "/path/to/claude-code-mods/plugins/turn-pulse;/path/to/claude-code-mods/plugins/notes"
  }
}

Interactive sessions watch those folders and reload a mod when its files are saved. Checks, per mod folder:

claude plugin validate plugins/notes
claude plugin test plugins/notes

To try a branch's copy of a mod in a cloud session, add these lines to the cloud environment's setup script, set BRANCH and MOD, then start a new session. They copy the mod into a one-mod marketplace and install it from there:

BRANCH=claude/my-branch
MOD=sessions
git clone --depth 1 -b "$BRANCH" https://github.com/ilya-paskhover/claude-code-mods /tmp/mod-branch
M=/tmp/mod-branch-mkt
mkdir -p $M/.claude-plugin $M/plugins
cp -r /tmp/mod-branch/plugins/$MOD $M/plugins/
cat > $M/.claude-plugin/marketplace.json <<EOF
{"name":"mod-branch","owner":{"name":"Ilya Paskhover"},"plugins":[{"name":"$MOD","source":"./plugins/$MOD"}]}
EOF
claude plugin marketplace add $M && claude plugin install $MOD@mod-branch

In the session, claude plugin list should then show <mod>@mod-branch enabled.

Each mod's tsconfig.json extends the type declarations the engine writes into .claude-plugin/types/ when it loads the mod (gitignored), so tsc -p plugins/notes works once the mod has loaded once.

License

MIT

Source 2 files
hooks/register.tsx 249 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register, SessionRateLimit } from 'claude-code'
3
4import type { EditedFile, Pulse, WindowTrack } from '../types'
5
6const last = atom({ plugin: 'turn-pulse', key: 'last' } as const, null)
7const isHidden = atom({ plugin: 'turn-pulse', key: 'isHidden' } as const, false)
8const windows = atom({ plugin: 'turn-pulse', key: 'windows' } as const, {})
9
10const EDITING = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit'])
11const SLOW_SECONDS = 120
12const TOAST_SECONDS = 60
13const WINDOW_LABELS: Record<string, string> = { five_hour: '5h', seven_day: 'week' }
14
15const baseName = (path: string) => path.split(/[\\/]/).pop() ?? path
16
17// Windows paths compare case-insensitively and with either slash.
18const normalize = (path: string) => path.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase()
19const isAbsolute = (path: string) => /^([a-z]:)?[\\/]/i.test(path)
20const isOutsideOf = (cwd: string, path: string) => {
21  if (!isAbsolute(path) || cwd === '') return false
22  const root = normalize(cwd)
23  const target = normalize(path)
24  return target !== root && !target.startsWith(`${root}/`)
25}
26
27const formatTime = (seconds: number) =>
28  seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`
29
30const round = (n: number) => Math.round(n * 10) / 10
31const label = (kind: string) => WINDOW_LABELS[kind] ?? kind
32const formatSpent = (spent: Record<string, number>) =>
33  Object.entries(spent)
34    .map(([kind, n]) => `${label(kind)} +${round(n)}%`)
35    .join(' · ')
36
37// The limits are account-wide: the session's share is how far each window
38// moved since the session first saw it, carried across window resets.
39const track = (tracks: Record<string, WindowTrack>, limits: SessionRateLimit[]) => {
40  const next = { ...tracks }
41  for (const limit of limits) {
42    const now = limit.percentUsed
43    const seen = next[limit.kind]
44    if (seen === undefined) {
45      next[limit.kind] = { start: now, last: now, carried: 0, resetsAt: limit.resetsAt }
46      continue
47    }
48    const hasReset =
49      (limit.resetsAt !== undefined && seen.resetsAt !== undefined && limit.resetsAt !== seen.resetsAt) ||
50      now < seen.last - 0.5
51    next[limit.kind] = hasReset
52      ? { start: 0, last: now, carried: seen.carried + (seen.last - seen.start), resetsAt: limit.resetsAt }
53      : { ...seen, last: now, resetsAt: limit.resetsAt ?? seen.resetsAt }
54  }
55  return next
56}
57
58const sessionSpent = (tracks: Record<string, WindowTrack>) =>
59  Object.fromEntries(
60    Object.entries(tracks).map(([kind, t]) => [kind, Math.max(0, t.carried + t.last - t.start)]),
61  )
62
63const countFails = (failed: Record<string, number>) => Object.values(failed).reduce((a, b) => a + b, 0)
64
65function liveStatus($: EngineInterface, tool: string, ok: number, fails: number) {
66  $.ui.status(`▶ ${tool} · ${ok} ok${fails > 0 ? ` · ✗ ${fails} failed` : ''}`)
67}
68
69// Reads the windows, folds them into the session's tracks, returns its spend.
70async function measure($: EngineInterface, limits?: SessionRateLimit[]) {
71  const reading = limits ?? (await $.session.usage()).rateLimits
72  const tracks = await update($, windows, tracks => track(tracks, reading))
73  return sessionSpent(tracks)
74}
75
76function idleStatus($: EngineInterface, spent: Record<string, number>) {
77  $.ui.status(Object.keys(spent).length > 0 ? `session: ${formatSpent(spent)}` : undefined)
78}
79
80const isCloud = async ($: EngineInterface) => (await $.env.get('CLAUDE_CODE_REMOTE')) === 'true'
81
82// A pulse saved by an older version of this mod has another shape: skip it.
83const isCurrent = (pulse: Pulse | null): pulse is Pulse => pulse !== null && typeof pulse.ok === 'number'
84
85// The parts of a pulse the band and /pulse both show.
86function describe(pulse: Pulse) {
87  const outside = pulse.files.filter(file => file.isOutside)
88  const inside = pulse.files.filter(file => !file.isOutside)
89  return {
90    outside,
91    inside,
92    shown: inside.slice(0, 3).map(file => file.name).join(', '),
93    more: inside.length > 3 ? ` +${inside.length - 3}` : '',
94    fails: countFails(pulse.failed),
95    failures: Object.entries(pulse.failed)
96      .map(([tool, n]) => (n > 1 ? `${tool} ×${n}` : tool))
97      .join(', '),
98    spent: pulse.spent ?? {},
99  }
100}
101
102// The band as one line of text, for /pulse in cloud sessions. Edits outside
103// the folder show full paths, as in the toast, since text has the room.
104function summarize(pulse: Pulse) {
105  const { outside, inside, shown, more, fails, failures, spent } = describe(pulse)
106  const parts = ['◆ last turn', `⏱ ${formatTime(pulse.seconds)}`]
107  if (outside.length > 0) parts.push(`⚠ outside: ${outside.map(file => file.path).join(', ')}`)
108  if (inside.length > 0) parts.push(`✎ ${shown}${more}`)
109  if (pulse.files.length === 0) parts.push('no edits')
110  parts.push(`✓ ${pulse.ok} ok`)
111  if (fails > 0) parts.push(`✗ ${fails} failed (${failures})`)
112  if (Object.keys(spent).length > 0) parts.push(formatSpent(spent))
113  return parts.join(' · ')
114}
115
116export const register: Register = on => {
117  let cwd = ''
118  let startedAt = 0
119  let inTurn = false
120  let ok = 0
121  let files = new Map<string, EditedFile>()
122  let failed: Record<string, number> = {}
123  let spentAtStart: Record<string, number> = {}
124
125  on('prompt.submit', async ($, e, next) => {
126    startedAt = await $.clock.now()
127    cwd = await $.session.cwd()
128    inTurn = true
129    ok = 0
130    files = new Map()
131    failed = {}
132    spentAtStart = await measure($)
133
134    return next(e)
135  })
136
137  on('tool.call', async ($, e, next) => {
138    liveStatus($, e.tool, ok, countFails(failed))
139
140    const ran = await next(e)
141    if (ran.deny === undefined && ran.isError === true) {
142      failed[e.tool] = (failed[e.tool] ?? 0) + 1
143    } else if (ran.deny === undefined) {
144      ok += 1
145      const { file_path, notebook_path } = e as { file_path?: unknown; notebook_path?: unknown }
146      const path = file_path ?? notebook_path
147      if (EDITING.has(e.tool) && typeof path === 'string') {
148        files.set(normalize(path), { name: baseName(path), path, isOutside: isOutsideOf(cwd, path) })
149      }
150    }
151    liveStatus($, e.tool, ok, countFails(failed))
152
153    return ran
154  })
155
156  on('turn.complete', async ($, e, next) => {
157    // A reload mid-turn drops startedAt and the counts: there is no turn to report.
158    if (!inTurn) return next(e)
159    inTurn = false
160    const seconds = Math.round(((await $.clock.now()) - startedAt) / 1000)
161    const spentNow = await measure($)
162    const spent = Object.fromEntries(
163      Object.entries(spentNow)
164        .map(([kind, n]): [string, number] => [kind, n - (spentAtStart[kind] ?? n)])
165        .filter(([, n]) => n >= 0.05),
166    )
167    const pulse: Pulse = { seconds, ok, files: [...files.values()], failed: { ...failed }, spent }
168    await update($, last, () => pulse)
169    idleStatus($, spentNow)
170
171    const outside = pulse.files.filter(file => file.isOutside)
172    const fails = countFails(failed)
173    if (outside.length > 0) {
174      $.ui.toast(`⚠ Edited outside ${cwd}: ${outside.map(file => file.path).join(', ')}`, { timeoutMs: 15000 })
175    } else if (seconds >= TOAST_SECONDS) {
176      const parts = [`Done in ${formatTime(seconds)}`, `${pulse.files.length} files edited`]
177      if (fails > 0) parts.push(`${fails} failed`)
178      $.ui.toast(parts.join(' · '), { timeoutMs: 10000 })
179    }
180
181    return next(e)
182  })
183
184  // Pushed when a window moves a whole point, also between turns.
185  on('session.measure', async ($, e, next) => {
186    const spent = await measure($, e.rateLimits)
187    if (!inTurn) idleStatus($, spent)
188
189    return next(e)
190  })
191
192  // Cloud sessions draw no band, so there /pulse prints the last turn as
193  // text instead of toggling the band.
194  on('command.run', { command: 'pulse' }, async ($, e, next) => {
195    if (!(await isCloud($))) {
196      const hidden = await read($, isHidden)
197      await update($, isHidden, () => !hidden)
198
199      return { text: hidden ? 'Turn pulse band shown.' : 'Turn pulse band hidden.' }
200    }
201
202    const pulse = await read($, last)
203    // Measured now: the saved windows can trail by up to a point.
204    const spent = await measure($)
205    const lines = [isCurrent(pulse) ? summarize(pulse) : 'No turn has finished yet.']
206    if (Object.keys(spent).length > 0) lines.push(`session: ${formatSpent(spent)}`)
207    return { text: lines.join('\n') }
208  })
209
210  on('session.start', async ($, e, next) => {
211    await $.command.register({
212      name: 'pulse',
213      description: (await isCloud($)) ? 'Print the last turn summary' : 'Show or hide the turn pulse band',
214    })
215    idleStatus($, await measure($))
216
217    return next(e)
218  })
219
220  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
221    const pulse = await read($, last)
222    if (e.props.hasSurvey || !isCurrent(pulse) || (await read($, isHidden))) {
223      return next(e)
224    }
225
226    const { Box, Button, Text } = $.ui.resolve(e)
227    const { outside, inside, shown, more, fails, failures, spent } = describe(pulse)
228
229    return (
230      <Box flexDirection="row" gap={1}>
231        <Text color="claude" bold>◆ last turn</Text>
232        <Text color={pulse.seconds > SLOW_SECONDS ? 'warning' : 'success'}>⏱ {formatTime(pulse.seconds)}</Text>
233        <Text dimColor>│</Text>
234        {outside.length > 0 ? (
235          <Text color="error" bold>⚠ outside: {outside.map(file => file.name).join(', ')}</Text>
236        ) : null}
237        {inside.length > 0 ? <Text color="diffAdded">✎ {shown}{more}</Text> : null}
238        {pulse.files.length === 0 ? <Text dimColor>no edits</Text> : null}
239        <Text dimColor>│</Text>
240        <Text color="success">✓ {pulse.ok} ok</Text>
241        {fails > 0 ? <Text color="error">✗ {fails} failed ({failures})</Text> : null}
242        {Object.keys(spent).length > 0 ? <Text dimColor>│</Text> : null}
243        {Object.keys(spent).length > 0 ? <Text color="suggestion">{formatSpent(spent)}</Text> : null}
244        <Button key="hide" label="Hide" onPress={() => update($, isHidden, () => true)} />
245      </Box>
246    )
247  })
248}
249
types/index.d.ts 29 lines
1export type EditedFile = { name: string; path: string; isOutside: boolean }
2
3export type Pulse = {
4  seconds: number
5  ok: number
6  files: EditedFile[]
7  failed: Record<string, number>
8  // Points of each rate-limit window this turn used, by window kind.
9  spent?: Record<string, number>
10}
11
12// One rate-limit window as this session has watched it.
13export type WindowTrack = {
14  start: number
15  last: number
16  carried: number
17  resetsAt?: string
18}
19
20declare module 'claude-code' {
21  interface PluginState {
22    'turn-pulse': {
23      last: Pulse | null
24      isHidden: boolean
25      windows: Record<string, WindowTrack>
26    }
27  }
28}
29