Calm, non-technical view: hides tool rows and shows one plain-English checklist above the prompt.

Public Claude Code plugins and mods by schmas.
| Plugin | Scope | Contents | ||
|---|---|---|---|---|
clean-view | Calm view for non-technical users (mod) | Hides tool calls, diffs and command output; shows one plain-English checklist with progress meters above the prompt. Three modes: on hides details, both shows details and the checklist, off. Switch with the band button or `/simple on\ | both\ | off`. With Toolbox installed, the switch is a row in the Toolbox panel |
toolbox | Model and effort switcher (mod) | ◆ Toolbox button sits in the prompt footer, next to the mode labels, and opens a panel last above the prompt. A SETTINGS row moves the button above the prompt too. One click sets the session model or effort. Other mods add rows to it through $.toolbox. Toggle with the button or /toolbox | ||
skillbox | General-purpose skills (grows over time) | media-processing: FFmpeg video/audio, ImageMagick images, RMBG background removal, plus helper scripts for conversion, web video optimization and batch resize |
Add the marketplace once, then install the plugins you want.
/plugin marketplace add schmas/claude-plugins
/plugin install clean-view@schmas
/plugin install toolbox@schmas
/plugin install skillbox@schmas
/reload-plugins
claude-plugins/
├── .claude-plugin/
│ └── marketplace.json # Lists 3 plugins
├── plugins/
│ ├── clean-view/
│ │ ├── .claude-plugin/plugin.json
│ │ ├── hooks/ # Function-hook mod + tests
│ │ └── types/ # Shared checklist state contract
│ ├── toolbox/
│ │ ├── .claude-plugin/plugin.json
│ │ ├── hooks/ # Function-hook mod + tests
│ │ └── types/ # $.toolbox add-on API + state contract
│ └── skillbox/
│ ├── .claude-plugin/plugin.json
│ └── skills/ # One folder per skill (media-processing, ...)
└── README.md
MIT. See LICENSE.
hooks/register.tsx 8 lines1import type { Register } from 'claude-code'
2
3import { registerCleanView } from './clean-view'
4
5export const register: Register = on => {
6 registerCleanView(on)
7}
8hooks/clean-view.tsx 1182 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, On, RenderElement, RenderInput, Timer } from 'claude-code'
3
4import type { CleanViewChecklist, CleanViewMode, CleanViewPhase, CleanViewTask } from '../types'
5
6type Engine = EngineInterface
7
8const PLAN_TOOL = 'mcp__clean-view__plan_steps'
9const PROGRESS_TOOL = 'mcp__clean-view__report_progress'
10const STORE_KEY = 'cleanViewMode'
11/** The on/off value saved before the both mode existed. */
12const LEGACY_STORE_KEY = 'cleanViewEnabled'
13const SECTION_ID = 'clean-view:checklist'
14
15const MAX_NAME = 40
16const FALLBACK_NAME = 'Working on it'
17const METER_CELLS = 16
18const FRAME_MS = 250
19const FAIL_LIMIT = 3
20const MIN_STEPS = 2
21const MAX_STEPS = 8
22
23const ALWAYS_ALLOWED = new Set([
24 'ToolSearch',
25 'TodoWrite',
26 'TaskCreate',
27 'TaskUpdate',
28 'AskUserQuestion',
29 PLAN_TOOL,
30])
31
32const PLACEHOLDER_STEPS = ['Understand your request', 'Plan the steps']
33
34const OWN_TOOLS = new Set([PLAN_TOOL, PROGRESS_TOOL])
35const OFF_DESCRIPTION = 'Clean View is off. Do not call this tool.'
36const OFF_REPLY = 'Clean View is off. Skip this tool and go on with the work.'
37
38const NEEDS_OK = 'Claude needs your OK to continue'
39const HAS_QUESTION = 'Claude has a question for you'
40const WAITING_REPLY = 'Claude is waiting for your reply'
41const SAID_NO = 'you said no to a step, so Claude paused'
42const KEEPS_FAILING = 'a step keeps failing, Claude is trying another way'
43const REFUSED = "Claude couldn't help with that request"
44const API_USAGE = 'you hit your usage limit, try again a little later'
45const API_BUSY = "Claude's servers are busy, try again in a minute"
46const API_TOO_LONG = 'type /compact and try again'
47const API_NETWORK = 'the internet connection dropped'
48const API_AUTH = 'type /login'
49const API_OTHER = 'something went wrong talking to Claude, try again'
50
51const USER_SAID_NO = /doesn't want to proceed|tool use was rejected/i
52
53const GATE_MESSAGE =
54 `Clean View: call ${PLAN_TOOL} first to lay out the steps of this job in plain English ` +
55 '(load it with ToolSearch if it is deferred). Then try this tool again.'
56
57const CODE_EXTENSIONS =
58 'tsx?|jsx?|mjs|cjs|mts|cts|py|rb|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|cs|php|sh|bash|zsh|fish|ps1|' +
59 'json|jsonc|ya?ml|toml|ini|env|lock|md|mdx|html?|css|scss|sass|less|sql|vue|svelte|xml|gradle|tf|dart|lua|r'
60const FILE_NAME = new RegExp(`^[("'\\[]*[\\w.-]+\\.(${CODE_EXTENSIONS})[)"'\\],.:;!?]*$`, 'i')
61
62const EMPTY: CleanViewChecklist = {
63 title: '',
64 phase: 'idle',
65 tasks: [],
66 needsYouReason: null,
67 stuckReason: null,
68 startedAt: null,
69 finishedAt: null,
70 isPlanned: false,
71}
72
73const MODES: readonly CleanViewMode[] = ['on', 'both', 'off']
74
75const MODE_LABEL: Record<CleanViewMode, string> = {
76 on: '● Clean View: ON',
77 both: '◐ Clean View: BOTH',
78 off: '○ Clean View: OFF',
79}
80
81const MODE_TOAST: Record<CleanViewMode, string> = {
82 on: 'Clean View is on. Technical details are hidden.',
83 both: 'Clean View is on. You see the checklist and every detail.',
84 off: 'Clean View is off. You see every detail again.',
85}
86
87/** The Toolbox row's choices, in /simple's order. */
88const MODE_CHOICE: Record<CleanViewMode, string> = {
89 on: 'On',
90 both: 'Both',
91 off: 'Off',
92}
93
94const MODE_REPLY: Record<CleanViewMode, string> = {
95 on: 'Clean View is on.',
96 both: 'Clean View is on, with every detail shown.',
97 off: 'Clean View is off.',
98}
99
100const MODE = { plugin: 'clean-view', key: 'mode' } as const
101const mode = atom(MODE, 'on' as CleanViewMode)
102const checklist = atom({ plugin: 'clean-view', key: 'checklist' } as const, EMPTY)
103const tick = atom({ plugin: 'clean-view', key: 'tick' } as const, 0)
104const isGuided = atom({ plugin: 'clean-view', key: 'isGuided' } as const, false)
105
106/** Turns any step or job name into short plain English with no code in it. */
107export function cleanName(raw: string): string {
108 const words = raw
109 .replace(/`[^`]*`/g, ' ')
110 .replace(/`/g, ' ')
111 .split(/\s+/)
112 .filter(word => word !== '' && !word.includes('/') && !word.includes('\\') && !FILE_NAME.test(word))
113 const text = words.join(' ').replace(/\s+/g, ' ').trim()
114
115 if (text === '') {
116 return FALLBACK_NAME
117 }
118
119 const named = text[0]!.toUpperCase() + text.slice(1)
120
121 if (named.length <= MAX_NAME) {
122 return named
123 }
124
125 const head = named.slice(0, MAX_NAME - 1)
126 const space = head.lastIndexOf(' ')
127 const cut = (space > 0 ? head.slice(0, space) : head).replace(/[\s,.;:!?-]+$/, '')
128
129 return `${cut}…`
130}
131
132function jobTitle(raw: string): string {
133 const firstLine = raw.split('\n').find(line => line.trim() !== '') ?? ''
134 const words = cleanName(firstLine.replace(/["'*_#.]/g, ' ')).replace(/…$/, '').split(' ')
135
136 return cleanName(words.slice(0, 6).join(' '))
137}
138
139function elapsed(ms: number): string {
140 const seconds = Math.max(0, Math.floor(ms / 1000))
141 const hours = Math.floor(seconds / 3600)
142 const minutes = Math.floor((seconds % 3600) / 60)
143
144 if (hours > 0) {
145 return `${hours}h ${minutes}m`
146 }
147
148 return minutes > 0 ? `${minutes}m ${seconds % 60}s` : `${seconds}s`
149}
150
151function clampPercent(value: unknown): number {
152 const number = Number(value)
153
154 return Number.isFinite(number) ? Math.min(100, Math.max(0, Math.round(number))) : 0
155}
156
157function isMode(value: unknown): value is CleanViewMode {
158 return MODES.includes(value as CleanViewMode)
159}
160
161function nextMode(current: CleanViewMode): CleanViewMode {
162 return MODES[(MODES.indexOf(current) + 1) % MODES.length]!
163}
164
165/**
166 * The mode now. A /clear starts the session's state over, and no event this
167 * mod can count on fires after it, so a mode not set yet this session comes
168 * from the store.
169 */
170async function currentMode($: Engine): Promise<CleanViewMode> {
171 const { value } = await $.state.get(MODE)
172
173 return isMode(value) ? value : storedMode($)
174}
175
176/** The checklist runs in `on` and `both`. */
177async function isTracking($: Engine): Promise<boolean> {
178 return (await currentMode($)) !== 'off'
179}
180
181/** Tool rows are hidden only in `on`; `both` keeps them next to the checklist. */
182async function isHiding($: Engine): Promise<boolean> {
183 return (await currentMode($)) === 'on'
184}
185
186/**
187 * Tools wait for a plan only once the model was told to plan. A plugin that
188 * runs first can skip the hooks that tell it, and the model cannot follow a rule it never got.
189 */
190async function mustPlanFirst($: Engine): Promise<boolean> {
191 return (await isTracking($)) && (await read($, isGuided)) && !(await read($, checklist)).isPlanned
192}
193
194async function markGuided($: Engine): Promise<void> {
195 if (!(await read($, isGuided))) {
196 await update($, isGuided, () => true)
197 }
198}
199
200function isRunning(phase: CleanViewPhase): boolean {
201 return phase === 'working' || phase === 'needsYou' || phase === 'stuck'
202}
203
204function task(id: string, name: string, status: CleanViewTask['status']): CleanViewTask {
205 const isDone = status === 'done'
206
207 return { id, name, status, percent: isDone ? 100 : 0, hasReported: isDone }
208}
209
210function finishAll(tasks: CleanViewTask[]): CleanViewTask[] {
211 return tasks.map(one => ({ ...one, status: 'done', percent: 100, hasReported: true }))
212}
213
214/** Checks off every step before `index`, sets that step's percent and starts the next one at 100. */
215function reportAt(tasks: CleanViewTask[], index: number, percent: number): CleanViewTask[] {
216 const isFinished = percent >= 100
217 const reported = tasks.map((one, at): CleanViewTask => {
218 if (at < index) {
219 return { ...one, status: 'done', percent: 100, hasReported: true }
220 }
221
222 if (at === index) {
223 return { ...one, status: isFinished ? 'done' : 'active', percent, hasReported: true }
224 }
225
226 return one.status === 'active' ? { ...one, status: 'upcoming', percent: 0, hasReported: false } : one
227 })
228
229 if (!isFinished) {
230 return reported
231 }
232
233 const following = reported.findIndex((one, at) => at > index && one.status === 'upcoming')
234
235 return following < 0
236 ? reported
237 : reported.map((one, at) => (at === following ? { ...one, status: 'active', percent: 0, hasReported: false } : one))
238}
239
240function applyProgress(tasks: CleanViewTask[], rawName: string, percent: number): CleanViewTask[] {
241 const name = cleanName(rawName)
242 const found = tasks.findIndex(one => one.name.toLowerCase() === name.toLowerCase())
243
244 if (found >= 0) {
245 return reportAt(tasks, found, percent)
246 }
247
248 // An unplanned step lands where the current step is, so nothing is checked off by mistake.
249 const active = tasks.findIndex(one => one.status === 'active')
250 const at = active >= 0 ? active : tasks.filter(one => one.status === 'done').length
251 const added = [...tasks.slice(0, at), task(`extra-${tasks.length + 1}`, name, 'upcoming'), ...tasks.slice(at)]
252
253 return reportAt(added, at, percent)
254}
255
256function todoStatus(status: unknown): CleanViewTask['status'] {
257 if (status === 'completed') {
258 return 'done'
259 }
260
261 return status === 'in_progress' ? 'active' : 'upcoming'
262}
263
264function apiReason(kind: string, details: string): string {
265 const text = `${kind} ${details}`
266
267 if (/rate_limit|billing|usage limit|429/i.test(text)) {
268 return API_USAGE
269 }
270
271 if (/overloaded|server_error|529|50\d/i.test(text)) {
272 return API_BUSY
273 }
274
275 if (/too long|context|too many tokens|max_output_tokens/i.test(text)) {
276 return API_TOO_LONG
277 }
278
279 if (/authentication|oauth|credential|verification|401|403|\/login|api key/i.test(text)) {
280 return API_AUTH
281 }
282
283 if (/network|connection|connect|econn|enotfound|fetch failed|socket|offline|timed? ?out/i.test(text)) {
284 return API_NETWORK
285 }
286
287 return API_OTHER
288}
289
290function guide(tools: readonly string[]): string {
291 const hasTodos = tools.includes('TodoWrite') || tools.includes('TaskCreate')
292 const lines = [
293 '# Clean View',
294 'The person sees a simple checklist of your work instead of tool calls. Keep it accurate.',
295 '- Write every step name in plain English a non-technical person understands. Keep it under 40 characters and start it with a verb, like "Build the pricing section".',
296 '- Never put file paths, file names, commands, code or tool names in a step name.',
297 `- For every request, even a quick question, call ${PLAN_TOOL} first with 2 to 8 short steps in order. Load it with ToolSearch if it is deferred. Other tools are blocked until a plan exists.`,
298 `- Then call ${PROGRESS_TOOL} as real progress happens, and with percent 100 the moment a step finishes.`,
299 ]
300
301 if (hasTodos) {
302 lines.push('- You can use your to-do list (TodoWrite or TaskCreate) as the plan instead; the same naming rules apply.')
303 }
304
305 return lines.join('\n')
306}
307
308function padEnd(text: string, width: number): string {
309 if (width <= 0) {
310 return ''
311 }
312
313 const chars = [...text]
314
315 if (chars.length > width) {
316 return `${chars.slice(0, Math.max(0, width - 1)).join('')}…`
317 }
318
319 return text + ' '.repeat(width - chars.length)
320}
321
322type Stops = readonly string[]
323
324const PINK = '#ff4f8b'
325const TITLE_STOPS: Stops = ['#ff8a3d', '#ff4f8b', '#c86bfa', '#7aa2ff']
326const OVERALL_STOPS: Stops = ['#ff8a3d', '#ff4f8b']
327const DONE_STOPS: Stops = ['#1e8f4e', '#6ee7a0']
328const ACTIVE_STOPS: Stops = ['#8a2f5a', '#ff6fb0']
329const GRADIENT_STEPS = 8
330const SHIMMER_CELLS = 6
331/** The empty part of a bar: a dark gray box, just above the terminal background. */
332const TRACK = '#1f1f25'
333/** One bar cell. The box is narrower than the cell, so each step shows as its own box. */
334const BOX = '■'
335
336const BORDER: Record<CleanViewPhase, string> = {
337 idle: PINK,
338 working: PINK,
339 needsYou: 'yellow',
340 stuck: 'yellow',
341 stopped: 'red',
342 done: 'green',
343}
344
345function hex(color: string): number[] {
346 return [1, 3, 5].map(at => parseInt(color.slice(at, at + 2), 16))
347}
348
349/** The color at `t` (0 to 1) along evenly spaced stops. */
350export function blend(stops: Stops, t: number): string {
351 if (stops.length === 1) {
352 return stops[0]!
353 }
354
355 const at = Math.min(1, Math.max(0, t)) * (stops.length - 1)
356 const low = Math.min(stops.length - 2, Math.floor(at))
357 const from = hex(stops[low]!)
358 const to = hex(stops[low + 1]!)
359 const mix = at - low
360
361 return `#${from.map((one, i) => Math.round(one + (to[i]! - one) * mix).toString(16).padStart(2, '0')).join('')}`
362}
363
364type Cell = { char: string; color: string }
365
366/** Draws cells as Text runs, one run per color, so a long bar stays a few elements. */
367function cells($: Engine, e: RenderInput<'AbovePrompt'>, key: string, list: Cell[]): RenderElement {
368 const { Text } = $.ui.resolve(e)
369 const runs: Cell[] = []
370
371 for (const one of list) {
372 const last = runs[runs.length - 1]
373
374 if (last !== undefined && last.color === one.color) {
375 last.char += one.char
376 } else {
377 runs.push({ ...one })
378 }
379 }
380
381 return (
382 <Text key={key}>
383 {runs.map((run, at) => (
384 <Text key={`${key}-${at}`} color={run.color}>
385 {run.char}
386 </Text>
387 ))}
388 </Text>
389 )
390}
391
392/** `filled` gradient boxes, then dark track boxes, `width` in all. */
393function bar(width: number, filled: number, stops: Stops): Cell[] {
394 return Array.from({ length: width }, (_, at): Cell => {
395 if (at >= filled) {
396 return { char: BOX, color: TRACK }
397 }
398
399 const t = Math.round((filled <= 1 ? 1 : at / (filled - 1)) * (GRADIENT_STEPS - 1)) / (GRADIENT_STEPS - 1)
400
401 return { char: BOX, color: blend(stops, t) }
402 })
403}
404
405/** A short pink streak that runs along the track while a step has no percent yet. */
406function shimmer(width: number, frame: number): Cell[] {
407 const head = frame % (width + SHIMMER_CELLS)
408
409 return Array.from({ length: width }, (_, at): Cell => {
410 const behind = head - at
411
412 if (behind < 0 || behind >= SHIMMER_CELLS) {
413 return { char: BOX, color: TRACK }
414 }
415
416 return { char: BOX, color: blend(ACTIVE_STOPS, 1 - behind / (SHIMMER_CELLS - 1)) }
417 })
418}
419
420function meter(one: CleanViewTask, frame: number, width: number): Cell[] {
421 if (one.status === 'done') {
422 return bar(width, width, DONE_STOPS)
423 }
424
425 if (one.status === 'upcoming') {
426 return bar(width, 0, DONE_STOPS)
427 }
428
429 if (!one.hasReported) {
430 return shimmer(width, frame)
431 }
432
433 return bar(width, Math.round((one.percent / 100) * width), ACTIVE_STOPS)
434}
435
436/** Whole-job progress: done steps plus the active step's reported share. */
437export function overallPercent(tasks: readonly CleanViewTask[]): number {
438 if (tasks.length === 0) {
439 return 0
440 }
441
442 const share = tasks.reduce((sum, one) => {
443 if (one.status === 'done') {
444 return sum + 1
445 }
446
447 return one.status === 'active' && one.hasReported ? sum + one.percent / 100 : sum
448 }, 0)
449
450 return Math.round((share / tasks.length) * 100)
451}
452
453/** The step number the header names: the active step, or the count done when none is active. */
454function stepNumber(tasks: readonly CleanViewTask[]): number {
455 const active = tasks.findIndex(one => one.status === 'active')
456
457 return active >= 0 ? active + 1 : tasks.filter(one => one.status === 'done').length
458}
459
460let frameTimer: Timer | null = null
461let failures = 0
462let lastApiError: { kind: string; details: string } | null = null
463
464function syncClock($: Engine, list: CleanViewChecklist): void {
465 const shouldAnimate = list.phase === 'working' || list.phase === 'needsYou'
466
467 if (shouldAnimate && frameTimer === null) {
468 frameTimer = $.clock.every(FRAME_MS, () => {
469 void update($, tick, frame => frame + 1)
470 })
471 }
472
473 if (!shouldAnimate && frameTimer !== null) {
474 frameTimer.cancel()
475 frameTimer = null
476 }
477}
478
479async function change($: Engine, fn: (list: CleanViewChecklist) => CleanViewChecklist): Promise<CleanViewChecklist> {
480 const list = await update($, checklist, fn)
481 syncClock($, list)
482
483 return list
484}
485
486async function startJob($: Engine, title: string): Promise<CleanViewChecklist> {
487 const now = await $.clock.now()
488 failures = 0
489 lastApiError = null
490
491 return change($, () => ({
492 ...EMPTY,
493 title,
494 phase: 'working',
495 tasks: PLACEHOLDER_STEPS.map((name, at) => task(`placeholder-${at + 1}`, name, at === 0 ? 'active' : 'upcoming')),
496 startedAt: now,
497 }))
498}
499
500async function ensureJob($: Engine): Promise<void> {
501 const list = await read($, checklist)
502
503 if (!isRunning(list.phase)) {
504 await startJob($, FALLBACK_NAME)
505 }
506}
507
508async function nameJob($: Engine, prompt: string, startedAt: number | null): Promise<void> {
509 try {
510 const reply = await $.model.complete({
511 model: 'haiku',
512 effort: 'low',
513 maxTokens: 40,
514 timeoutMs: 15000,
515 system:
516 'Name the request as a job title a non-technical person understands: 2 to 6 plain English words that start with a verb, like "Build my landing page". No file names, paths, code or quotes. Reply with the title only.',
517 prompt: prompt.slice(0, 4000),
518 })
519
520 if (!reply.isAnswered) {
521 return
522 }
523
524 const title = jobTitle(reply.text)
525 await update($, checklist, list => (list.startedAt === startedAt ? { ...list, title } : list))
526 } catch {
527 // The header keeps its fallback name.
528 }
529}
530
531async function setStuck($: Engine, reason: string): Promise<void> {
532 await change($, list => (isRunning(list.phase) ? { ...list, phase: 'stuck', stuckReason: reason, needsYouReason: null } : list))
533}
534
535async function setNeedsYou($: Engine, reason: string): Promise<void> {
536 await ensureJob($)
537 await change($, list => ({ ...list, phase: 'needsYou', needsYouReason: reason }))
538}
539
540async function resume($: Engine): Promise<void> {
541 await change($, list =>
542 list.phase === 'needsYou' || list.phase === 'stuck'
543 ? { ...list, phase: 'working', needsYouReason: null, stuckReason: null }
544 : list,
545 )
546}
547
548async function setMode($: Engine, value: CleanViewMode): Promise<void> {
549 const wasTracking = await isTracking($)
550 await update($, mode, () => value)
551
552 // The tool descriptions change only between off and the other modes; a redescribe spends the prompt cache.
553 if (wasTracking !== (value !== 'off')) {
554 $.ui.invalidate('tool.describe')
555 }
556
557 await $.store.set(STORE_KEY, value)
558 sendToolboxRow($, value)
559 $.ui.toast(MODE_TOAST[value])
560}
561
562/** The mode a Toolbox choice names, or null for an unknown one. */
563export function choiceMode(choice: unknown): CleanViewMode | null {
564 return MODES.find(one => MODE_CHOICE[one] === choice) ?? null
565}
566
567const TOOLBOX_ROW = 'clean-view.mode'
568
569/**
570 * Sends the mode switch to the Toolbox panel when the Toolbox mod is loaded.
571 * Returns false when Toolbox is not loaded, so Clean View keeps its own button.
572 */
573function sendToolboxRow($: Engine, current: CleanViewMode): boolean {
574 try {
575 $.toolbox.addSetting({
576 id: TOOLBOX_ROW,
577 label: 'Clean View',
578 hint: 'simple checklist',
579 kind: 'choice',
580 options: MODES.map(one => MODE_CHOICE[one]),
581 value: MODE_CHOICE[current],
582 })
583
584 return true
585 } catch {
586 // Toolbox is not installed or not enabled: Clean View works as before.
587 return false
588 }
589}
590
591async function storedMode($: Engine): Promise<CleanViewMode> {
592 const stored = await $.store.get(STORE_KEY)
593
594 if (isMode(stored)) {
595 return stored
596 }
597
598 const legacy = await $.store.get(LEGACY_STORE_KEY)
599
600 return legacy === false ? 'off' : 'on'
601}
602
603async function planSteps($: Engine, input: Record<string, unknown>) {
604 const raw = Array.isArray(input.steps) ? input.steps : []
605 const steps = raw.map(step => cleanName(String(step))).slice(0, MAX_STEPS)
606
607 if (steps.length < MIN_STEPS) {
608 return { deny: `Give ${MIN_STEPS} to ${MAX_STEPS} short step names, in order.` }
609 }
610
611 await ensureJob($)
612 await change($, list => ({
613 ...list,
614 phase: list.phase === 'stuck' ? 'working' : list.phase,
615 stuckReason: list.phase === 'stuck' ? null : list.stuckReason,
616 tasks: steps.map((name, at) => task(`step-${at + 1}`, name, at === 0 ? 'active' : 'upcoming')),
617 isPlanned: true,
618 }))
619
620 return { result: `Planned ${steps.length} steps. The first one has started.` }
621}
622
623async function reportProgress($: Engine, input: Record<string, unknown>) {
624 const percent = clampPercent(input.percent)
625 await ensureJob($)
626 await change($, list => ({ ...list, tasks: applyProgress(list.tasks, String(input.task ?? ''), percent) }))
627
628 return { result: `Progress noted: ${percent}%.` }
629}
630
631async function trackTodos($: Engine, input: Record<string, unknown>): Promise<void> {
632 if (!Array.isArray(input.todos)) {
633 return
634 }
635
636 const todos = input.todos as Array<Record<string, unknown>>
637 await ensureJob($)
638 await change($, list => ({
639 ...list,
640 isPlanned: list.isPlanned || todos.length > 0,
641 tasks: todos.map((todo, at) => {
642 const name = cleanName(String(todo.content ?? todo.activeForm ?? ''))
643 const status = todoStatus(todo.status)
644 const before = list.tasks.find(one => one.name === name && one.status === 'active')
645
646 return status === 'active' && before !== undefined
647 ? { ...before, id: `todo-${at + 1}` }
648 : task(`todo-${at + 1}`, name, status)
649 }),
650 }))
651}
652
653async function trackTaskCreate($: Engine, input: Record<string, unknown>, resultText: string): Promise<void> {
654 const name = cleanName(String(input.subject ?? input.description ?? ''))
655 const number = /#?(\d+)/.exec(resultText)?.[1]
656 await ensureJob($)
657 await change($, list => {
658 const kept = list.isPlanned ? list.tasks : []
659 const id = `task-${number ?? kept.length + 1}`
660
661 return { ...list, isPlanned: true, tasks: [...kept.filter(one => one.id !== id), task(id, name, 'upcoming')] }
662 })
663}
664
665async function trackTaskUpdate($: Engine, input: Record<string, unknown>): Promise<void> {
666 const id = `task-${String(input.taskId ?? '')}`
667 const subject = typeof input.subject === 'string' ? cleanName(input.subject) : null
668 await change($, list => {
669 if (input.status === 'deleted') {
670 return { ...list, tasks: list.tasks.filter(one => one.id !== id) }
671 }
672
673 const status = input.status === undefined ? null : todoStatus(input.status)
674
675 return {
676 ...list,
677 tasks: list.tasks.map(one => {
678 if (one.id !== id) {
679 return one
680 }
681
682 const named = subject === null ? one : { ...one, name: subject }
683
684 if (status === null || status === named.status) {
685 return named
686 }
687
688 return status === 'active' ? { ...named, status, percent: 0, hasReported: false } : task(id, named.name, status)
689 }),
690 }
691 })
692}
693
694async function trackOutcome($: Engine, ran: { deny?: string; isError?: true; text?: string; result?: unknown }): Promise<void> {
695 const message = ran.deny ?? ran.text ?? (typeof ran.result === 'string' ? ran.result : '')
696
697 if (USER_SAID_NO.test(message)) {
698 failures = 0
699 await setStuck($, SAID_NO)
700
701 return
702 }
703
704 if (ran.deny !== undefined) {
705 return
706 }
707
708 if (ran.isError === true) {
709 failures += 1
710
711 if (failures >= FAIL_LIMIT) {
712 await setStuck($, KEEPS_FAILING)
713 }
714
715 return
716 }
717
718 failures = 0
719 await change($, list => (list.phase === 'stuck' ? { ...list, phase: 'working', stuckReason: null } : list))
720}
721
722/** Colors each word of the title along the title gradient. */
723function gradientTitle($: Engine, e: RenderInput<'AbovePrompt'>, title: string): RenderElement {
724 const { Text } = $.ui.resolve(e)
725 const words = title.split(' ')
726
727 return (
728 <Text bold>
729 {words.map((word, at) => (
730 <Text key={`word-${at}`} color={blend(TITLE_STOPS, words.length <= 1 ? 0 : at / (words.length - 1))}>
731 {at === 0 ? word : ` ${word}`}
732 </Text>
733 ))}
734 </Text>
735 )
736}
737
738/** Draws the band; null when there is nothing to show. With Toolbox loaded, the mode switch lives in its panel. */
739async function drawBand($: Engine, e: RenderInput<'AbovePrompt'>, hasToolbox: boolean): Promise<RenderElement | null> {
740 const { Box, Text, Button } = $.ui.resolve(e)
741 const current = await currentMode($)
742 const list = await read($, checklist)
743 const frame = await read($, tick)
744 const now = await $.clock.now()
745 const width = Math.max(24, e.props.bodyColumns)
746 // The round border and one cell of padding on each side.
747 const inner = width - 4
748
749 const toggle = hasToolbox ? null : (
750 <Box key="toggle-row" flexDirection="row" justifyContent="flex-end" width={width}>
751 <Button key="toggle" label={MODE_LABEL[current]} onPress={() => setMode($, nextMode(current))} />
752 </Box>
753 )
754
755 if (current === 'off' || list.phase === 'idle') {
756 return toggle === null ? null : <Box flexDirection="column">{toggle}</Box>
757 }
758
759 const title = list.title || FALLBACK_NAME
760 const runFor = elapsed((list.finishedAt ?? now) - (list.startedAt ?? now))
761 let left: RenderElement
762
763 switch (list.phase) {
764 case 'needsYou':
765 left = (
766 <Text wrap="truncate">
767 <Text bold inverse color="yellow"> Needs you </Text> {list.needsYouReason ?? WAITING_REPLY}
768 </Text>
769 )
770 break
771 case 'stuck':
772 left = (
773 <Text wrap="truncate" color="yellow">
774 ⚠ Stuck: {list.stuckReason ?? KEEPS_FAILING}
775 </Text>
776 )
777 break
778 case 'stopped':
779 left = (
780 <Text wrap="truncate">
781 <Text color="red">■ Stopped</Text> · {title} · you pressed Esc
782 </Text>
783 )
784 break
785 case 'done':
786 left = (
787 <Text wrap="truncate">
788 <Text color="green">✓ All done</Text> · {title}
789 </Text>
790 )
791 break
792 default:
793 left = (
794 <Text wrap="truncate">
795 <Text color={PINK}>✶ </Text>
796 {gradientTitle($, e, title)}
797 </Text>
798 )
799 }
800
801 // One button per mode; the current one is bracketed and full strength, the others dim.
802 const switches = MODES.map(one =>
803 one === current ? (
804 <Button key={`mode-${one}`} plain label={`[${MODE_CHOICE[one]}]`} onPress={() => setMode($, one)} />
805 ) : (
806 <Button key={`mode-${one}`} plain dimColor label={` ${MODE_CHOICE[one]} `} onPress={() => setMode($, one)} />
807 ),
808 )
809 // A finished list stays until the next request or until this button clears it.
810 const clear = isRunning(list.phase) ? null : (
811 <Button key="clear" plain dimColor label=" ✕ Clear " onPress={() => change($, () => EMPTY)} />
812 )
813 const header = (
814 <Box key="header" flexDirection="row" justifyContent="space-between" width={inner}>
815 <Box flexShrink={1}>{left}</Box>
816 <Box key="header-right" flexDirection="row" flexShrink={0}>
817 {switches}
818 {clear}
819 <Text dimColor> {runFor}</Text>
820 </Box>
821 </Box>
822 )
823 const frameBox = (children: RenderElement[]) => (
824 <Box key="frame" flexDirection="column" borderStyle="round" borderColor={BORDER[list.phase]} paddingX={1} width={width}>
825 {children}
826 </Box>
827 )
828
829 const total = list.tasks.length
830 const percent = overallPercent(list.tasks)
831 const stepLabel = `Step ${stepNumber(list.tasks)} of ${total} `
832 // label + bar + gap (1) + percent (4)
833 const overallWidth = Math.max(4, inner - stepLabel.length - 1 - 4)
834 const overall = (
835 <Box key="overall" flexDirection="row">
836 <Text>{stepLabel}</Text>
837 {cells($, e, 'overall-bar', bar(overallWidth, Math.round((percent / 100) * overallWidth), OVERALL_STOPS))}
838 <Text bold color={PINK}> {`${percent}%`.padStart(4)}</Text>
839 </Box>
840 )
841
842 // icon (2) + name + meter + gap (2) + label (7)
843 const meterWidth = Math.max(4, Math.min(METER_CELLS, inner - 2 - 12 - 2 - 7))
844 const nameWidth = Math.max(4, Math.min(MAX_NAME + 2, inner - 2 - meterWidth - 2 - 7))
845 const firstUpcoming = list.tasks.findIndex(one => one.status === 'upcoming')
846 const rows = list.tasks.map((one, at) => {
847 const name = `${padEnd(one.name, nameWidth - 1)} `
848 const track = cells($, e, `meter-${one.id}`, meter(one, frame, meterWidth))
849
850 if (one.status === 'done') {
851 return (
852 <Box key={`row-${one.id}`} flexDirection="row">
853 <Text color="green">✓ </Text>
854 <Text>{name}</Text>
855 {track}
856 <Text> Done</Text>
857 </Box>
858 )
859 }
860
861 if (one.status === 'active') {
862 const isWaiting = list.phase === 'needsYou'
863
864 return (
865 <Box key={`row-${one.id}`} flexDirection="row">
866 <Text color={isWaiting ? 'yellow' : PINK}>{isWaiting ? '‖ ' : '● '}</Text>
867 <Text bold>{name}</Text>
868 {track}
869 <Text bold color={PINK}>
870 {' '}
871 {one.hasReported ? `${one.percent}%` : 'Working'}
872 </Text>
873 </Box>
874 )
875 }
876
877 return (
878 <Box key={`row-${one.id}`} flexDirection="row">
879 <Text dimColor>○ </Text>
880 <Text dimColor>{name}</Text>
881 {track}
882 <Text dimColor> {at === firstUpcoming ? 'Next' : 'Up next'}</Text>
883 </Box>
884 )
885 })
886
887 return (
888 <Box flexDirection="column" marginTop={1}>
889 {toggle}
890 {frameBox([header, overall, ...rows])}
891 </Box>
892 )
893}
894
895export function registerCleanView(on: On): void {
896 on('session.start', async ($, e, next) => {
897 await $.tool.register({
898 name: 'plan_steps',
899 description:
900 'Lay out every step of the current job up front, in order, so the person sees a simple checklist. Call it first for every request. Each step is plain English, under 40 characters, starts with a verb, and never holds file paths, file names, commands, code or tool names.',
901 inputSchema: {
902 type: 'object',
903 properties: {
904 steps: {
905 type: 'array',
906 items: { type: 'string' },
907 minItems: MIN_STEPS,
908 maxItems: MAX_STEPS,
909 description: '2 to 8 short step names, in order, like "Build the pricing section".',
910 },
911 },
912 required: ['steps'],
913 },
914 })
915 await $.tool.register({
916 name: 'report_progress',
917 description:
918 'Report progress on the current step of the plan. Call it as real progress happens, and with percent 100 the moment a step finishes; the next step then starts by itself. Use the step name exactly as planned.',
919 inputSchema: {
920 type: 'object',
921 properties: {
922 task: { type: 'string', description: 'The step name, as given to plan_steps.' },
923 percent: { type: 'number', minimum: 0, maximum: 100, description: 'How far along the step is, 0 to 100.' },
924 },
925 required: ['task', 'percent'],
926 },
927 })
928 await $.command.register({
929 name: 'simple',
930 description: 'Set Clean View: on hides details, both shows details and the checklist, off (no argument cycles)',
931 argumentHint: 'on|both|off',
932 })
933
934 const stored = await storedMode($)
935 await update($, mode, () => stored)
936 syncClock($, await read($, checklist))
937 sendToolboxRow($, stored)
938
939 return next(e)
940 })
941
942 // A click on Clean View's row in the Toolbox panel.
943 on('state.set', { plugin: 'toolbox', key: 'press' }, async ($, e, next) => {
944 const result = await next(e)
945 const pressed = e.value
946 const value = pressed !== null && pressed.id === TOOLBOX_ROW ? choiceMode(pressed.value) : null
947
948 if (value !== null) {
949 await setMode($, value)
950 }
951
952 return result
953 })
954
955 on('command.run', { command: 'simple' }, async ($, e) => {
956 const arg = e.args.trim().toLowerCase()
957
958 if (arg !== '' && !isMode(arg)) {
959 return { text: 'Use /simple on, /simple both, /simple off, or /simple to go to the next mode.' }
960 }
961
962 const value = arg === '' ? nextMode(await currentMode($)) : arg
963 await setMode($, value)
964
965 return { text: MODE_REPLY[value] }
966 })
967
968 on('prompt.compose', async ($, e, next) => {
969 const composed = await next(e)
970
971 if (!(await isTracking($))) {
972 return composed
973 }
974
975 const sections = composed.sections.filter(section => section.id !== SECTION_ID)
976 await markGuided($)
977
978 return { ...composed, sections: [...sections, { id: SECTION_ID, text: guide(e.tools), scope: 'session' as const }] }
979 })
980
981 // A plugin that runs first can skip the prompt.compose hook. The guide then goes beside the next prompt, once.
982 on('prompt.submit', async ($, e, next) => {
983 if (e.command !== undefined || !(await isTracking($)) || (await read($, isGuided))) {
984 return next(e)
985 }
986
987 const text = guide((await $.tool.list()).map(one => one.name))
988 const entered = await next({ ...e, context: [...(e.context ?? []), text] })
989
990 if (entered.context?.includes(text) === true) {
991 await markGuided($)
992 }
993
994 return entered
995 })
996
997 // Off: the model is told to leave the Clean View tools alone, not only the checklist section.
998 on('tool.describe', async ($, e, next) => {
999 const described = await next(e)
1000
1001 if (!OWN_TOOLS.has(e.tool) || (await isTracking($))) {
1002 return described
1003 }
1004
1005 return { description: OFF_DESCRIPTION, isDeferred: true }
1006 })
1007
1008 on('turn.start', async ($, e, next) => {
1009 const text = e.text.trim()
1010
1011 if (text === '' || text.startsWith('/')) {
1012 return next(e)
1013 }
1014
1015 const list = await read($, checklist)
1016
1017 if (isRunning(list.phase)) {
1018 await resume($)
1019
1020 return next(e)
1021 }
1022
1023 const started = await startJob($, FALLBACK_NAME)
1024
1025 if (await isTracking($)) {
1026 void nameJob($, text, started.startedAt)
1027 }
1028
1029 return next(e)
1030 })
1031
1032 on('tool.call', async ($, e, next) => {
1033 const tool = String(e.tool)
1034 const input = e as unknown as Record<string, unknown>
1035 const isMain = e.agentId === undefined
1036
1037 if (isMain && !ALWAYS_ALLOWED.has(tool) && (await mustPlanFirst($))) {
1038 return { deny: GATE_MESSAGE }
1039 }
1040
1041 if (OWN_TOOLS.has(tool) && !(await isTracking($))) {
1042 return { result: OFF_REPLY }
1043 }
1044
1045 if (tool === PLAN_TOOL) {
1046 return planSteps($, input)
1047 }
1048
1049 if (tool === PROGRESS_TOOL) {
1050 return reportProgress($, input)
1051 }
1052
1053 if (!isMain) {
1054 return next(e)
1055 }
1056
1057 if (tool === 'AskUserQuestion') {
1058 await setNeedsYou($, HAS_QUESTION)
1059 } else {
1060 await resume($)
1061 }
1062
1063 const ran = await next(e)
1064
1065 await change($, list => (list.phase === 'needsYou' ? { ...list, phase: 'working', needsYouReason: null } : list))
1066
1067 if (ran.deny === undefined && ran.isError !== true) {
1068 if (tool === 'TodoWrite') {
1069 await trackTodos($, input)
1070 } else if (tool === 'TaskCreate') {
1071 await trackTaskCreate($, input, ran.text ?? JSON.stringify(ran.result ?? ''))
1072 } else if (tool === 'TaskUpdate') {
1073 await trackTaskUpdate($, input)
1074 }
1075 }
1076
1077 await trackOutcome($, ran)
1078
1079 return ran
1080 })
1081
1082 on('classic.Notification', async ($, e, next) => {
1083 if (e.notification_type === 'permission_prompt') {
1084 await setNeedsYou($, NEEDS_OK)
1085 } else if (e.notification_type === 'elicitation_dialog') {
1086 await setNeedsYou($, HAS_QUESTION)
1087 }
1088
1089 return next(e)
1090 })
1091
1092 on('classic.StopFailure', async ($, e, next) => {
1093 lastApiError = { kind: e.error, details: e.error_details ?? e.last_assistant_message ?? '' }
1094 await setStuck($, apiReason(lastApiError.kind, lastApiError.details))
1095
1096 return next(e)
1097 })
1098
1099 on('turn.complete', async ($, e, next) => {
1100 if (e.agentId !== undefined) {
1101 return next(e)
1102 }
1103
1104 const list = await read($, checklist)
1105
1106 if (!isRunning(list.phase)) {
1107 return next(e)
1108 }
1109
1110 const now = await $.clock.now()
1111 const apiError = lastApiError
1112 failures = 0
1113 lastApiError = null
1114
1115 if (e.reason === 'error') {
1116 await setStuck($, apiReason(apiError?.kind ?? '', apiError?.details ?? e.answer))
1117 } else if (e.reason === 'refusal') {
1118 await setStuck($, REFUSED)
1119 } else if (e.reason === 'aborted') {
1120 await change($, current => ({ ...current, phase: 'stopped', needsYouReason: null, stuckReason: null, finishedAt: now }))
1121 } else if (list.isPlanned && list.tasks.some(one => one.status !== 'done')) {
1122 await change($, current => ({ ...current, phase: 'needsYou', needsYouReason: WAITING_REPLY, stuckReason: null }))
1123 } else {
1124 await change($, current => ({
1125 ...current,
1126 phase: 'done',
1127 tasks: finishAll(current.tasks),
1128 needsYouReason: null,
1129 stuckReason: null,
1130 finishedAt: now,
1131 }))
1132 }
1133
1134 return next(e)
1135 })
1136
1137 on('ui.render', { component: 'ToolUse' }, async ($, e, next) => {
1138 const { Box } = $.ui.resolve(e)
1139
1140 return (await isHiding($)) ? <Box display="none" /> : next(e)
1141 })
1142
1143 on('ui.render', { component: 'ToolResult' }, async ($, e, next) => {
1144 const { Box } = $.ui.resolve(e)
1145
1146 return (await isHiding($)) ? <Box display="none" /> : next(e)
1147 })
1148
1149 on('ui.render', { component: 'ToolGroup' }, async ($, e, next) => {
1150 const { Box } = $.ui.resolve(e)
1151
1152 return (await isHiding($)) ? <Box display="none" /> : next(e)
1153 })
1154
1155 on('ui.render', { component: 'ToolProgress' }, async ($, e, next) =>
1156 (await isHiding($)) ? next({ ...e, props: { ...e.props, hint: '' } }) : next(e),
1157 )
1158
1159 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
1160 if (e.props.hasSurvey) {
1161 return next(e)
1162 }
1163
1164 // Sent on each draw, so the Toolbox panel has the row again after Toolbox reloads.
1165 const hasToolbox = sendToolboxRow($, await currentMode($))
1166 const { Box } = $.ui.resolve(e)
1167 const band = await drawBand($, e, hasToolbox)
1168 const beneath = await next(e)
1169
1170 if (band === null) {
1171 return beneath
1172 }
1173
1174 return (
1175 <Box flexDirection="column">
1176 {band}
1177 {beneath}
1178 </Box>
1179 )
1180 })
1181}
1182types/index.d.ts 39 lines1/** `on` hides details, `both` shows details and the checklist, `off` shows details only. */
2export type CleanViewMode = 'on' | 'both' | 'off'
3
4export type CleanViewTaskStatus = 'done' | 'active' | 'upcoming'
5
6export type CleanViewTask = {
7 id: string
8 name: string
9 status: CleanViewTaskStatus
10 percent: number
11 hasReported: boolean
12}
13
14export type CleanViewPhase = 'idle' | 'working' | 'needsYou' | 'stuck' | 'stopped' | 'done'
15
16export type CleanViewChecklist = {
17 title: string
18 phase: CleanViewPhase
19 tasks: CleanViewTask[]
20 needsYouReason: string | null
21 stuckReason: string | null
22 startedAt: number | null
23 finishedAt: number | null
24 /** True once Claude laid out a real plan (plan_steps or a to-do list). */
25 isPlanned: boolean
26}
27
28declare module 'claude-code' {
29 interface PluginState {
30 'clean-view': {
31 mode: CleanViewMode
32 checklist: CleanViewChecklist
33 tick: number
34 /** True once the model has the guide, in the system prompt or beside a prompt. */
35 isGuided: boolean
36 }
37 }
38}
39