/ask: side questions you can list, reopen, continue, and send to the main conversation

Side questions that don't vanish. Like /btw, but every question becomes a thread you can list, reopen, continue, and hand to the main conversation.
/ask why did we pick SQLite over Postgres here?
Or end any message with /ask when you decide halfway through typing that it is a side question:
why did we pick SQLite over Postgres here /ask
Only the last word counts, so a message that mentions /ask goes to the main chat as written.
The answer opens in a pane. It is asked over the main conversation's context (its prompt cache, no tools) and stays out of the main transcript, so the main task is undisturbed. /ask runs right away, even while Claude is mid-turn.
| Command | Does |
|---|---|
/ask <question> | Ask a side question; starts thread #N |
/ask or /ask list | List this session's threads |
/ask N | Reopen thread #N |
/ask N <follow-up> | Continue thread #N (or type in the pane's field) |
/ask pull N | Send thread #N to Claude with your next message |
/ask drop N | Delete thread #N |
In a thread, Send to main chat does the same as /ask pull N: the whole thread goes to Claude as hidden context with your next message, once. The status line confirms it until you send.
/plugin install ask-threads --marketplace yyosifov/prompt-mods
/btw itself? A mod can't reliably take over a built-in command that runs mid-turn, so /ask is its own command and /btw is left as it is.hooks/register.tsx 225 lines1import type { EngineInterface, ModelCompleteResult, Register } from 'claude-code';
2import { atom, read, update } from 'claude-code';
3
4import type { Exchange } from '../types';
5import { askRequest, parseArgs } from './args';
6import { describeFailure } from './failure';
7import { forkPrompt, pulledContext } from './prompts';
8
9const PANE = 'ask-threads';
10const threads = atom({ plugin: 'ask-threads', key: 'threads' } as const, []);
11const openId = atom({ plugin: 'ask-threads', key: 'openId' } as const, null);
12const busy = atom({ plugin: 'ask-threads', key: 'busy' } as const, []);
13const pulled = atom({ plugin: 'ask-threads', key: 'pulled' } as const, []);
14
15const preview = (text: string, width: number): string => {
16 const line = text.replace(/\s+/g, ' ').trim();
17 return line.length > width ? `${line.slice(0, width - 1)}…` : line;
18};
19
20const show = async ($: EngineInterface, id: number | null): Promise<void> => {
21 await update($, openId, () => id);
22 await $.ui.open({ id: PANE, title: 'ask', focus: true });
23};
24
25// Adds the question to the thread and asks the fork, on a timer of its own so
26// the answer lands even after the dispatch that asked has ended.
27const ask = async ($: EngineInterface, id: number, question: string): Promise<void> => {
28 const earlier = (await read($, threads)).find((t) => t.id === id)?.exchanges ?? [];
29 await update($, threads, (all) => all.map((t) => (t.id === id ? { ...t, exchanges: [...t.exchanges, { question, answer: null }] } : t)));
30 await update($, busy, (ids) => [...ids, id]);
31 $.clock.after(0, () => void answer($, id, question, earlier));
32};
33
34// The main chat has nothing to fork until its first reply, so until then the question goes to the session's model on its own.
35const askModel = async ($: EngineInterface, prompt: string): Promise<ModelCompleteResult> => {
36 const forked = await $.model.fork({ prompt });
37
38 if (forked.isAnswered || forked.reason !== 'nothing-to-fork') {
39 return forked;
40 }
41
42 const model = await $.session.model();
43 const completed = await $.model.complete({ model, prompt, maxTokens: 4096 });
44 return completed;
45};
46
47const answer = async ($: EngineInterface, id: number, question: string, earlier: readonly Exchange[]): Promise<void> => {
48 const reply = await askModel($, forkPrompt(earlier, question));
49 const exchange: Exchange = reply.isAnswered ? { question, answer: reply.text } : { question, answer: null, error: describeFailure(reply) };
50 await update($, threads, (all) => all.map((t) => (t.id === id ? { ...t, exchanges: [...t.exchanges.slice(0, -1), exchange] } : t)));
51 await update($, busy, (ids) => ids.filter((one) => one !== id));
52};
53
54const startThread = async ($: EngineInterface, question: string): Promise<number> => {
55 const list = await read($, threads);
56 const id = list.reduce((max, t) => Math.max(max, t.id), 0) + 1;
57 const startedAt = await $.clock.now();
58 await update($, threads, (all) => [...all, { id, startedAt, exchanges: [] }]);
59 await show($, id);
60 await ask($, id, question);
61 return id;
62};
63
64const pull = async ($: EngineInterface, id: number): Promise<void> => {
65 const ids = await update($, pulled, (all) => (all.includes(id) ? all : [...all, id]));
66 $.ui.status(`ask ${ids.map((one) => `#${one}`).join(' ')} attached to your next message`);
67};
68
69// A pulled thread rides along with the next prompt, unseen in the transcript.
70const takePulled = async ($: EngineInterface): Promise<string[]> => {
71 const ids = await read($, pulled);
72 if (ids.length === 0) {
73 return [];
74 }
75
76 const all = await read($, threads);
77 const context = all.filter((t) => ids.includes(t.id)).map(pulledContext);
78 await update($, pulled, () => []);
79 $.ui.status(undefined);
80 $.ui.log(`▸ ask ${ids.map((id) => `#${id}`).join(' ')} sent along with this message`);
81 return context;
82};
83
84export const register: Register = (on) => {
85 on('session.start', async ($, e, next) => {
86 await $.command.register({
87 name: 'ask',
88 description: 'Side question that stays out of the main conversation; /ask list to reopen one',
89 argumentHint: '<question> | list | N <follow-up> | pull N | drop N',
90 immediate: true,
91 });
92
93 return next(e);
94 });
95
96 on('command.run', { command: 'ask' }, async ($, e) => {
97 const action = parseArgs(e.args);
98 const list = await read($, threads);
99
100 if (action.kind === 'list') {
101 await show($, null);
102 return {};
103 }
104
105 if (action.kind === 'ask') {
106 await startThread($, action.question);
107 return {};
108 }
109
110 const thread = list.find((t) => t.id === action.id);
111 if (thread === undefined) {
112 return { text: `No ask thread #${action.id}. /ask list shows them.` };
113 }
114
115 switch (action.kind) {
116 case 'open':
117 await show($, thread.id);
118 return {};
119 case 'follow':
120 await show($, thread.id);
121 await ask($, thread.id, action.question);
122 return {};
123 case 'pull':
124 await pull($, thread.id);
125 return { text: `ask #${thread.id} goes to Claude with your next message.` };
126 case 'drop':
127 await update($, threads, (all) => all.filter((t) => t.id !== thread.id));
128 await update($, pulled, (ids) => ids.filter((one) => one !== thread.id));
129 await update($, openId, (id) => (id === thread.id ? null : id));
130 return { text: `Dropped ask #${thread.id}.` };
131 }
132 });
133
134 on('prompt.submit', async ($, e, next) => {
135 const isTyped = e.command === undefined && e.isMeta === undefined;
136 const question = isTyped ? askRequest(e.text) : null;
137 if (question !== null) {
138 const id = await startThread($, question);
139 return { drop: `Asked on the side as #${id} · /ask list shows it` };
140 }
141
142 const context = await takePulled($);
143 if (context.length === 0) {
144 return next(e);
145 }
146
147 return next({ ...e, context: [...(e.context ?? []), ...context] });
148 });
149
150 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
151 const elements = $.ui.resolve(e);
152 const { Box, Text, Button, Markdown } = elements;
153 // Mobile draws no field: the follow-up is typed as /ask N there.
154 const Input = 'Input' in elements ? elements.Input : null;
155 const all = await read($, threads);
156 const id = await read($, openId);
157 const waiting = await read($, busy);
158 const attached = await read($, pulled);
159 const thread = all.find((t) => t.id === id);
160 const width = Math.max(20, (e.viewport?.columns ?? 80) - 16);
161
162 if (thread === undefined) {
163 return (
164 <Box flexDirection="column">
165 {all.length === 0 && <Text dimColor>No side questions yet. /ask <question> asks one.</Text>}
166 {all.map((t) => {
167 const question = preview(t.exchanges[0]?.question ?? '', width);
168 const attachedMark = attached.includes(t.id) ? ' ✓ attached' : '';
169
170 return (
171 <Button
172 key={`t${t.id}`}
173 plain
174 label={`#${t.id} ${question} (${t.exchanges.length})${attachedMark}`}
175 onPress={() => update($, openId, () => t.id)}
176 />
177 );
178 })}
179 {all.length > 0 && <Text dimColor>/ask N <follow-up> · /ask pull N · /ask drop N</Text>}
180 </Box>
181 );
182 }
183
184 const isBusy = waiting.includes(thread.id);
185 const isAttached = attached.includes(thread.id);
186
187 return (
188 <Box flexDirection="column">
189 <Text dimColor>ask #{thread.id}</Text>
190 {thread.exchanges.map((x, i) => (
191 <Box key={`x${i}`} flexDirection="column" marginBottom={1}>
192 <Text bold>› {x.question}</Text>
193 {x.answer !== null && <Markdown text={x.answer} />}
194 {x.answer === null && x.error !== undefined && <Text color="red">No answer: {x.error}</Text>}
195 {x.answer === null && x.error === undefined && <Text dimColor>thinking…</Text>}
196 </Box>
197 ))}
198 {!isBusy && Input === null && <Text dimColor>/ask {thread.id} <follow-up> to continue</Text>}
199 {!isBusy && Input !== null && (
200 <Input
201 key="follow"
202 placeholder={`Follow up on #${thread.id}…`}
203 autoFocus
204 onSubmit={(value: string) => {
205 const question = value.trim();
206 if (question !== '') {
207 void ask($, thread.id, question);
208 }
209 }}
210 />
211 )}
212 <Box>
213 <Button key="back" label="← All threads" onPress={() => update($, openId, () => null)} />
214 <Text> </Text>
215 {isAttached ? (
216 <Text color="green">✓ attached to your next message</Text>
217 ) : (
218 <Button key="pull" label="Send to main chat" onPress={() => void pull($, thread.id)} />
219 )}
220 </Box>
221 </Box>
222 );
223 });
224};
225hooks/args.ts 50 lines1export type AskAction =
2 | { kind: 'list' }
3 | { kind: 'ask'; question: string }
4 | { kind: 'open'; id: number }
5 | { kind: 'follow'; id: number; question: string }
6 | { kind: 'pull'; id: number }
7 | { kind: 'drop'; id: number };
8
9export const parseArgs = (args: string): AskAction => {
10 const text = args.trim();
11 if (text === '' || text === 'list' || text === 'ls') {
12 return { kind: 'list' };
13 }
14
15 const verb = /^(pull|drop|rm|open)\s+#?(\d+)$/i.exec(text);
16 if (verb !== null) {
17 const id = Number(verb[2]);
18 const name = (verb[1] ?? '').toLowerCase();
19 if (name === 'pull') {
20 return { kind: 'pull', id };
21 }
22 if (name === 'open') {
23 return { kind: 'open', id };
24 }
25
26 return { kind: 'drop', id };
27 }
28
29 const numbered = /^#?(\d+)(?:\s+([\s\S]+))?$/.exec(text);
30 if (numbered !== null) {
31 const id = Number(numbered[1]);
32 const question = numbered[2]?.trim();
33 return question ? { kind: 'follow', id, question } : { kind: 'open', id };
34 }
35
36 return { kind: 'ask', question: text };
37};
38
39const ASK_SUFFIX = /(^|\s)\/ask\s*$/;
40
41export const askRequest = (text: string): string | null => {
42 const isRequest = ASK_SUFFIX.test(text);
43 if (!isRequest) {
44 return null;
45 }
46
47 const question = text.replace(ASK_SUFFIX, '').trim();
48 return question === '' ? null : question;
49};
50hooks/failure.ts 15 lines1import type { ModelCompleteResult } from 'claude-code';
2
3type Failure = Exclude<ModelCompleteResult, { isAnswered: true }>;
4
5export const describeFailure = (reply: Failure): string => {
6 switch (reply.reason) {
7 case 'api-error':
8 return reply.status === null ? `no response from the API (${reply.error})` : `the API returned ${reply.status} (${reply.error})`;
9 case 'empty-reply':
10 return 'the model replied without any text';
11 case 'aborted':
12 return 'the request was cancelled';
13 }
14};
15hooks/prompts.ts 22 lines1import type { Exchange, Thread } from '../types';
2
3const PREAMBLE =
4 'This is a side question (/ask) asked while the main task continues. ' +
5 'Answer it directly and briefly from what you already know of this conversation; ' +
6 'it does not change the main task.';
7
8const transcript = (exchanges: readonly Exchange[]): string =>
9 exchanges
10 .filter((x) => x.answer !== null)
11 .map((x) => `Q: ${x.question}\nA: ${x.answer}`)
12 .join('\n\n');
13
14export const forkPrompt = (earlier: readonly Exchange[], question: string): string => {
15 const before = transcript(earlier);
16
17 return before === '' ? `${PREAMBLE}\n\n${question}` : `${PREAMBLE}\n\nThe side conversation so far:\n\n${before}\n\nFollow-up: ${question}`;
18};
19
20export const pulledContext = (thread: Thread): string =>
21 `The user pulled in side thread #${thread.id} (a /ask conversation you had alongside this one):\n\n${transcript(thread.exchanges)}`;
22types/index.d.ts 18 lines1export type Exchange = { question: string; answer: string | null; error?: string };
2
3export type Thread = { id: number; startedAt: number; exchanges: Exchange[] };
4
5declare module 'claude-code' {
6 interface PluginState {
7 'ask-threads': {
8 threads: Thread[];
9 // The thread the pane shows; null shows the list.
10 openId: number | null;
11 // Threads whose next answer is on its way.
12 busy: number[];
13 // Threads to hand the model with the next prompt.
14 pulled: number[];
15 };
16 }
17}
18