MCPcopy
hub / github.com/codeaashu/claude-code / getPrompt

Function getPrompt

src/tools/AgentTool/prompt.ts:66–287  ·  view source on GitHub ↗
(
  agentDefinitions: AgentDefinition[],
  isCoordinator?: boolean,
  allowedAgentTypes?: string[],
)

Source from the content-addressed store, hash-verified

64}
65
66export async function getPrompt(
67 agentDefinitions: AgentDefinition[],
68 isCoordinator?: boolean,
69 allowedAgentTypes?: string[],
70): Promise<string> {
71 // Filter agents by allowed types when Agent(x,y) restricts which agents can be spawned
72 const effectiveAgents = allowedAgentTypes
73 ? agentDefinitions.filter(a => allowedAgentTypes.includes(a.agentType))
74 : agentDefinitions
75
76 // Fork subagent feature: when enabled, insert the "When to fork" section
77 // (fork semantics, directive-style prompts) and swap in fork-aware examples.
78 const forkEnabled = isForkSubagentEnabled()
79
80 const whenToForkSection = forkEnabled
81 ? `
82
83## When to fork
84
85Fork yourself (omit \`subagent_type\`) when the intermediate tool output isn't worth keeping in your context. The criterion is qualitative \u2014 "will I need this output again" \u2014 not task size.
86- **Research**: fork open-ended questions. If research can be broken into independent questions, launch parallel forks in one message. A fork beats a fresh subagent for this \u2014 it inherits context and shares your cache.
87- **Implementation**: prefer to fork implementation work that requires more than a couple of edits. Do research before jumping to implementation.
88
89Forks are cheap because they share your prompt cache. Don't set \`model\` on a fork \u2014 a different model can't reuse the parent's cache. Pass a short \`name\` (one or two words, lowercase) so the user can see the fork in the teams panel and steer it mid-run.
90
91**Don't peek.** The tool result includes an \`output_file\` path — do not Read or tail it unless the user explicitly asks for a progress check. You get a completion notification; trust it. Reading the transcript mid-flight pulls the fork's tool noise into your context, which defeats the point of forking.
92
93**Don't race.** After launching, you know nothing about what the fork found. Never fabricate or predict fork results in any format — not as prose, summary, or structured output. The notification arrives as a user-role message in a later turn; it is never something you write yourself. If the user asks a follow-up before the notification lands, tell them the fork is still running — give status, not a guess.
94
95**Writing a fork prompt.** Since the fork inherits your context, the prompt is a *directive* — what to do, not what the situation is. Be specific about scope: what's in, what's out, what another agent is handling. Don't re-explain background.
96`
97 : ''
98
99 const writingThePromptSection = `
100
101## Writing the prompt
102
103${forkEnabled ? 'When spawning a fresh agent (with a `subagent_type`), it starts with zero context. ' : ''}Brief the agent like a smart colleague who just walked into the room — it hasn't seen this conversation, doesn't know what you've tried, doesn't understand why this task matters.
104- Explain what you're trying to accomplish and why.
105- Describe what you've already learned or ruled out.
106- Give enough context about the surrounding problem that the agent can make judgment calls rather than just following a narrow instruction.
107- If you need a short response, say so ("report in under 200 words").
108- Lookups: hand over the exact command. Investigations: hand over the question — prescribed steps become dead weight when the premise is wrong.
109
110${forkEnabled ? 'For fresh agents, terse' : 'Terse'} command-style prompts produce shallow, generic work.
111
112**Never delegate understanding.** Don't write "based on your findings, fix the bug" or "based on the research, implement it." Those phrases push synthesis onto the agent instead of doing it yourself. Write prompts that prove you understood: include file paths, line numbers, what specifically to change.
113`
114
115 const forkExamples = `Example usage:
116
117<example>
118user: "What's left on this branch before we can ship?"
119assistant: <thinking>Forking this \u2014 it's a survey question. I want the punch list, not the git output in my context.</thinking>
120${AGENT_TOOL_NAME}({
121 name: "ship-audit",
122 description: "Branch ship-readiness audit",
123 prompt: "Audit what's left before this branch can ship. Check: uncommitted changes, commits ahead of main, whether tests exist, whether the GrowthBook gate is wired up, whether CI-relevant files changed. Report a punch list \u2014 done vs. missing. Under 200 words."

Callers 1

promptFunction · 0.70

Calls 8

isForkSubagentEnabledFunction · 0.85
formatAgentLineFunction · 0.85
hasEmbeddedSearchToolsFunction · 0.85
getSubscriptionTypeFunction · 0.85
isEnvTruthyFunction · 0.85
isInProcessTeammateFunction · 0.85
isTeammateFunction · 0.85

Tested by

no test coverage detected