SLOPSHOPPER

session-band

A status line under the prompt counting belt denials this session, shown from the first deny on.

guardstatus
★ 2v0.2.1BSD-3-Clauseupdated 2026-10-21mad01/thismoon/mods/session-band
A shopper browsing a rack in a slop shop
README

session-band

A Claude Code mod that counts belt denials in this session and pins the count in the status row under the prompt, from the first deny on:

session-band: belt denies 2

The engine prefixes a plugin's status line with its name; the text the mod composes starts at belt. Before the first deny the line stays clear, so a quiet session shows nothing. Nothing is drawn above the prompt: the mod registers no ui.render hook, so the engine's band area stays hidden.

Where the count comes from

A tool.call observer. belt runs as a settings PreToolUse hook beneath every mod's tool.call hook, so a belt deny comes back from next(e) as an errored result whose text is belt's reason. A result counts when the first line of that text carries belt[<guard>]: (the engine may put its own hook-error prefix in front). A command that fails and quotes belt in a later line does not count, and neither does a successful call. Every caller counts: the main loop and each subagent.

The mod does not hook classic.PreToolUse: when the built-in guard mod is seated, it forwards every classic.* event past the user tier, and the hook is skipped. The count is per session. It lives in $.state, so it survives a hot reload and a compaction; /clear puts it back to zero and the line goes with it on the next tool call.

pi face

pi/index.ts keeps the same count in the pi coding agent. pi has no hook chain to read a decision from, so the permission gate in the belt pi package (tools/belt/pi) announces each belt denial on the extension bus as belt:deny. The face counts those, keeps the count in the session (pi.appendEntry, restored from the active branch), and pins belt denies N with ctx.ui.setStatus. Silent without a UI.

Dev loop

claude --plugin-dir mods/session-band        # from the repo root; a save hot-reloads
claude --debug --plugin-dir mods/session-band  # every pin lands in the debug log as `$.ui.status (session-band): <text>`
claude plugin validate mods/session-band     # what the engine would refuse
node --test mods/session-band/test/*.test.mjs  # lib and the pi face
claude plugin test mods/session-band         # the count against the engine's test kit
npx -p typescript tsc -p mods/session-band   # after one load wrote .claude-plugin/types/

The engine writes .claude-plugin/types/ beside the mod on load; those files are the authority on event shapes for the build you run. Each counted deny writes session-band: belt deny <n> counted on <tool> to the debug log; a belt deny without that line was not counted.

What it never does

  • never blocks: every hook carries a .catch that logs to the debug log and passes the event on, and the tool.call observer returns the result untouched
  • never edits the transcript or the model's answer
  • never probes a service: the one signal comes from an event the session already raises
  • never required by any skill, hook, or service; belt stays the guard
Source 3 files
hooks/register.tsx 59 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import { composeStatusText, isBeltRefusal } from '../lib/band'
5
6const beltDenies = atom({ plugin: 'session-band', key: 'beltDenies' } as const, 0)
7
8type Logger = { ui: { log: (text: string, options: { to: 'debug' }) => void } }
9type Failed<E, R> = ((e: E) => R) & { event: string; error: { kind: string; message?: string } }
10
11// The one .catch every hook below carries: say why in the debug log, then
12// let the chain beneath answer as if the hook were absent. The line never
13// blocks a turn or a tool call.
14const skipOnFailure = <E, R>($: Logger, e: E, next: Failed<E, R>): R => {
15  const why = next.error.message === undefined ? next.error.kind : `${next.error.kind}: ${next.error.message}`
16  $.ui.log(`session-band: ${next.event} skipped (${why})`, { to: 'debug' })
17  return next(e)
18}
19
20// The text this module instance last pinned; null before its first pin. A
21// hot reload starts over and pins again, and the engine keeps one status
22// line per plugin either way.
23let pinned: string | undefined | null = null
24
25// Recomposes the line and pins it when it changed; undefined clears it.
26async function refreshStatus($: EngineInterface): Promise<void> {
27  const text = composeStatusText(await read($, beltDenies))
28  if (pinned !== null && text === pinned) return
29  pinned = text
30  $.ui.status(text)
31}
32
33export const register: Register = on => {
34  // The count lives in $.state and outlives a reload; the pin does not, so
35  // a count carried across a hot reload is put back on screen here.
36  on('session.start', async ($, e, next) => {
37    const started = await next(e)
38    $.ui.log('session-band: loaded', { to: 'debug' })
39    await refreshStatus($)
40    return started
41  }).catch(skipOnFailure)
42
43  // belt runs as a settings PreToolUse hook beneath every mod's tool.call
44  // hook, so a belt deny comes back from next(e) as an errored result whose
45  // text starts with the `belt[<guard>]: ` reason. Every caller counts: the
46  // main loop and each subagent. Counted, never changed: the result returns
47  // exactly as it came. The line is refreshed on every call, not only on a
48  // deny, so a /clear that zeroed the count takes the stale line down with it.
49  on('tool.call', async ($, e, next) => {
50    const ran = await next(e)
51    if (isBeltRefusal(ran)) {
52      const count = await update($, beltDenies, n => n + 1)
53      $.ui.log(`session-band: belt deny ${count} counted on ${e.tool}`, { to: 'debug' })
54    }
55    await refreshStatus($)
56    return ran
57  }).catch(skipOnFailure)
58}
59
lib/band.ts 33 lines
1// Pure helpers behind the session-band mod: no `$`, no I/O, so `node --test`
2// covers them without the engine. register.tsx and the pi face import them.
3
4// Every belt denial reason carries `belt[<guard>]: `, possibly behind the
5// engine's own prefix on the same line.
6const BELT_REASON = /belt\[[^\]]+\]:/
7
8function isRecord(value: unknown): value is Record<string, unknown> {
9  return typeof value === 'object' && value !== null && !Array.isArray(value)
10}
11
12/**
13 * True when a tool call's result is a belt denial. A denial from a settings
14 * hook reaches a plugin as an errored result whose text is the reason, so
15 * only the first line counts: a failed command whose output mentions belt
16 * does not.
17 */
18export function isBeltRefusal(result: unknown): boolean {
19  if (!isRecord(result)) return false
20  if (typeof result.deny === 'string') return BELT_REASON.test(result.deny)
21  if (result.isError !== true || typeof result.text !== 'string') return false
22  return BELT_REASON.test(result.text.trimStart().split('\n')[0] ?? '')
23}
24
25/**
26 * The one line pinned under the prompt, or undefined (clear it) before the
27 * first deny. The engine prefixes a status line with the mod's name, so the
28 * text never repeats it.
29 */
30export function composeStatusText(beltDenies: number): string | undefined {
31  return beltDenies > 0 ? `belt denies ${beltDenies}` : undefined
32}
33
types/index.d.ts 11 lines
1/** How many belt denials this session has seen; zero keeps the line clear. */
2export type SessionBandDenies = number
3
4declare module 'claude-code' {
5  interface PluginState {
6    'session-band': {
7      beltDenies: SessionBandDenies
8    }
9  }
10}
11