SLOPSHOPPER

buffer-pane

A pane beside the transcript that holds the next things to tell the agent: write blocks of text while a turn runs, then press [+] to put one block into the…

panecommandstatus
v0.2.0MITupdated 2026-10-22meganemura/buffer-pane/plugin
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · buffer-pane
│ ┃ buffer-pane ✕ › fix the failing auth test and add an audit log call │ ┃ │ ┃ the next thing to tell ⏺ Read(src/auth.ts) │ ┃ ⎿ Read 6 lines │ ┃ [+] replaces the prompt box with the block. ⏺ Update(src/auth.ts) │ ┃ [>] sends the block as a prompt. [x] ⎿ Added 2 lines, removed 1 line │ ┃ deletes the block. [^] [v] move the block. ⏺ Bash(bun test) │ ┃ Enter in the last field adds a block. ⎿ 3 pass, 1 fail │ │ ● Done. refresh now rejects expired claims and logs an audit event. │ │ ✻ Worked for 42s · done 4:20 PM │ │ › /buffer-pane │ ⎿ buffer-pane: buffer-pane shown │ │ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Pane · buffer-pane
the next thing to tell the agent [+] replaces the prompt box with the block. [>] sends the block as a prompt. [x] deletes the block. [^] [v] move the block. Enter in the last field adds a block.
README

buffer-pane

test

A Claude Code plugin (a mod) that opens a pane beside the transcript where you write the next things to tell the agent.

An idea for the next request frequently comes while the agent runs a long turn. Text in the prompt box is one Enter away from the agent: Enter interrupts the turn or puts the text in the queue. The pane is a place to collect that text until you are ready.

  • Write blocks of text in the pane while a turn runs.
  • Press [+] beside a block to put that block into the prompt box, read it, then press Enter yourself.
  • Press [>] to send the block as a prompt in one press.
  • The buffer survives sessions. Each working directory has its own buffer.

Requirements

  • Claude Code 2.1.273 or later. Claude Code 2.1.287 and later load mods by default. On an older version, set CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1.
  • A terminal session, or the Code tab of Claude Code Desktop. Print mode (-p) has no pane.

Install

claude plugin marketplace add meganemura/buffer-pane
claude plugin install buffer-pane@buffer-pane

To develop against a checkout, run the plugin from its working tree:

claude --plugin-dir /path/to/buffer-pane/plugin

Claude Code Desktop

The pane also draws in the Code tab of Claude Code Desktop. A plugin installed at the user scope with the commands above loads there too. /plugin does not run in the desktop app: to install from the app, click + beside the prompt box, then Plugins, then Add marketplace with meganemura/buffer-pane, then Add plugin.

The desktop app takes no --plugin-dir. To develop against a checkout there, set these in the env of ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_PLUGIN_DIRS": "/path/to/buffer-pane/plugin",
    "CLAUDE_CODE_PLUGIN_DIR_WATCH": "1"
  }
}

Use

Type /buffer-pane to show the pane. Type it again to hide the pane.

[+] [>] [x] [^] [v]   rename the flag to --dry-run
[+] [>] [x] [^] [v] ✓ add a test for the empty list
                      the next thing to tell the agent

[+] replaces the prompt box with the block. [>] sends the block as a prompt. [x] deletes the block. [^] [v] move the block.
  • Add a block. Type in the last field and press Enter. The block goes above the field, and the field becomes empty for the next block.
  • Edit a block. Move the focus to the field of the block and type. The pane saves each change.
  • Put a block into the prompt box. Press [+]. The block goes into the prompt box and stays in the pane with a ✓. You can send the block again. An edit to the block removes the ✓.
  • Send a block as a prompt. Press [>]. The block goes to the agent as your next prompt and leaves the pane. During a turn, it waits in the queue until the turn ends.
  • Move a block. Press [^] to move it up one place, [v] to move it down.
  • Delete a block. Press [x]. You can also make the field empty and press Enter.

To press a control, click it, or move the focus to it with the arrow keys and press Enter.

[+] replaces the prompt box

