Codex-style queued follow-up inputs: the queue key while a turn runs holds the prompt until the turn ends, one per turn; alt+↑ edits the last one; an interrupt…

Codex-style queued follow-up inputs for Claude Code.
While Claude is working, press Tab to queue your next prompt instead of steering the current turn. Queued prompts wait above the input box and go out one per turn, oldest first, after each turn ends.
• Queued follow-up inputs
↳ run the tests you just wrote
↳ then update the README
alt+↑ edit last queued message
claude plugin marketplace add Demo-0416/claude-code-mods
claude plugin install prompt-queue@demo-0416-mods
Then bind the keys (next section). A mod can't change your keybindings itself.
Add these to ~/.claude/keybindings.json, or run /keybindings to open it:
{
"bindings": [
{
"context": "Chat",
"bindings": {
"tab": "chat:queueSubmit"
}
},
{
"context": "Autocomplete",
"bindings": {
"tab": "autocomplete:accept"
}
}
]
}
tab → chat:queueSubmit makes Tab the queue key. Without it the queue key is Claude Code's default, ctrl+x enter.Autocomplete block keeps Tab for accepting a completion while the menu is open.Without this plugin loaded, a Tab bound to chat:queueSubmit behaves like Enter: Claude Code delivers the message into the running turn at the next tool call.
| Key | While Claude works | While idle |
|---|---|---|
| Tab | Queue the prompt for after the turn | Send it now, like Enter |
| Enter | Steer the running turn (Claude Code's default) | Send |
| alt+↑ (Option+↑ on macOS) | Take the last queued prompt back into the input box, replacing the draft | Same, while anything is queued |
| Esc | Interrupt; every queued prompt returns to the input box, oldest first, ahead of the draft |
· tab to queue message while Claude works and the input box has text.@file mentions in a queued prompt aren't expanded. Claude sees the path as text.Prompt dropped by a hook: Queued follow-up input. Claude Code requires a reason when a mod holds back a prompt, and shows it.alt+↑, not Codex's shift+←: Claude Code doesn't hand a mod the input box's cursor keys.app:diffFileListUp, the one that scrolls the /diff panel's file list. While that panel is open, the key scrolls the panel instead.claude --plugin-dir ./plugins/prompt-queue # load from source; saves reload the mod
claude plugin validate ./plugins/prompt-queue
claude plugin test ./plugins/prompt-queue
tsconfig.json extends .claude-plugin/types/tsconfig.json, which Claude Code writes the first time it loads the mod. After that, tsc -p plugins/prompt-queue type-checks the mod.
hooks/register.tsx 375 lines1// Queued follow-up inputs, as Codex's TUI has them (codex-rs/tui,
2// bottom_pane/pending_input_preview.rs and chatwidget/input_restore.rs):
3// the queue key while a turn runs holds the prompt until the turn ends, one
4// prompt per turn, oldest first; the edit key takes the last one back into
5// the composer; an interrupt puts every queued prompt back into the composer.
6import { atom, read, update } from 'claude-code'
7import type { EngineInterface, Register } from 'claude-code'
8
9import type { QueuedPrompt } from '../types'
10
11// Prompts waiting for the running turn to end, oldest first.
12const items = atom({ plugin: 'prompt-queue', key: 'items' } as const, [] as QueuedPrompt[])
13// A main-loop turn is running.
14const isBusy = atom({ plugin: 'prompt-queue', key: 'isBusy' } as const, false)
15// The id of a released prompt whose turn has not started yet, so a turn that
16// ends meanwhile (a steered prompt, a notification) releases nothing more.
17// Cleared when its prompt enters, when any main-loop turn starts, and on a
18// reload, so a release the plugin never saw enter cannot stall the queue.
19const releasing = atom({ plugin: 'prompt-queue', key: 'releasing' } as const, null as string | null)
20
21// Codex's PREVIEW_LINE_LIMIT: wrapped rows shown per queued prompt.
22const PREVIEW_LINE_LIMIT = 3
23const DEFAULT_QUEUE_KEY = 'ctrl+x enter'
24// The prompt box hands a mod no cursor keys, so the edit key is an engine
25// action the band's Button names: its chord presses the Button while the queue
26// shows. This one scrolls /diff's file list and is bound to alt+↑ (Codex's
27// second edit key) by default, so it needs no keybinding of the person's.
28const EDIT_ACTION = 'app:diffFileListUp'
29const EDIT_KEY_LABEL = 'alt+↑'
30// How long to look for a queued prompt the engine puts back in the prompt box:
31// this often, this many times.
32const HAND_BACK_POLL_MS = 25
33const HAND_BACK_POLLS = 20
34// What the prompt box shows in place of pasted text.
35const PASTE_PLACEHOLDER = /\[(?:Pasted text #\d+(?: \+\d+ lines)?|\.\.\.Truncated text #\d+ \+\d+ lines\.\.\.)\]/
36
37const newId = () => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
38
39const ARROWS: Record<string, string> = { left: '←', right: '→', up: '↑', down: '↓' }
40
41// A keybinding as Codex labels it off macOS: `shift+←`, `alt+↑`.
42const keyLabel = (chord: string) =>
43 chord
44 .split(' ')
45 .map(stroke =>
46 stroke
47 .split('+')
48 .map(part => {
49 const name = part.toLowerCase()
50
51 return ['meta', 'opt', 'option'].includes(name) ? 'alt' : (ARROWS[name] ?? name)
52 })
53 .join('+'),
54 )
55 .join(' ')
56
57const isWide = (code: number) =>
58 (code >= 0x1100 && code <= 0x115f) ||
59 (code >= 0x2e80 && code <= 0xa4cf && code !== 0x303f) ||
60 (code >= 0xac00 && code <= 0xd7a3) ||
61 (code >= 0xf900 && code <= 0xfaff) ||
62 (code >= 0xfe30 && code <= 0xfe4f) ||
63 (code >= 0xff00 && code <= 0xff60) ||
64 (code >= 0xffe0 && code <= 0xffe6) ||
65 (code >= 0x1f300 && code <= 0x1f64f) ||
66 (code >= 0x1f900 && code <= 0x1f9ff) ||
67 (code >= 0x20000 && code <= 0x3fffd)
68
69const cellWidth = (char: string) => (isWide(char.codePointAt(0) ?? 0) ? 2 : 1)
70
71// Wraps one prompt into rows of at most `width` cells, breaking after a space
72// where the row has one, so English words stay whole and CJK breaks anywhere.
73function wrapRows(text: string, width: number): string[] {
74 const rows: string[] = []
75 for (const line of text.split('\n')) {
76 let row: string[] = []
77 let used = 0
78 let isContinued = false
79 for (const char of line) {
80 const w = cellWidth(char)
81 if (used + w > width && row.length > 0) {
82 const space = row.lastIndexOf(' ')
83 const carry = space > 0 ? row.splice(space + 1) : []
84 rows.push(row.join('').trimEnd())
85 row = carry
86 used = carry.reduce((sum, c) => sum + cellWidth(c), 0)
87 isContinued = true
88 }
89 if (isContinued && row.length === 0 && char === ' ') {
90 continue
91 }
92 row.push(char)
93 used += w
94 }
95 rows.push(row.join(''))
96 }
97
98 return rows
99}
100
101// The key bound to chat:queueSubmit in the Chat context: the person's last
102// binding of it in keybindings.json, else the default unless they unbound it.
103let queueKey: string | undefined = DEFAULT_QUEUE_KEY
104
105async function readQueueKey($: EngineInterface) {
106 const dir = (await $.env.get('CLAUDE_CONFIG_DIR')) ?? `${await $.env.get('HOME')}/.claude`
107 let file: unknown
108 try {
109 file = JSON.parse(await $.fs.read(`${dir}/keybindings.json`))
110 } catch {
111 return DEFAULT_QUEUE_KEY
112 }
113 let key: string | undefined = DEFAULT_QUEUE_KEY
114 const blocks = (file as { bindings?: unknown }).bindings
115 for (const block of Array.isArray(blocks) ? blocks : []) {
116 const { context, bindings } = block as { context?: unknown; bindings?: unknown }
117 if (context !== 'Chat' || typeof bindings !== 'object' || bindings === null) {
118 continue
119 }
120 for (const [chord, action] of Object.entries(bindings)) {
121 if (action === 'chat:queueSubmit') {
122 key = chord
123 } else if (chord === key && action === null) {
124 key = undefined
125 }
126 }
127 }
128
129 return key
130}
131
132// Sends the oldest queued prompt as a turn of its own once the session is idle.
133async function release($: EngineInterface) {
134 let head: QueuedPrompt | undefined
135 await update($, items, list => {
136 head = list[0]
137
138 return list.slice(1)
139 })
140 if (head === undefined) {
141 return
142 }
143 const sent = head
144 await update($, releasing, () => sent.id)
145 // Not awaited: it resolves when the prompt's turn starts, after this hook.
146 void $.prompt.submit({ text: sent.text, asUser: true })
147}
148
149// Releases the next prompt when nothing runs or is about to. Deferred to a
150// timer, so the submit never comes from within the hook that holds the turn,
151// and this plugin's prompt.submit hook sees it.
152function kick($: EngineInterface) {
153 $.clock.after(0, () => void kickNow($))
154}
155
156async function kickNow($: EngineInterface) {
157 const isIdle =
158 !(await read($, isBusy)) &&
159 (await read($, releasing)) === null &&
160 (await read($, items)).length > 0
161 if (isIdle) {
162 await release($)
163 }
164}
165
166// Takes the newest queued prompt back into the composer, over the draft, as
167// Codex's edit key does.
168async function takeLast($: EngineInterface) {
169 const last = (await read($, items)).at(-1)
170 if (last === undefined) {
171 return
172 }
173 const filled = await $.prompt.fill({ text: last.text, mode: 'replace' })
174 if (filled.isFilled) {
175 await update($, items, list => list.filter(one => one.id !== last.id))
176 }
177}
178
179// Puts every queued prompt back into the composer, oldest first, ahead of the
180// draft, as Codex does on an interrupt.
181async function restore($: EngineInterface) {
182 const list = await read($, items)
183 if (list.length === 0) {
184 return
185 }
186 const draft = (await $.prompt.read()).text
187 const text = [...list.map(one => one.text), ...(draft ? [draft] : [])].join('\n')
188 const filled = await $.prompt.fill({ text, mode: 'replace' })
189 if (filled.isFilled) {
190 const restored = new Set(list.map(one => one.id))
191 await update($, items, all => all.filter(one => !restored.has(one.id)))
192 }
193}
194
195// Whether `typed`, a prompt as the prompt box holds it, is `text`, the prompt
196// as the hook saw it: the box keeps each paste as a placeholder, which stands
197// for any text.
198function isSamePrompt(typed: string, text: string) {
199 const pieces = typed
200 .trim()
201 .split(PASTE_PLACEHOLDER)
202 .map(piece => piece.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
203
204 return new RegExp(`^${pieces.join('[\\s\\S]*')}$`).test(text.trim())
205}
206
207// Claude Code puts a typed prompt a hook dropped back in the prompt box once
208// the hook answers: on a line of its own after the draft, or alone over a
209// blank one. Takes exactly that back out, so the queue key leaves the box as
210// Codex's does; leaves the box alone when it holds anything else.
211function undoHandBack($: EngineInterface, draft: string, text: string) {
212 let polls = 0
213 const check = async () => {
214 const box = (await $.prompt.read().catch(() => undefined))?.text
215 if (box === undefined) {
216 return
217 }
218 if (box === draft) {
219 if (++polls < HAND_BACK_POLLS) {
220 $.clock.after(HAND_BACK_POLL_MS, () => void check())
221 }
222
223 return
224 }
225 const isBlank = draft.trim() === ''
226 const typed = isBlank
227 ? box
228 : box.startsWith(`${draft}\n`)
229 ? box.slice(draft.length + 1)
230 : undefined
231 if (typed !== undefined && isSamePrompt(typed, text)) {
232 await $.prompt.fill({ text: isBlank ? '' : draft, mode: 'replace' }).catch(() => undefined)
233 }
234 }
235 $.clock.after(0, () => void check())
236}
237
238export const register: Register = on => {
239 on('session.start', async ($, e, next) => {
240 queueKey = await readQueueKey($)
241 // A reload: a release in flight may have entered unseen.
242 await update($, releasing, () => null)
243 kick($)
244
245 return next(e)
246 })
247
248 on('prompt.submit', async ($, e, next) => {
249 if (e.origin.kind === 'plugin' && e.origin.name === 'prompt-queue') {
250 // One of ours: its turn has started once `next` resolves.
251 const entered = await next(e)
252 await update($, releasing, () => null)
253 if (entered.drop !== undefined) {
254 kick($)
255 }
256
257 return entered
258 }
259
260 if (!e.wait || e.origin.kind !== 'composer' || e.text.trim() === '') {
261 return next(e)
262 }
263 const hasPending = (await read($, items)).length > 0
264 if (e.turnId === undefined && !hasPending) {
265 // Idle with nothing queued: the queue key sends at once, like Enter.
266 return next(e)
267 }
268 if (e.attachments?.length) {
269 $.ui.toast('Images can’t be queued yet; sent now instead')
270
271 return next(e)
272 }
273 await update($, items, list => [...list, { id: newId(), text: e.text }])
274 if (e.turnId === undefined) {
275 kick($)
276 }
277 // The draft as the drop finds it, for the hand-back to be told from.
278 const draft = (await $.prompt.read().catch(() => undefined))?.text
279 if (draft !== undefined) {
280 undoHandBack($, draft, e.text)
281 }
282
283 return { drop: 'Queued follow-up input' }
284 })
285
286 on('turn.start', async ($, e, next) => {
287 await update($, isBusy, () => true)
288 await update($, releasing, () => null)
289
290 return next(e)
291 })
292
293 on('turn.complete', async ($, e, next) => {
294 const result = await next(e)
295 if (e.agentId !== undefined) {
296 return result
297 }
298 await update($, isBusy, () => false)
299 if (e.reason === 'aborted') {
300 await restore($)
301
302 return result
303 }
304 // An answer, and an error or refusal too, sends the next one.
305 if ((await read($, releasing)) === null) {
306 await release($)
307 }
308
309 return result
310 })
311
312 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
313 const list = await read($, items)
314 if (list.length === 0 || e.props.hasSurvey) {
315 return next(e)
316 }
317 const { Box, Button, Text } = $.ui.resolve(e)
318 const width = Math.max(8, e.props.bodyColumns - 4)
319
320 return (
321 <Box flexDirection="column">
322 <Text>
323 <Text dimColor>• </Text>
324 Queued follow-up inputs
325 </Text>
326 {list.flatMap(one => {
327 const rows = wrapRows(one.text, width)
328 const shown = rows.slice(0, PREVIEW_LINE_LIMIT)
329
330 return [
331 ...shown.map((row, i) => (
332 <Text wrap="truncate-end">
333 <Text dimColor>{i === 0 ? ' ↳ ' : ' '}</Text>
334 <Text dimColor italic>
335 {row}
336 </Text>
337 </Text>
338 )),
339 ...(rows.length > PREVIEW_LINE_LIMIT
340 ? [
341 <Text dimColor italic>
342 {' …'}
343 </Text>,
344 ]
345 : []),
346 ]
347 })}
348 <Box flexDirection="row">
349 <Text>{' '}</Text>
350 <Button
351 key="edit"
352 plain
353 label={EDIT_KEY_LABEL}
354 action={EDIT_ACTION}
355 onPress={() => takeLast($)}
356 />
357 <Text dimColor> edit last queued message</Text>
358 </Box>
359 </Box>
360 )
361 })
362
363 on('ui.render', { component: 'PromptHint' }, ($, e, next) => {
364 if (!e.props.isWorking || !e.props.isDraft || queueKey === undefined) {
365 return next(e)
366 }
367 const key = keyLabel(queueKey)
368 const full = ` · ${key} to queue message`
369 const columns = e.viewport?.columns ?? 80
370 const tail = e.props.hint.length + full.length <= columns ? full : ` · ${key} to queue`
371
372 return next({ ...e, props: { ...e.props, tail } })
373 })
374}
375types/index.d.ts 12 lines1export type QueuedPrompt = { id: string; text: string }
2
3declare module 'claude-code' {
4 interface PluginState {
5 'prompt-queue': {
6 items: QueuedPrompt[]
7 isBusy: boolean
8 releasing: string | null
9 }
10 }
11}
12