When the 5-hour usage limit is hit, wait for the reset and send "continue" automatically.

A Claude Code mod. Part of my wider collection, claude-mods.
Hit the 5-hour limit and walk away: this mod waits for the window to reset (plus a margin) and submits "continue" so the session carries on without you.
claude plugin marketplace add icedevil2001/auto-continue
claude plugin install auto-continue@auto-continue --scope user
Needs a Claude Code build with mods (tested on 2.1.286). Footprint: reads the engine's rate-limit usage, sets one timer, submits one prompt; no network, files or processes.
/auto-continue (toggle), /auto-continue on|off|status.| Option | Default | |
|---|---|---|
threshold | 25 | % of the 5-hour window at which the button appears |
graceMinutes | 5 | wait after the reset time before sending |
message | continue | the prompt sent on resume |
ponytail: note in hooks/register.tsx.hooks/register.tsx 139 lines1import { atom, read, update } from 'claude-code'
2import type { Register } from 'claude-code'
3
4const percent = atom({ plugin: 'auto-continue', key: 'percent' } as const, null)
5const isArmed = atom({ plugin: 'auto-continue', key: 'isArmed' } as const, false)
6const resumeAt = atom({ plugin: 'auto-continue', key: 'resumeAt' } as const, null)
7const resetsAt = atom({ plugin: 'auto-continue', key: 'resetsAt' } as const, null)
8
9const clock = (ms: number) =>
10 new Date(ms).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
11
12const BAR = 10
13const bar = (pct: number) => {
14 const filled = Math.min(BAR, Math.max(0, Math.round((pct / 100) * BAR)))
15 return '█'.repeat(filled) + '░'.repeat(BAR - filled)
16}
17
18export const register: Register = (on, options) => {
19 const threshold = Number(options.threshold)
20 const graceMs = Number(options.graceMinutes) * 60_000
21 const message = String(options.message)
22 let timer: { cancel: () => void } | undefined
23
24 const stopTimer = () => {
25 timer?.cancel()
26 timer = undefined
27 }
28
29 on('session.start', async ($, e, next) => {
30 await $.command.register({
31 name: 'auto-continue',
32 description: 'Resume automatically after the 5-hour limit resets',
33 argumentHint: '[on|off|status]',
34 immediate: true,
35 })
36
37 return next(e)
38 })
39
40 on('command.run', { command: 'auto-continue' }, async ($, e) => {
41 const arg = e.args.trim()
42 const was = await read($, isArmed)
43 const now = arg === 'on' ? true : arg === 'off' ? false : arg === '' ? !was : was
44 if (!now) {
45 stopTimer()
46 await update($, resumeAt, () => null)
47 }
48 await update($, isArmed, () => now)
49 const at = await read($, resumeAt)
50 const wait = at ? `, resuming ~${clock(at)}` : ''
51
52 return { text: `Auto-continue ${now ? 'ON' : 'OFF'}${wait}.` }
53 })
54
55 on('session.measure', async ($, e, next) => {
56 const w = e.rateLimits.find(l => l.kind === 'five_hour')
57 await update($, percent, () => w?.percentUsed ?? null)
58 await update($, resetsAt, () => (w?.resetsAt ? Date.parse(w.resetsAt) : null))
59
60 return next(e)
61 })
62
63 on('turn.complete', async ($, e, next) => {
64 const done = await next(e)
65 if (e.reason !== 'error' || e.isAborted || !(await read($, isArmed))) {
66 return done
67 }
68
69 const { rateLimits } = await $.session.usage()
70 const w = rateLimits.find(l => l.kind === 'five_hour')
71 const reset = w?.resetsAt ? Date.parse(w.resetsAt) : NaN
72 const now = await $.clock.now()
73 // ponytail: an API error with the window >= 95% counts as the limit hit;
74 // if the error response leaves the usage stale, parse the reset time from the message instead
75 if (!w || w.percentUsed < 95 || !(reset > now)) {
76 return done
77 }
78
79 stopTimer()
80 const at = reset + graceMs
81 await update($, resumeAt, () => at)
82 $.ui.toast(`Limit reached. Resuming at ${clock(at)}.`)
83 timer = $.clock.after(at - now, () => {
84 timer = undefined
85 void update($, resumeAt, () => null)
86 void $.prompt.submit({ text: message })
87 })
88
89 return done
90 })
91
92 // the person typing takes over from a pending resume
93 on('prompt.submit', async ($, e, next) => {
94 if (timer && e.origin.kind !== 'plugin') {
95 stopTimer()
96 await update($, resumeAt, () => null)
97 }
98
99 return next(e)
100 })
101
102 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
103 const pct = await read($, percent)
104 const armed = await read($, isArmed)
105 const at = await read($, resumeAt)
106 const reset = await read($, resetsAt)
107 const isQuiet = e.props.hasSurvey || (!armed && (pct === null || pct < threshold))
108 if (isQuiet) {
109 return next(e)
110 }
111
112 const { Box, Button, Text } = $.ui.resolve(e)
113 const below = await next(e)
114
115 return (
116 <Box flexDirection="column">
117 <Box>
118 <Button
119 key="toggle"
120 label={`Auto-continue: ${armed ? 'ON' : 'OFF'}`}
121 onPress={async () => {
122 if (armed) {
123 stopTimer()
124 await update($, resumeAt, () => null)
125 }
126 await update($, isArmed, () => !armed)
127 }}
128 />
129 <Text dimColor>
130 {` ${bar(pct ?? 0)}`}
131 {at ? ` resumes ~${clock(at)}` : reset ? ` resets ${clock(reset)}` : ''}
132 </Text>
133 </Box>
134 {below}
135 </Box>
136 )
137 })
138}
139types/index.d.ts 13 lines1export type Timestamp = number | null
2
3declare module 'claude-code' {
4 interface PluginState {
5 'auto-continue': {
6 percent: number | null
7 isArmed: boolean
8 resumeAt: Timestamp
9 resetsAt: Timestamp
10 }
11 }
12}
13