MCPcopy
hub / github.com/claude-code-best/claude-code / runSideQuestion

Function runSideQuestion

src/utils/sideQuestion.ts:53–102  ·  view source on GitHub ↗
({
  question,
  cacheSafeParams,
}: {
  question: string
  cacheSafeParams: CacheSafeParams
})

Source from the content-addressed store, hash-verified

51 * All tools are blocked and we cap at 1 turn.
52 */
53export async function runSideQuestion({
54 question,
55 cacheSafeParams,
56}: {
57 question: string
58 cacheSafeParams: CacheSafeParams
59}): Promise<SideQuestionResult> {
60 // Wrap the question with instructions to answer without tools
61 const wrappedQuestion = `<system-reminder>This is a side question from the user. You must answer this question directly in a single response.
62
63IMPORTANT CONTEXT:
64- You are a separate, lightweight agent spawned to answer this one question
65- The main agent is NOT interrupted - it continues working independently in the background
66- You share the conversation context but are a completely separate instance
67- Do NOT reference being interrupted or what you were "previously doing" - that framing is incorrect
68
69CRITICAL CONSTRAINTS:
70- You have NO tools available - you cannot read files, run commands, search, or take any actions
71- This is a one-off response - there will be no follow-up turns
72- You can ONLY provide information based on what you already know from the conversation context
73- NEVER say things like "Let me try...", "I'll now...", "Let me check...", or promise to take any action
74- If you don't know the answer, say so - do not offer to look it up or investigate
75
76Simply answer the question with the information you have.</system-reminder>
77
78${question}`
79
80 const agentResult = await runForkedAgent({
81 promptMessages: [createUserMessage({ content: wrappedQuestion })],
82 // Do NOT override thinkingConfig — thinking is part of the API cache key,
83 // and diverging from the main thread's config busts the prompt cache.
84 // Adaptive thinking on a quick Q&A has negligible overhead.
85 cacheSafeParams,
86 canUseTool: async () => ({
87 behavior: 'deny' as const,
88 message: 'Side questions cannot use tools',
89 decisionReason: { type: 'other' as const, reason: 'side_question' },
90 }),
91 querySource: 'side_question',
92 forkLabel: 'side_question',
93 maxTurns: 1, // Single turn only - no tool use loops
94 // No future request shares this suffix; skip writing cache entries.
95 skipCacheWrite: true,
96 })
97
98 return {
99 response: extractSideQuestionResponse(agentResult.messages),
100 usage: agentResult.totalUsage,
101 }
102}
103
104/**
105 * Extract a display string from forked agent messages.

Callers 2

fetchResponseFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 3

runForkedAgentFunction · 0.85
createUserMessageFunction · 0.85

Tested by

no test coverage detected