Shows the running plan's current step, elapsed times and estimates as a timeline above the prompt

A Claude Code mod that shows the plan Claude is executing as a live timeline above the prompt:
Plan · Checkup 3 · step 3/5: Fix tier A
━━━━━━━━│━━━━━━━━━━━━━│━━━━━━━──────│─────────────────│──────
elapsed 1h12m · step 8m of ~15m · ~45m left · ETA 14:32
At the prompt of a Claude Code terminal session:
/plugin install plan-progress --marketplace liveweird/claude-mods
Answer y to add the marketplace (once), then pick the user scope. It is active at once, and in every later session.
Claude reports progress through the plan_progress tool the mod registers (start with steps and minute estimates, step on each move, revise, finish, clear). To make it do so by default, add to ~/.claude/CLAUDE.md:
When executing a multi-step plan and the
plan_progresstool (the plan-progress mod) is available, report it:startwith every step and an estimate in minutes,stepeach time you move on,revisewhen steps or estimates change,finishat the end. Skip it for one-step tasks.
/plan-progress opens a pane with the timeline and one row per step./plan-progress clear drops the plan.Each step is { title, estimateMin }. A start or revise whose step lacks a numeric estimateMin (or a title) is refused with an error naming the step and the keys it got, so a misspelt key never shows as a 0-minute estimate.
A finished plan stays on the band for ten minutes, then leaves it.
claude plugin validate . and claude plugin test .; after an edit, /reload-plugins in a session that installed it from this folder.
hooks/register.tsx 264 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Plan } from '../types'
5import {
6 clockTime,
7 describe,
8 fmt,
9 goTo,
10 revise,
11 type Segment,
12 startPlan,
13 stepDurationMs,
14 stepsProblem,
15 type StepInput,
16 summarize,
17 timeline,
18} from './plan'
19
20const PANE = 'plan-progress'
21const TOOL = 'mcp__plan-progress__plan_progress'
22const TICK_MS = 10_000
23/** A finished plan stays on the band this long, then leaves it. */
24const LINGER_MS = 10 * 60_000
25
26const plan = atom({ plugin: 'plan-progress', key: 'plan' } as const, null)
27
28const COLOR: Record<Segment['kind'], string> = {
29 done: 'success',
30 now: 'suggestion',
31 over: 'warning',
32 left: 'suggestion',
33 todo: 'inactive',
34 gap: 'subtle',
35}
36
37/** Done is green, the running step blue (solid for time spent, thin for its rest), later steps grey. */
38const DIM: ReadonlySet<Segment['kind']> = new Set(['todo', 'gap'])
39
40const STEPS_SCHEMA = {
41 type: 'array',
42 items: {
43 type: 'object',
44 properties: {
45 title: { type: 'string', description: 'Short step name (a few words).' },
46 estimateMin: { type: 'number', description: 'Estimated duration in minutes.' },
47 },
48 required: ['title', 'estimateMin'],
49 },
50}
51
52export const register: Register = on => {
53 on('session.start', async ($, e, next) => {
54 await $.tool.register({
55 name: 'plan_progress',
56 description: [
57 'Reports progress through the plan being executed, shown to the user as a timeline above the prompt.',
58 'Call action "start" when you begin executing a multi-step plan (title + steps, each with an estimate in minutes).',
59 'Call action "step" with the 1-based step number each time you move on to a step.',
60 'Call action "revise" when steps or estimates change (steps replace the list from step `from`, default the running one).',
61 'Call action "finish" when the plan is done, "clear" to drop it, "show" to read it back.',
62 ].join(' '),
63 inputSchema: {
64 type: 'object',
65 properties: {
66 action: { type: 'string', enum: ['start', 'step', 'revise', 'finish', 'clear', 'show'] },
67 title: { type: 'string', description: 'start: the plan name.' },
68 steps: { ...STEPS_SCHEMA, description: 'start/revise: the steps in order.' },
69 step: { type: 'number', description: 'step: the 1-based step now starting.' },
70 from: { type: 'number', description: 'revise: the 1-based step the new list starts at.' },
71 },
72 required: ['action'],
73 },
74 })
75 await $.command.register({
76 name: 'plan-progress',
77 description: 'Show the running plan as a timeline (args: clear)',
78 argumentHint: '[clear]',
79 })
80 $.clock.every(TICK_MS, async () => {
81 const p = await read($, plan)
82 if (p !== null && p.finishedAt === undefined) $.ui.invalidate('ui.render')
83 })
84
85 return next(e)
86 })
87
88 on('tool.call', { tool: TOOL }, async ($, e) => {
89 const now = await $.clock.now()
90 const current = await read($, plan)
91 const steps = Array.isArray(e.steps) ? (e.steps as StepInput[]) : undefined
92 const stepsError = steps ? stepsProblem(steps) : undefined
93 const num = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) ? Math.round(v) : undefined)
94 let nextPlan: Plan | null = current
95
96 switch (e.action) {
97 case 'start':
98 if (!steps?.length) return { result: 'start needs a non-empty steps list.', isError: true }
99 if (stepsError) return { result: stepsError, isError: true }
100 nextPlan = startPlan(typeof e.title === 'string' && e.title.trim() ? e.title.trim() : 'Plan', steps, now)
101 break
102 case 'step': {
103 const n = num(e.step)
104 if (current === null) return { result: 'No plan is running; call start first.', isError: true }
105 if (n === undefined || n < 1 || n > current.steps.length) {
106 return { result: `step must be 1..${current.steps.length}.`, isError: true }
107 }
108 nextPlan = goTo(current, n - 1, now)
109 break
110 }
111 case 'revise': {
112 if (current === null) return { result: 'No plan is running; call start first.', isError: true }
113 if (!steps) return { result: 'revise needs steps.', isError: true }
114 if (stepsError) return { result: stepsError, isError: true }
115 const from = num(e.from)
116 nextPlan = revise(current, steps, from === undefined ? undefined : from - 1, now)
117 if (typeof e.title === 'string' && e.title.trim()) nextPlan = { ...nextPlan, title: e.title.trim() }
118 break
119 }
120 case 'finish':
121 if (current === null) return { result: 'No plan is running.', isError: true }
122 nextPlan = goTo(current, current.steps.length, now)
123 break
124 case 'clear':
125 nextPlan = null
126 break
127 case 'show':
128 break
129 default:
130 return { result: 'action must be one of start, step, revise, finish, clear, show.', isError: true }
131 }
132
133 if (nextPlan !== current) await update($, plan, () => nextPlan)
134 return { result: nextPlan === null ? 'No plan.' : describe(nextPlan, now) }
135 })
136
137 on('command.run', { command: 'plan-progress' }, async ($, e) => {
138 if (e.args.trim() === 'clear') {
139 await update($, plan, () => null)
140 return { text: 'Plan progress cleared.' }
141 }
142 await $.ui.open({ id: PANE, title: 'Plan progress' })
143 return { text: 'Plan progress pane opened.' }
144 })
145
146 // Stacks on top of whatever band is drawn beneath (e.g. the backlog row) rather than replacing it.
147 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
148 const below = await next(e)
149 const p = await read($, plan)
150 if (e.props.hasSurvey || p === null) return below
151 const now = await $.clock.now()
152 if (p.finishedAt !== undefined && now - p.finishedAt > LINGER_MS) return below
153
154 const { Box, Text } = $.ui.resolve(e)
155 const width = Math.max(10, e.props.bodyColumns)
156 const sum = summarize(p, now)
157 const step = p.steps[p.current]
158
159 return (
160 <Box flexDirection="column">
161 <Text wrap="truncate-end">
162 <Text dimColor>Plan · {p.title} · </Text>
163 {sum.isFinished ? (
164 <Text color="success" bold>
165 ✓ done, {p.steps.length} steps
166 </Text>
167 ) : (
168 <Text bold color={sum.isOver ? 'warning' : 'suggestion'}>
169 step {p.current + 1}/{p.steps.length}: {step?.title}
170 </Text>
171 )}
172 </Text>
173 {bar($, e, p, now, width)}
174 <Text wrap="truncate-end" dimColor>
175 {statusLine(p, now)}
176 </Text>
177 {below.type === 'engine' ? null : below}
178 </Box>
179 )
180 })
181
182 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
183 const { Box, Text } = $.ui.resolve(e)
184 const p = await read($, plan)
185 if (p === null) {
186 return (
187 <Text dimColor>
188 No plan is running. Claude reports one with its plan_progress tool when it starts executing a plan.
189 </Text>
190 )
191 }
192 const now = await $.clock.now()
193 const width = Math.max(10, e.props.bodyColumns)
194 const sum = summarize(p, now)
195 let cursor = now + Math.max(0, sum.stepEstimateMs - sum.stepElapsedMs)
196
197 return (
198 <Box flexDirection="column">
199 <Text bold wrap="truncate-end">
200 {p.title}
201 </Text>
202 <Text dimColor wrap="truncate-end">
203 {statusLine(p, now)}
204 </Text>
205 {bar($, e, p, now, width)}
206 <Text> </Text>
207 {p.steps.map((s, i) => {
208 const isDone = sum.isFinished || i < p.current
209 const isNow = !sum.isFinished && i === p.current
210 const took = stepDurationMs(p, i, now)
211 let right: string
212 let color: string | undefined
213 if (isDone) {
214 right = `${fmt(took ?? 0)} / est ${s.estimateMin}m`
215 color = 'success'
216 } else if (isNow) {
217 right = `${fmt(took ?? 0)} / est ${s.estimateMin}m`
218 color = sum.isOver ? 'warning' : 'suggestion'
219 } else {
220 right = `est ${s.estimateMin}m · ≈${clockTime(cursor)}`
221 cursor += s.estimateMin * 60_000
222 }
223 return (
224 <Box flexDirection="row" key={`step-${i}`}>
225 <Box flexGrow={1} flexShrink={1}>
226 <Text wrap="truncate-end" color={color} bold={isNow} dimColor={!isDone && !isNow}>
227 {isDone ? '✓' : isNow ? '▶' : '·'} {i + 1}. {s.title}
228 </Text>
229 </Box>
230 <Text color={isNow ? color : undefined} dimColor={!isNow}> {right}</Text>
231 </Box>
232 )
233 })}
234 </Box>
235 )
236 })
237}
238
239function statusLine(p: Plan, now: number): string {
240 const sum = summarize(p, now)
241 if (sum.isFinished) {
242 const est = p.steps.reduce((t, s) => t + s.estimateMin, 0)
243 return `took ${fmt(sum.elapsedMs)} (estimated ${fmt(est * 60_000)}) · finished ${clockTime(p.finishedAt ?? now)}`
244 }
245 const stepPart = sum.isOver
246 ? `step ${fmt(sum.stepElapsedMs)}, ${fmt(sum.stepElapsedMs - sum.stepEstimateMs)} over its ${fmt(sum.stepEstimateMs)}`
247 : `step ${fmt(sum.stepElapsedMs)} of ~${fmt(sum.stepEstimateMs)}`
248 return `elapsed ${fmt(sum.elapsedMs)} · ${stepPart} · ~${fmt(sum.remainingMs)} left · ETA ${clockTime(now + sum.remainingMs)}`
249}
250
251function bar($: EngineInterface, e: Parameters<EngineInterface['ui']['resolve']>[0], p: Plan, now: number, width: number) {
252 const { Box, Text } = $.ui.resolve(e)
253 const segments = timeline(p, now, width)
254 return (
255 <Box flexDirection="row">
256 {segments.map(s => (
257 <Text color={COLOR[s.kind]} bold={s.kind === 'now'} dimColor={DIM.has(s.kind)}>
258 {s.text}
259 </Text>
260 ))}
261 </Box>
262 )
263}
264hooks/plan.ts 190 lines1import type { Plan, PlanStep } from '../types'
2
3export type StepInput = { title: string; estimateMin: number }
4
5const MINUTE = 60_000
6
7/**
8 * Why the steps list is not `{ title, estimateMin }[]`, or undefined when it is. The engine does not enforce the
9 * schema's `required`, and a misspelt key (`estimate_minutes`) used to land as a silent 0-minute estimate.
10 */
11export function stepsProblem(steps: unknown[]): string | undefined {
12 const problems = steps.flatMap((s, i) => {
13 if (typeof s !== 'object' || s === null || Array.isArray(s)) return [`step ${i + 1} is not an object`]
14 const step = s as Record<string, unknown>
15 const out: string[] = []
16 if (typeof step.title !== 'string' || !step.title.trim()) out.push(`step ${i + 1} needs a non-empty "title"`)
17 if (typeof step.estimateMin !== 'number' || !Number.isFinite(step.estimateMin) || step.estimateMin < 0) {
18 const others = Object.keys(step).filter(k => k !== 'title')
19 const got = 'estimateMin' in step ? `got ${JSON.stringify(step.estimateMin)}` : `got keys: ${others.join(', ') || 'none'}`
20 out.push(`step ${i + 1} needs "estimateMin", a number of minutes >= 0 (${got})`)
21 }
22 return out
23 })
24 return problems.length ? `Invalid steps: ${problems.join('; ')}.` : undefined
25}
26
27export function startPlan(title: string, steps: StepInput[], now: number): Plan {
28 return {
29 title,
30 startedAt: now,
31 current: 0,
32 steps: steps.map((s, i) => ({ ...clean(s), ...(i === 0 ? { startedAt: now } : {}) })),
33 }
34}
35
36/** Ends the running step and starts `index` (0-based); steps jumped over count as skipped. */
37export function goTo(plan: Plan, index: number, now: number): Plan {
38 const target = Math.max(0, Math.min(index, plan.steps.length))
39 const steps = plan.steps.map((s, i): PlanStep => {
40 if (i < target) {
41 return s.endedAt !== undefined ? s : { ...s, startedAt: s.startedAt ?? now, endedAt: now }
42 }
43 if (i === target) {
44 return { title: s.title, estimateMin: s.estimateMin, startedAt: s.startedAt !== undefined && s.endedAt === undefined ? s.startedAt : now }
45 }
46 return { title: s.title, estimateMin: s.estimateMin }
47 })
48 const isDone = target >= steps.length
49 return { ...plan, steps, current: target, ...(isDone ? { finishedAt: now } : { finishedAt: undefined }) }
50}
51
52/** Replaces the steps from `from` (default: the running one) on, keeping what already ran. */
53export function revise(plan: Plan, steps: StepInput[], from: number | undefined, now: number): Plan {
54 const at = Math.max(0, Math.min(from ?? plan.current, plan.steps.length))
55 const kept = plan.steps.slice(0, at)
56 const fresh = steps.map((s, i): PlanStep => {
57 const old = plan.steps[at + i]
58 const isRunning = at + i === plan.current
59 return { ...clean(s), ...(isRunning ? { startedAt: old?.startedAt ?? now } : {}) }
60 })
61 const merged = [...kept, ...fresh]
62 const current = Math.min(plan.current, merged.length)
63 return { ...plan, steps: merged, current, ...(current >= merged.length && merged.length > 0 ? { finishedAt: plan.finishedAt ?? now } : { finishedAt: undefined }) }
64}
65
66function clean(s: StepInput): PlanStep {
67 return { title: String(s.title).trim() || 'Untitled step', estimateMin: Math.max(0, Number(s.estimateMin) || 0) }
68}
69
70export type Summary = {
71 elapsedMs: number
72 stepElapsedMs: number
73 stepEstimateMs: number
74 /** Estimated time still to go: the running step's unspent estimate plus every later step's. */
75 remainingMs: number
76 isOver: boolean
77 isFinished: boolean
78}
79
80export function summarize(plan: Plan, now: number): Summary {
81 const end = plan.finishedAt ?? now
82 const running = plan.steps[plan.current]
83 const isFinished = plan.finishedAt !== undefined || running === undefined
84 const stepElapsedMs = !isFinished && running?.startedAt !== undefined ? now - running.startedAt : 0
85 const stepEstimateMs = isFinished ? 0 : (running?.estimateMin ?? 0) * MINUTE
86 const later = plan.steps.slice(plan.current + 1).reduce((sum, s) => sum + s.estimateMin * MINUTE, 0)
87 return {
88 elapsedMs: end - plan.startedAt,
89 stepElapsedMs,
90 stepEstimateMs,
91 remainingMs: isFinished ? 0 : Math.max(0, stepEstimateMs - stepElapsedMs) + later,
92 isOver: !isFinished && stepEstimateMs > 0 && stepElapsedMs > stepEstimateMs,
93 isFinished,
94 }
95}
96
97export function stepDurationMs(plan: Plan, i: number, now: number): number | undefined {
98 const s = plan.steps[i]
99 if (s?.startedAt === undefined) return undefined
100 return (s.endedAt ?? now) - s.startedAt
101}
102
103export type Segment = { text: string; kind: 'done' | 'now' | 'left' | 'over' | 'todo' | 'gap' }
104
105/**
106 * The timeline as runs of cells, one block per step sized by its actual time (done),
107 * its larger of elapsed and estimate (running) or its estimate (to do).
108 */
109export function timeline(plan: Plan, now: number, width: number): Segment[] {
110 const n = plan.steps.length
111 if (n === 0 || width < n) return []
112 /** Separators only where every step still gets a cell of its own. */
113 const hasGaps = width - (n - 1) >= n
114 const room = hasGaps ? width - (n - 1) : width
115 const weights = plan.steps.map((s, i) => {
116 const est = s.estimateMin * MINUTE
117 if (i < plan.current || plan.finishedAt !== undefined) return Math.max(stepDurationMs(plan, i, now) ?? 0, 1)
118 if (i === plan.current) return Math.max(est, stepDurationMs(plan, i, now) ?? 0, 1)
119 return Math.max(est, 1)
120 })
121 const cells = allocate(weights, room)
122 const out: Segment[] = []
123 plan.steps.forEach((s, i) => {
124 if (i > 0 && hasGaps) out.push({ text: '│', kind: 'gap' })
125 const w = cells[i] ?? 1
126 if (i < plan.current || plan.finishedAt !== undefined) {
127 out.push({ text: '━'.repeat(w), kind: 'done' })
128 } else if (i === plan.current) {
129 const spent = stepDurationMs(plan, i, now) ?? 0
130 const est = s.estimateMin * MINUTE
131 if (est > 0 && spent > est) {
132 const ok = Math.max(1, Math.round((w * est) / spent))
133 out.push({ text: '━'.repeat(Math.min(ok, w)), kind: 'now' })
134 if (w - ok > 0) out.push({ text: '━'.repeat(w - ok), kind: 'over' })
135 } else {
136 const fill = est > 0 ? Math.min(w, Math.max(1, Math.round((w * spent) / est))) : w
137 out.push({ text: '━'.repeat(fill), kind: 'now' })
138 if (w - fill > 0) out.push({ text: '─'.repeat(w - fill), kind: 'left' })
139 }
140 } else {
141 out.push({ text: '─'.repeat(w), kind: 'todo' })
142 }
143 })
144 return out
145}
146
147/** Every weight gets at least one cell; the rest go by largest remainder. */
148function allocate(weights: number[], room: number): number[] {
149 const spare = room - weights.length
150 const total = weights.reduce((a, b) => a + b, 0)
151 const exact = weights.map(w => (spare * w) / total)
152 const cells = exact.map(x => 1 + Math.floor(x))
153 let left = room - cells.reduce((a, b) => a + b, 0)
154 const order = exact.map((x, i) => [x - Math.floor(x), i] as const).sort((a, b) => b[0] - a[0])
155 for (const [, i] of order) {
156 if (left <= 0) break
157 cells[i] = (cells[i] ?? 0) + 1
158 left -= 1
159 }
160 return cells
161}
162
163export function fmt(ms: number): string {
164 const s = Math.max(0, Math.round(ms / 1000))
165 if (s < 60) return `${s}s`
166 const m = Math.floor(s / 60)
167 if (m < 60) return `${m}m`
168 const h = Math.floor(m / 60)
169 return `${h}h${String(m % 60).padStart(2, '0')}m`
170}
171
172export function clockTime(ms: number): string {
173 const d = new Date(ms)
174 return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
175}
176
177/** The plan as text: the tool's answer and the pane's fallback. */
178export function describe(plan: Plan, now: number): string {
179 const sum = summarize(plan, now)
180 const head = sum.isFinished
181 ? `Plan "${plan.title}" finished in ${fmt(sum.elapsedMs)}.`
182 : `Plan "${plan.title}": step ${plan.current + 1}/${plan.steps.length}, ${fmt(sum.elapsedMs)} elapsed, ~${fmt(sum.remainingMs)} left.`
183 const rows = plan.steps.map((s, i) => {
184 const took = stepDurationMs(plan, i, now)
185 const mark = i < plan.current || sum.isFinished ? 'done' : i === plan.current ? 'now ' : 'todo'
186 return ` ${mark} ${i + 1}. ${s.title} — est ${s.estimateMin}m${took !== undefined ? `, ${fmt(took)}` : ''}`
187 })
188 return [head, ...rows].join('\n')
189}
190types/index.d.ts 23 lines1export type PlanStep = {
2 title: string
3 /** The estimate in minutes, as last given. */
4 estimateMin: number
5 startedAt?: number
6 endedAt?: number
7}
8
9export type Plan = {
10 title: string
11 startedAt: number
12 finishedAt?: number
13 /** Index of the running step; equals steps.length once finished. */
14 current: number
15 steps: PlanStep[]
16}
17
18declare module 'claude-code' {
19 interface PluginState {
20 'plan-progress': { plan: Plan | null }
21 }
22}
23