SLOPSHOPPER

kevin-idle

Wakes an idle Kevin with `kevin idle check` after kevin.idle_seconds (two hours by default) without a turn, in place of a CronCreate idle check, and draws the…

bandprompttimer
v0.2.1no licenseupdated 2026-10-1721StarkCom/bifrost/mods/kevin-idle
A shopper browsing a rack in a slop shop
README

kevin-idle

A Claude Code mod that wakes an idle Kevin (/kevin, a repo's request desk) so he can idle out without arming a timer of his own. In a session whose project root is a KEVIN-<repo>-<n> worktree, it notes when each main-loop turn starts and ends, and once he has gone kevin.idle_seconds without a turn it submits one prompt, kevin idle check and then its note (below). Kevin runs his own check (skill/kevin/SKILL.md, "Idle out") and decides; the wake's own turn restarts the clock, so an idle Kevin is woken once per idle period, never more. Every other session is left alone.

Install it on its own; the seven skill plugins do not need it:

/plugin install kevin-idle@bifrost

Threshold

kevin.idle_seconds in the stark config, 7200 (two hours) by default, read at session start from config.json (then global/config.json) under STARK_ASSET_ROOT, else from ~/.claude/code-review/config.json, the link tools/asset_links.ts makes into the bifrost checkout. A missing file or a value that is not a whole number of seconds reads as 7200. A change reaches the next Kevin launched.

The idle band

Between turns, a Kevin session shows the idle clock above the prompt, in the operator's status-line gauge style:

IDLE ▐████░░░░░░▌ 48m / 2h · wakes 16:12

The 10 cells fade from light red to dark red and round down, so the bar never reads full ahead of the wake (the wake's tick restarts it); wakes is local time. The band is hidden while a turn runs (the wake's own included) and while a survey shows, and restarts at <1m when the turn ends. It refreshes on the mod's one-minute tick and shows whole minutes, so a threshold is best set in whole minutes. Other sessions get no band.

How Kevin knows it is armed

Every prompt that enters a Kevin session carries one note, in Kevin sessions only. His kickoff and each request carry it as context, which the model reads beside the prompt and the operator never sees. The mod's own wake skips its own hook, so the wake carries the note in its text, after kevin idle check. A compaction can drop the note, and the next prompt, wake or request, brings it back.

kevin-idle: the kevin-idle mod is armed in this session, at kevin.idle_seconds 7200. It sends you `kevin idle check` once you have gone 7200 seconds without a turn, so start no idle waker of your own.

The note does not go in the system prompt. Where an organization manages Claude Code, the managed settings' plugins pass over an installed plugin's prompt.compose, prompt.context and session.compact hooks, and claude plugin validate says so. A prompt.submit hook's context reaches the model there.

With no such note (a Codex Kevin, or a Claude without this mod) Kevin starts tools/kevin_idle.ts --detach at launch instead, which wakes him by hermod at the same threshold.

Checking it

claude plugin validate mods/kevin-idle
claude plugin test mods/kevin-idle
Source 2 files
hooks/register.tsx 195 lines
1import { atom, read, update } from 'claude-code'
2import type { Register, StateDollar } from 'claude-code'
3
4import type { Idle } from '../types'
5
6// The wake skill/kevin's "Idle out" answers; the waker tools/kevin_idle.ts sends the same text.
7export const WAKE_TEXT = 'kevin idle check'
8// tools/stark_config_lib.ts's DEFAULT_KEVIN, which this module cannot import.
9const DEFAULT_IDLE_SECONDS = 7200
10const POLL_MS = 60 * 1000
11const KEVIN_NAME = /^KEVIN-[A-Za-z0-9_-]+-\d+$/
12
13// The band's bar is the operator's status-line gauge (idavoll's statusline
14// bar): a rail, CELLS cells fading light to dark red, the rest dim.
15export const CELLS = 10
16const LIGHT = [248, 168, 168]
17const DARK = [139, 0, 0]
18const RAIL = '#d0d0d0'
19const EMPTY = '#8a8a8a'
20
21const idle = atom({ plugin: 'kevin-idle', key: 'idle' } as const, null)
22
23/** What tells Kevin the mod is armed and at what threshold, so he starts no waker of his own. */
24export function armed(idleSeconds: number): string {
25  return (
26    `kevin-idle: the kevin-idle mod is armed in this session, at kevin.idle_seconds ${idleSeconds}. ` +
27    `It sends you \`${WAKE_TEXT}\` once you have gone ${idleSeconds} seconds without a turn, so start no ` +
28    'idle waker of your own.'
29  )
30}
31
32/** A Claude Kevin stands in a worktree named for his launch id, `KEVIN-<repo>-<n>`. */
33export function isKevinRoot(root: string): boolean {
34  return KEVIN_NAME.test(root.replace(/[\\/]+$/, '').split(/[\\/]/).pop() ?? '')
35}
36
37/** The stark config's paths, as tools/asset_root_lib.ts's assetConfigPath probes them, flat first. */
38export function configPaths(assetRoot: string | undefined, home: string | undefined): string[] {
39  if (assetRoot) return [`${assetRoot}/config.json`, `${assetRoot}/global/config.json`]
40
41  return home ? [`${home}/.claude/code-review/config.json`] : []
42}
43
44/** `kevin.idle_seconds` from the config's text when it is a whole number of seconds, at least 1; else the default. */
45export function idleSeconds(text: string | undefined): number {
46  try {
47    const value: unknown = JSON.parse(text ?? '').kevin?.idle_seconds
48
49    return Number.isInteger(value) && (value as number) >= 1 ? (value as number) : DEFAULT_IDLE_SECONDS
50  } catch {
51    return DEFAULT_IDLE_SECONDS
52  }
53}
54
55/** Filled cells, rounded down: the bar is full only once the wake is due. */
56export function filled(state: Idle): number {
57  const share = (state.now - state.since) / (state.seconds * 1000)
58
59  return Math.min(CELLS, Math.max(0, Math.floor(share * CELLS)))
60}
61
62/** Cell `i`'s colour, `#rrggbb`, from LIGHT at the first cell to DARK at the last. */
63export function shade(i: number): string {
64  const hex = (a: number, b: number) =>
65    Math.round(a + ((b - a) * i) / (CELLS - 1))
66      .toString(16)
67      .padStart(2, '0')
68
69  return `#${LIGHT.map((a, k) => hex(a, DARK[k]!)).join('')}`
70}
71
72/** Whole minutes, at the status line's minute grain: `<1m`, `48m`, `1h05m`, `2h`. */
73export function duration(ms: number): string {
74  const minutes = Math.floor(ms / 60_000)
75  if (minutes < 1) return '<1m'
76  if (minutes < 60) return `${minutes}m`
77  const rest = minutes % 60
78
79  return `${Math.floor(minutes / 60)}h${rest === 0 ? '' : `${String(rest).padStart(2, '0')}m`}`
80}
81
82/** Local `HH:MM` of an epoch time. */
83export function clockTime(ms: number): string {
84  const at = new Date(ms)
85
86  return `${String(at.getHours()).padStart(2, '0')}:${String(at.getMinutes()).padStart(2, '0')}`
87}
88
89/**
90 * Publishes the band's state; a write redraws the band. `value` is worked out
91 * as the write lands, and again on update's retry, so a retry never puts back
92 * a state a turn hook has since replaced. A failed write costs the band alone,
93 * never the wake.
94 */
95async function publish($: StateDollar, value: () => Idle | null): Promise<void> {
96  await update($, idle, value).catch(() => undefined)
97}
98
99export const register: Register = on => {
100  let isKevin = false
101  let seconds = DEFAULT_IDLE_SECONDS
102  let note: string | null = null
103  let isBusy = false
104  // When the last wake went out: a wake that never became a turn (another hook
105  // refused it) goes again a period later, not never.
106  let wakeMs = 0
107  let lastMs = 0
108
109  // What the band draws as of `now`, read from the turn state when the write
110  // lands: nothing while a turn runs.
111  const idleAt = (now: number) => (): Idle | null =>
112    isBusy ? null : { since: Math.max(lastMs, wakeMs), seconds, now }
113
114  on('session.start', async ($, e, next) => {
115    if (!isKevinRoot(await $.session.root())) return next(e)
116    isKevin = true
117    const [assetRoot, home] = await Promise.all([$.env.get('STARK_ASSET_ROOT'), $.env.get('HOME')])
118    let text: string | undefined
119    for (const path of configPaths(assetRoot, home)) {
120      text = await $.fs.read(path).catch(() => undefined)
121      if (typeof text === 'string') break
122    }
123    seconds = idleSeconds(text)
124    const armedNote = armed(seconds)
125    note = armedNote
126    lastMs = await $.clock.now()
127
128    $.clock.every(POLL_MS, async () => {
129      const now = await $.clock.now()
130      // A running turn's band is already hidden; turn.complete shows it again.
131      if (isBusy) return
132      if (now - Math.max(lastMs, wakeMs) < seconds * 1000) return publish($, idleAt(now))
133      // Once per idle period: the wake's own turn restarts the clock.
134      wakeMs = now
135      await publish($, idleAt(now))
136      // The wake skips this module's own prompt.submit hook, so it carries the
137      // note in its text: a wake right after a compaction still names it.
138      await $.prompt.submit({ text: `${WAKE_TEXT}\n\n${armedNote}` })
139    })
140    await publish($, idleAt(lastMs))
141
142    return next(e)
143  })
144
145  on('turn.start', async ($, e, next) => {
146    isBusy = true
147    lastMs = await $.clock.now()
148    if (isKevin) await publish($, idleAt(lastMs))
149
150    return next(e)
151  })
152
153  on('turn.complete', async ($, e, next) => {
154    // A subagent's turn ends inside the main one; only the main loop's end is idle.
155    if (e.agentId === undefined) {
156      isBusy = false
157      lastMs = await $.clock.now()
158      if (isKevin) await publish($, idleAt(lastMs))
159    }
160
161    return next(e)
162  })
163
164  // Not the system prompt: where an organization manages Claude Code, an
165  // installed plugin's prompt.compose (and session.compact) is passed over, so
166  // the note rides every other prompt that enters (his kickoff, each request)
167  // as context instead.
168  on('prompt.submit', async ($, e, next) =>
169    note === null ? next(e) : next({ ...e, context: [...(e.context ?? []), note] }),
170  )
171
172  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
173    const state = await read($, idle)
174    // The engine's isWorking too: a reload mid-turn restarts this module idle.
175    if (e.props.hasSurvey || e.props.isWorking || state === null) return next(e)
176
177    const { Text } = $.ui.resolve(e)
178    const n = filled(state)
179
180    return (
181      <Text key="kevin-idle">
182        <Text color={shade(0)}>IDLE</Text> <Text color={RAIL}>▐</Text>
183        {Array.from({ length: n }, (_, i) => (
184          <Text key={`cell-${i}`} color={shade(i)}>
185            █
186          </Text>
187        ))}
188        <Text color={EMPTY}>{'░'.repeat(CELLS - n)}</Text>
189        <Text color={RAIL}>▌</Text> {duration(state.now - state.since)} / {duration(state.seconds * 1000)}{' '}
190        <Text dimColor>· wakes {clockTime(state.since + state.seconds * 1000)}</Text>
191      </Text>
192    )
193  })
194}
195
types/index.d.ts 9 lines
1/** The idle clock the band draws: idle since `since`, as of `now`, both epoch ms; the wake is due `seconds` after `since`. */
2export type Idle = { since: number; seconds: number; now: number }
3
4declare module 'claude-code' {
5  interface PluginState {
6    'kevin-idle': { idle: Idle | null }
7  }
8}
9