SLOPSHOPPER

auto-handoff

Hands the work to a fresh, named session when the context gets too full, using your /handoff command

bandtoastprompttimer
★ 1v0.2.6MITupdated 2026-10-18Spardutti/claude-mods/plugins/auto-handoff
A shopper browsing a rack in a slop shop
README

claude-mods

Little mods for Claude Code: panels that keep the stuff you'd normally go check next to the chat, and helpers that do the chores for you.

Claude Code 2.1.287+ mods: 5 License: MIT

Why

You spend all day in Claude Code. But the small stuff keeps pulling you out of it: checking git, rescuing a session that got too long, doing the same cleanup by hand.

These mods put that stuff inside Claude Code. Some draw a live panel next to the chat. Some do a chore for you at the right moment. You keep your eyes on the work.

Each one installs on its own, so you take only what you want.

Get started

Add the marketplace once, then install a mod:

/plugin marketplace add spardutti/claude-mods
/plugin install branch-status@spardutti-mods
/plugin install auto-handoff@spardutti-mods
/plugin install handoff-pickup@spardutti-mods
/plugin install blocked-run@spardutti-mods
/plugin install dev-apps@spardutti-mods

Install any you like. Each one starts working on the next session start.

The mods

Each mod has its own page with the full story.

ModWhat it does
branch-statusA panel with your branch, develop and main as a tiny git-flow graph, so you see what's waiting to ship without running git log.
auto-handoffWhen the context gets too full, it warns you, counts down, then hands the work to a fresh session.
handoff-pickup/pickup picks up your newest handoff, /pickup done deletes it.
blocked-runWhen auto mode blocks a command, it shows above the prompt with a button to run it yourself.
dev-appsUnder the Git panel: this project's apps, a link to open each, and Start and Stop. Stops them when you close Claude.
/plugin marketplace update spardutti-mods
/plugin update branch-status@spardutti-mods
/plugin update auto-handoff@spardutti-mods
/plugin update handoff-pickup@spardutti-mods
/plugin update blocked-run@spardutti-mods
/plugin update dev-apps@spardutti-mods
/reload-plugins
Source 3 files
hooks/register.tsx 178 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register, RenderInputOf, RenderSurface, Timer } from 'claude-code'
3
4import type { Notice } from '../types'
5import { handoffPath, resumePrompt, sessionName } from './handoff'
6
7type Phase = 'idle' | 'writing' | 'waiting' | 'busy'
8type BandInput = { [S in RenderSurface]: RenderInputOf<'AbovePrompt', S> }[RenderSurface]
9
10const WARN_POINTS = 5
11const COUNTDOWN_SECONDS = 10
12const LOOP_MARGIN = 10
13// Shells, monitors and artifact watches can run for good (a dev server), so only these hold a handoff.
14const WAITED_FOR = ['subagent', 'workflow']
15const notice = atom({ plugin: 'auto-handoff', key: 'notice' } as const, null as Notice | null)
16
17// Module state, not $.state: it must survive /clear, which keeps this module loaded.
18let phase: Phase = 'idle'
19let countdown: Timer | undefined
20let startedAt = 0
21let waitingPath = ''
22let floor = 0
23let floorPending = false
24let hasBackgroundWork = false
25let running: string[] = []
26let retried = false
27let failed: string | undefined
28
29const show = ($: EngineInterface, next: Notice | null) => update($, notice, () => next)
30
31function stopCountdown($: EngineInterface) {
32  if (!countdown) return
33  countdown.cancel()
34  countdown = undefined
35  void show($, null)
36}
37
38async function findHandoffCommand($: EngineInterface) {
39  const commands = await $.command.list()
40  return commands.find(c => c.name === 'handoff' || c.name.endsWith(':handoff'))?.name
41}
42
43async function fail($: EngineInterface, reason: string) {
44  phase = 'idle'
45  failed = reason
46  await show($, { failed: reason })
47}
48
49async function start($: EngineInterface, percent: number) {
50  const command = await findHandoffCommand($)
51  if (!command) return fail($, 'no /handoff command found')
52  $.ui.toast(`Context at ${percent}%. Handing off to a fresh session.`)
53  phase = 'writing'
54  retried = false
55  startedAt = await $.clock.now()
56  await $.command.run({ command })
57}
58
59async function countDown($: EngineInterface, percent: number, threshold: number) {
60  if (countdown) return
61  let secondsLeft = COUNTDOWN_SECONDS
62  await show($, { percent, threshold, secondsLeft })
63  countdown = $.clock.every(1000, () => {
64    secondsLeft -= 1
65    if (secondsLeft > 0) return void show($, { percent, threshold, secondsLeft })
66    stopCountdown($)
67    void start($, percent)
68  })
69}
70
71async function writtenHandoff($: EngineInterface, answer: string) {
72  const path = handoffPath(answer)
73  if (!path) return undefined
74  const stat = await $.fs.stat(path).catch(() => undefined)
75  return stat && stat.mtimeMs >= startedAt ? path : undefined
76}
77
78async function resumeFresh($: EngineInterface, path: string, lastReply: string) {
79  phase = 'busy'
80  try {
81    const name = sessionName(path, await $.fs.read(path))
82    await $.command.run({ command: 'clear' })
83    await $.command.run({ command: 'rename', args: name })
84    floorPending = true
85    await $.prompt.submit({ text: resumePrompt(path, lastReply, running), asUser: true })
86  } catch {
87    await fail($, 'the fresh session could not start')
88  } finally {
89    phase = 'idle'
90  }
91}
92
93async function askToFoldIn($: EngineInterface) {
94  phase = 'writing'
95  const text = `The background work finished. Add its results to ${waitingPath}, then reply with that path.`
96  await $.prompt.submit({ text, asUser: true })
97}
98
99async function askAgain($: EngineInterface) {
100  retried = true
101  const text = 'No new handoff note turned up. Write it under .claude/handoffs/ now, then reply with its path.'
102  await $.prompt.submit({ text, asUser: true })
103}
104
105async function finishHandoff($: EngineInterface, answer: string, hasBackgroundWork: boolean) {
106  if (phase === 'waiting') return hasBackgroundWork ? undefined : askToFoldIn($)
107  const path = await writtenHandoff($, answer)
108  if (!path) return retried ? fail($, 'no handoff note was written') : askAgain($)
109  if (!hasBackgroundWork) return resumeFresh($, path, answer)
110  phase = 'waiting'
111  waitingPath = path
112}
113
114async function drawNotice($: EngineInterface, e: BandInput) {
115  const shown = await read($, notice)
116  if (e.props.hasSurvey || !shown) return undefined
117  const { Box, Button, Text } = $.ui.resolve(e)
118  if ('failed' in shown) {
119    return <Text color="red">Handoff failed: {shown.failed}. Nothing was cleared. Run /handoff yourself.</Text>
120  }
121  if (shown.secondsLeft === undefined) {
122    return <Text color="yellow">Context at {shown.percent}%. Handoff starts at {shown.threshold}%.</Text>
123  }
124  return (
125    <Box>
126      <Text color="yellow">Context at {shown.percent}%. Handing off in {shown.secondsLeft}s. </Text>
127      <Button key="not-now" label="Not now" onPress={() => stopCountdown($)} />
128    </Box>
129  )
130}
131
132async function checkUsage($: EngineInterface, threshold: number) {
133  const percent = (await $.session.usage()).context.percent ?? 0
134  if (floorPending) floor = percent + LOOP_MARGIN
135  else if (percent < floor - LOOP_MARGIN) floor = 0
136  floorPending = false
137  const at = Math.max(threshold, floor)
138  if (percent < at) failed = undefined
139  if (failed) return show($, { failed })
140  if (percent >= at) return countDown($, percent, at)
141  await show($, percent >= at - WARN_POINTS ? { percent, threshold: at } : null)
142}
143
144export const register: Register = (on, options) => {
145  const threshold = Number(options.threshold)
146
147  on('turn.complete', async ($, e, next) => {
148    const done = await next(e)
149    if (e.agentId || phase === 'busy') return done
150
151    if (phase !== 'idle') {
152      if (e.reason === 'answer') void finishHandoff($, e.answer, hasBackgroundWork)
153      else phase = 'idle'
154      hasBackgroundWork = false
155      return done
156    }
157
158    if (e.reason === 'answer') await checkUsage($, threshold)
159    return done
160  })
161
162  // Only Stop lists running background tasks, and it ends before turn.complete, which acts on them.
163  on('classic.Stop', async ($, e, next) => {
164    const tasks = e.background_tasks ?? []
165    hasBackgroundWork = tasks.some(task => WAITED_FOR.includes(task.type))
166    running = tasks.filter(task => task.status === 'running' && !WAITED_FOR.includes(task.type)).map(task => task.description)
167    return next(e)
168  })
169
170  // A message sent during the countdown wins; the countdown starts again when that reply ends.
171  on('prompt.submit', async ($, e, next) => {
172    stopCountdown($)
173    return next(e)
174  })
175
176  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => (await drawNotice($, e)) ?? next(e))
177}
178
hooks/handoff.ts 26 lines
1// Only a file the handoff skill writes is accepted: .claude/handoffs/<name>.md, no slashes or dots up.
2// Matched anywhere in the answer, since output styles reword the skill's "Handoff written:" line.
3export function handoffPath(answer: string): string | undefined {
4  return answer.match(/\.claude\/handoffs\/[\w-][\w.-]*\.md\b/)?.[0]
5}
6
7export function resumePrompt(path: string, lastReply: string, running: string[]): string {
8  const parts = [`Read ${path} and continue.`]
9  const said = lastReply.trim()
10  if (said) {
11    parts.push(`The reset hid your last reply, below. Repeat to the user anything in it beyond the handoff path.\n\n${said}`)
12  }
13  if (running.length) {
14    const list = running.map(task => `- ${task}`).join('\n')
15    parts.push(`These background tasks started before the reset. When one reports back, that is not the user's answer:\n${list}`)
16  }
17  return parts.join('\n\n')
18}
19
20export function sessionName(path: string, doc: string): string {
21  const subject = doc.match(/^#\s*Handoff\s*[—–-]\s*(.+)$/m)?.[1]?.trim()
22  if (subject) return subject
23  const file = path.split('/').pop() ?? path
24  return file.replace(/\.md$/, '').replace(/^\d{4}-\d{2}-\d{2}-/, '')
25}
26
types/index.d.ts 8 lines
1export type Notice = { percent: number; threshold: number; secondsLeft?: number } | { failed: string }
2
3declare module 'claude-code' {
4  interface PluginState {
5    'auto-handoff': { notice: Notice | null }
6  }
7}
8