[+] replaces all the text in the prompt box with the block. The function-hooks API can only replace the box, and it cannot read the box, so the plugin cannot warn you about text that is already there. Send a block when the prompt box is empty.

When a dialog is open, the prompt box cannot take the text. The status line then shows a message, and the block gets no ✓.

Blocks

The buffer is one text, and blank lines split it into blocks. In this version, one block is one line. A multi-line editor is the next milestone (decision 0003).

Where the buffer lives

The plugin store of Claude Code holds the buffer under the key buffer:<working directory>. A session in another directory shows another buffer.

Development

Run /plugin-types one time in a new checkout. It writes the type declarations to .claude/types/, which git ignores.

Run the three quality gates before a commit:

claude plugin validate plugin
npx -p typescript tsc -p plugin/hooks
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin test plugin

docs/decisions/ holds the design decisions. AGENTS.md holds the rules for changes to this repository.

Status

Early access. The function-hooks API can change between Claude Code releases without notice.


Japanese

Source 1 files
hooks/mod.ts 405 lines
1// The plugin's one function-hooks module (the validator admits one per plugin). `/buffer-pane`
2// opens a pane beside the transcript that holds text the person writes for later: the next
3// things to tell the agent. The buffer is one text. Blank lines split it into blocks. Each
4// block has a `[+]` that writes the block into the prompt box, a `[>]` that submits the block as
5// a prompt and deletes it, and a `[x]` that deletes it. The
6// buffer lives in the plugin store, one key for each working directory, so it survives sessions
7// and hot reloads.
8//
9// Must NOT know about: what the person does with the prompt box after a fill; what the prompt box holds
10// (the API cannot read it, and `prompt.fill` always replaces it); any other repository's
11// buffer (one key, the current working directory's).
12//
13// It loads only where Claude Code has function hooks enabled. The engine's validator reads
14// this file statically, so every call on `$` is spelled `$.noun.event(...)` and `$` is handed
15// only to the function declarations at the top of the file; the rest of the module holds a
16// `Host`, a bundle of closures built once at `session.start`.
17
18import type { Elements, On, RenderElement } from 'claude-code'
19
20const PANE_ID = 'buffer-pane'
21const PANE_TITLE = 'buffer-pane'
22const COMMAND = 'buffer-pane'
23
24const STORE_KEY_PREFIX = 'buffer:'
25
26const PANE_PADDING_RIGHT = 1
27
28// `✓` is a long-established narrow symbol: it draws in one cell. A symbol that a font draws
29// two cells wide would push the text field out of line with the rows that have no mark.
30const SENT_MARK = '✓'
31const NOT_SENT_MARK = ' '
32
33const FILL_REFUSED_TEXT = 'buffer-pane: the prompt box did not take the block (a dialog is open, or there is no prompt box)'
34// A session whose surface draws its own prompt box (Claude Code Desktop can be one) answers a
35// fill with the refusal `no_composer`. No later press can fill that box, so the status names
36// `[>]`, the other way to send a block.
37const NO_COMPOSER_TEXT = 'buffer-pane: this prompt box does not take text from a plugin. Press [>] to send the block as a prompt.'
38const SUBMIT_REFUSED_TEXT = 'buffer-pane: the prompt was refused: '
39// The surface draws `⏎ <submitLabel>` beside a field while it has the focus, and the field
40// shrinks by that width, so the row moved on each focus change (real-terminal feedback). An
41// empty label is the one value the props offer to give it nothing to draw. What Enter does is
42// in the note at the bottom of the pane instead.
43const SUBMIT_LABEL = ''
44
45const REPLACE_NOTE = '[+] replaces the prompt box with the block. [>] sends the block as a prompt. [x] deletes the block. [^] [v] move the block. Enter in the last field adds a block.'
46
47type Host = {
48  cwd: () => Promise<string>
49  status: (text: string | undefined) => void
50  open: () => Promise<void>
51  close: () => Promise<void>
52  invalidate: () => void
53  log: (text: string) => void
54  register: () => Promise<unknown>
55  // `refusal` is the engine's cause when it refused the fill itself; absent when a hook did.
56  fill: (text: string) => Promise<{ isFilled: boolean; refusal?: string }>
57  submit: (text: string) => Promise<{ drop?: string | undefined }>
58  storeGet: (key: string) => Promise<unknown>
59  storeSet: (key: string, value: unknown) => Promise<void>
60}
61
62// A block holds an id because its position changes when `[x]` deletes a block above it. The
63// id is the element key, so the text field of block 3 does not become the text field of
64// block 2 under the person's cursor.
65export type Block = { id: number; text: string }
66
67// What the pane edits. `sent` holds the text of each block that a `[+]` wrote into the prompt
68// box. A block shows the mark only while its text is in `sent`, so an edit removes the mark
69// with no separate bookkeeping. `draft` is the text in the new-block field before Enter.
70export type Buffer = { blocks: Block[]; sent: string[]; draft: string; nextId: number }
71
72// What the store holds. The buffer is one text with blank lines between blocks, not a list:
73// a later multi-line editor edits the same text, and a person can read the stored value.
74export type Stored = { text: string; sent: string[]; draft: string }
75
76type State = {
77  host: Host | null
78  isOpen: boolean
79  storeKey: string | null
80  buffer: Buffer
81  // Counts Enter presses in the new-block field. The count is part of that field's key, so
82  // each Enter draws a new element. The surface keeps the typed text of an element it has
83  // seen before, and an empty `value` drawn again for the same key might not clear it.
84  draftGeneration: number
85}
86
87// The host is a bundle of closures over `$`, built once at `session.start`, so the rest of
88// this file never holds `$` itself. That is the validator's rule and also the seam a test
89// fakes: every world a test builds stubs these same calls with `on(...)`.
90function hostOf($: any): Host {
91  return {
92    cwd: () => $.session.cwd(),
93    status: (text) => $.ui.status(text),
94    open: () => $.ui.open({ id: PANE_ID, title: PANE_TITLE, focus: true }),
95    close: () => $.ui.close({ id: PANE_ID }),
96    invalidate: () => $.ui.invalidate('ui.render'),
97    log: (text) => $.ui.log(text),
98    register: () => $.command.register({ name: COMMAND, description: 'Show or hide the buffer-pane' }),
99    fill: (text) => $.prompt.fill({ text }),
100    submit: (text) => $.prompt.submit({ text }),
101    storeGet: (key) => $.store.get(key),
102    storeSet: (key, value) => $.store.set(key, value),
103  }
104}
105
106function messageOf(error: unknown): string {
107  return error instanceof Error ? error.message : String(error)
108}
109
110export function storeKeyOf(cwd: string): string {
111  return `${STORE_KEY_PREFIX}${cwd}`
112}
113
114export function emptyBuffer(): Buffer {
115  return { blocks: [], sent: [], draft: '', nextId: 1 }
116}
117
118// A line that holds only spaces also separates blocks: a person cannot see the difference
119// between that line and an empty line.
120export function blockTextsOf(text: string): string[] {
121  return text
122    .split(/\n[ \t]*(?:\n[ \t]*)+/)
123    .map((block) => block.trim())
124    .filter((block) => block !== '')
125}
126
127export function textOfBlocks(blocks: readonly Block[]): string {
128  return blocks
129    .map((block) => block.text.trim())
130    .filter((text) => text !== '')
131    .join('\n\n')
132}
133
134// A mark for a text that is no longer in the buffer is dropped. Without this, a block that
135// the person edits and then edits back shows a mark for a fill of a different text.
136function withSentPruned(buffer: Buffer): Buffer {
137  const texts = new Set(buffer.blocks.map((block) => block.text.trim()))
138  return { ...buffer, sent: buffer.sent.filter((text) => texts.has(text)) }
139}
140
141export function afterSubmitOf(buffer: Buffer, value: string): Buffer {
142  const text = value.trim()
143  if (text === '') return { ...buffer, draft: '' }
144  return { ...buffer, blocks: [...buffer.blocks, { id: buffer.nextId, text }], draft: '', nextId: buffer.nextId + 1 }
145}
146
147export function afterDraftOf(buffer: Buffer, value: string): Buffer {
148  return { ...buffer, draft: value }
149}
150
151export function afterEditOf(buffer: Buffer, id: number, value: string): Buffer {
152  return withSentPruned({ ...buffer, blocks: buffer.blocks.map((block) => (block.id === id ? { ...block, text: value } : block)) })
153}
154
155// Enter in the field of a block that the person emptied deletes the block. An empty block
156// has nothing to send, and the stored text could not hold it.
157export function afterEditSubmitOf(buffer: Buffer, id: number, value: string): Buffer {
158  if (value.trim() === '') return afterRemoveOf(buffer, id)
159  return afterEditOf(buffer, id, value.trim())
160}
161
162// Moves a block one place up (`-1`) or down (`+1`). A block at the end stays where it is.
163// Buttons in place of a drag: a drag needs pointer events, which only a `Client` receives,
164// and keys and pointer events did not reach a `Client` in a repeatable way (docs/decisions/0008).
165export function afterMoveOf(buffer: Buffer, id: number, direction: -1 | 1): Buffer {
166  const index = buffer.blocks.findIndex((block) => block.id === id)
167  const target = index + direction
168  if (index < 0 || target < 0 || target >= buffer.blocks.length) return buffer
169  const blocks = [...buffer.blocks]
170  const [moved] = blocks.splice(index, 1)
171  blocks.splice(target, 0, moved!)
172  return { ...buffer, blocks }
173}
174
175export function afterRemoveOf(buffer: Buffer, id: number): Buffer {
176  return withSentPruned({ ...buffer, blocks: buffer.blocks.filter((block) => block.id !== id) })
177}
178
179// `sent` holds trimmed text, the form the store keeps (`textOfBlocks`). A field holds the text
180// as typed, with a possible space at the end, so each comparison trims first. Without this, a
181// block sent with a space at its end loses its mark on the next load.
182export function afterSentOf(buffer: Buffer, text: string): Buffer {
183  const sent = text.trim()
184  return buffer.sent.includes(sent) ? buffer : { ...buffer, sent: [...buffer.sent, sent] }
185}
186
187export function isSentOf(buffer: Buffer, block: Block): boolean {
188  return buffer.sent.includes(block.text.trim())
189}
190
191export function storedOf(buffer: Buffer): Stored {
192  return { text: textOfBlocks(buffer.blocks), sent: withSentPruned(buffer).sent, draft: buffer.draft }
193}
194
195// What comes out of the store is this file's own past write, not the engine's word. A
196// version with a different shape could have written it, so each field is checked. A value
197// that does not fit reads as an empty buffer, never as an error: the pane must still open.
198export function bufferFromStore(value: unknown): Buffer {
199  if (typeof value !== 'object' || value === null) return emptyBuffer()
200  const text = Reflect.get(value, 'text')
201  const sent = Reflect.get(value, 'sent')
202  const draft = Reflect.get(value, 'draft')
203  if (typeof text !== 'string') return emptyBuffer()
204  const blocks = blockTextsOf(text).map((blockText, index) => ({ id: index + 1, text: blockText }))
205  return withSentPruned({
206    blocks,
207    sent: Array.isArray(sent) ? sent.filter((item): item is string => typeof item === 'string') : [],
208    draft: typeof draft === 'string' ? draft : '',
209    nextId: blocks.length + 1,
210  })
211}
212
213// Reads the buffer of the current working directory. It runs at `session.start` and again
214// each time the pane opens, because the working directory can change during a session.
215// It does not read again for a key that is already loaded: the state is newer than the store
216// while a write is in flight.
217async function load(state: State, host: Host): Promise<void> {
218  const key = storeKeyOf(await host.cwd())
219  if (key === state.storeKey) return
220  state.buffer = bufferFromStore(await host.storeGet(key).catch(() => undefined))
221  state.storeKey = key
222}
223
224// Every change goes through here: state first, then the store, then a redraw. The render
225// hook never writes the store. It fires many times a second.
226function commit(state: State, host: Host, buffer: Buffer): void {
227  state.buffer = buffer
228  if (state.storeKey !== null) {
229    void host.storeSet(state.storeKey, storedOf(buffer)).catch((error: unknown) => {
230      host.log(`buffer-pane: the buffer was not saved: ${messageOf(error)}`)
231    })
232  }
233  host.invalidate()
234}
235
236function blockTextOf(state: State, id: number): string {
237  const block = state.buffer.blocks.find((candidate) => candidate.id === id)
238  return block?.text.trim() ?? ''
239}
240
241// The status line for a fill the prompt box did not take, by the engine's cause.
242export function fillRefusedTextOf(refusal: string | undefined): string {
243  return refusal === 'no_composer' ? NO_COMPOSER_TEXT : FILL_REFUSED_TEXT
244}
245
246// `[+]`: the block goes into the prompt box, and the person presses Enter.
247async function fill(state: State, host: Host, id: number): Promise<void> {
248  const text = blockTextOf(state, id)
249  if (text === '') return
250  const { isFilled, refusal } = await host.fill(text)
251  if (!isFilled) {
252    host.status(fillRefusedTextOf(refusal))
253    return
254  }
255  host.status(undefined)
256  // The block stays in the buffer. The pane is the source of truth: the person can lose the
257  // text in the prompt box with one key, and then sends the same block again.
258  commit(state, host, afterSentOf(state.buffer, text))
259}
260
261// `[>]`: the block goes to the model as a prompt (asked for, beside `[+]`: a block that needs no
262// second look is sent in one press). `$.prompt.submit` runs the prompt when the session is idle,
263// so a press during a turn queues it. The block is deleted once the prompt entered (asked for:
264// a sent request is done, and a block that stays reads as one still to send). A refused prompt
265// leaves the block in place.
266async function submit(state: State, host: Host, id: number): Promise<void> {
267  const text = blockTextOf(state, id)
268  if (text === '') return
269  const result = await host.submit(text)
270  if (result.drop !== undefined) {
271    host.status(`${SUBMIT_REFUSED_TEXT}${result.drop}`)
272    return
273  }
274  host.status(undefined)
275  commit(state, host, afterRemoveOf(state.buffer, id))
276}
277
278// The real element types, so the typecheck refuses a prop the engine would refuse. One
279// unknown prop drops the whole tree with no message. `Text` takes no `key`.
280// The pane draws on the terminal and on Claude Code Desktop, so `Ui` holds only what both
281// tables declare. Other surfaces go to `next(e)`.
282type DrawnSurface = 'terminal' | 'desktop'
283type Ui = Pick<Elements[DrawnSurface], 'Box' | 'Button' | 'Text' | 'Input'>
284
285// No `hotkey` on a Button: a hotkey does not fire in a pane (measured in pull-request-pane,
286// two terminal setups). The arrow keys with Enter, or a click, press a Button. `plain` draws
287// the label alone, and the focus and the pointer still invert it, so the brackets of `[+]` are
288// the only chrome and the gutter keeps a fixed width.
289function blockRowOf(ui: Ui, block: Block, state: State, host: Host): RenderElement {
290  const { Box, Button, Text, Input } = ui
291  const key = `block:${block.id}`
292  return Box({
293    key,
294    flexDirection: 'row',
295    width: '100%',
296    columnGap: 1,
297    children: [
298      Button({ key: `${key}:fill`, label: '[+]', plain: true, onPress: () => void fill(state, host, block.id).catch(() => undefined) }),
299      Button({ key: `${key}:submit`, label: '[>]', plain: true, onPress: () => void submit(state, host, block.id).catch(() => undefined) }),
300      Button({ key: `${key}:remove`, label: '[x]', plain: true, onPress: () => commit(state, host, afterRemoveOf(state.buffer, block.id)) }),
301      // `^` and `v` are ASCII: no font draws them wider than one cell (an arrow glyph can).
302      Button({ key: `${key}:up`, label: '[^]', plain: true, onPress: () => commit(state, host, afterMoveOf(state.buffer, block.id, -1)) }),
303      Button({ key: `${key}:down`, label: '[v]', plain: true, onPress: () => commit(state, host, afterMoveOf(state.buffer, block.id, 1)) }),
304      Text({ color: 'green', children: isSentOf(state.buffer, block) ? SENT_MARK : NOT_SENT_MARK }),
305      fieldBoxOf(ui, `${key}:field`, Input({
306        key: `${key}:text`,
307        value: block.text,
308        submitLabel: SUBMIT_LABEL,
309        onInput: (value) => commit(state, host, afterEditOf(state.buffer, block.id, value)),
310        onSubmit: (value) => commit(state, host, afterEditSubmitOf(state.buffer, block.id, value)),
311      })),
312    ],
313  })
314}
315
316// A field on its own draws as wide as its text (real-terminal feedback: the new-block field was
317// too narrow to write in). `InputProps` has no width, so the Box around it takes the rest of
318// the row and the field fills the Box.
319function fieldBoxOf(ui: Ui, key: string, field: RenderElement): RenderElement {
320  return ui.Box({ key, flexGrow: 1, width: '100%', children: [field] })
321}
322
323function draftRowOf(ui: Ui, state: State, host: Host): RenderElement {
324  const { Box, Input } = ui
325  return Box({
326    key: 'draft',
327    flexDirection: 'row',
328    width: '100%',
329    // Lines the field up with the block fields: five 3-cell buttons, the mark, six gaps.
330    paddingLeft: 22,
331    children: [
332      fieldBoxOf(ui, 'draft:field', Input({
333        key: `draft:${state.draftGeneration}`,
334        value: state.buffer.draft,
335        placeholder: 'the next thing to tell the agent',
336        submitLabel: SUBMIT_LABEL,
337        autoFocus: true,
338        onInput: (value) => commit(state, host, afterDraftOf(state.buffer, value)),
339        onSubmit: (value) => {
340          state.draftGeneration += 1
341          commit(state, host, afterSubmitOf(state.buffer, value))
342        },
343      })),
344    ],
345  })
346}
347
348function paneOf(ui: Ui, state: State, host: Host): RenderElement {
349  const { Box, Text } = ui
350  return Box({
351    key: 'buffer-pane',
352    flexDirection: 'column',
353    paddingTop: 1,
354    paddingRight: PANE_PADDING_RIGHT,
355    children: [
356      Box({ flexDirection: 'column', children: [...state.buffer.blocks.map((block) => blockRowOf(ui, block, state, host)), draftRowOf(ui, state, host)] }),
357      Box({ flexDirection: 'column', marginTop: 1, children: [Text({ dimColor: true, children: REPLACE_NOTE })] }),
358    ],
359  })
360}
361
362export function register(on: On) {
363  const state: State = { host: null, isOpen: false, storeKey: null, buffer: emptyBuffer(), draftGeneration: 0 }
364
365  on('session.start', async ($, e, next) => {
366    state.host = hostOf($)
367    await state.host.register().catch((error: unknown) => {
368      state.host?.log(`buffer-pane: /${COMMAND} is not available: ${messageOf(error)}`)
369    })
370    // A hot reload of this module starts a new session under an open pane. The buffer is
371    // read here so the first redraw after the reload shows it.
372    await load(state, state.host).catch(() => undefined)
373    return next(e)
374  })
375
376  on('command.run', { command: COMMAND }, async ($, e, next) => {
377    const host = state.host
378    if (host === null) return next(e)
379
380    if (state.isOpen) {
381      await host.close()
382      state.isOpen = false
383      return { text: 'buffer-pane hidden' }
384    }
385
386    await load(state, host)
387    await host.open()
388    state.isOpen = true
389    return { text: 'buffer-pane shown' }
390  })
391
392  on('ui.render', { component: 'Pane' }, async ($, e, next) => {
393    if (e.requestId !== PANE_ID || state.host === null) return next(e)
394    if (e.surface !== 'terminal' && e.surface !== 'desktop') return next(e)
395    const { Box, Button, Text, Input } = await $.ui.resolve(e)
396    return paneOf({ Box, Button, Text, Input }, state, state.host)
397  })
398
399  on('ui.close', { id: PANE_ID }, async ($, e, next) => {
400    const result = await next(e)
401    if (result.deny === undefined) state.isOpen = false
402    return result
403  })
404}
405