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

Function buildEffectiveSystemPrompt

src/utils/systemPrompt.ts:41–123  ·  view source on GitHub ↗
({
  mainThreadAgentDefinition,
  toolUseContext,
  customSystemPrompt,
  defaultSystemPrompt,
  appendSystemPrompt,
  overrideSystemPrompt,
}: {
  mainThreadAgentDefinition: AgentDefinition | undefined
  toolUseContext: Pick<ToolUseContext, 'options'>
  customSystemPrompt: string | undefined
  defaultSystemPrompt: string[]
  appendSystemPrompt: string | undefined
  overrideSystemPrompt?: string | null
})

Source from the content-addressed store, hash-verified

39 * Plus appendSystemPrompt is always added at the end if specified (except when override is set).
40 */
41export function buildEffectiveSystemPrompt({
42 mainThreadAgentDefinition,
43 toolUseContext,
44 customSystemPrompt,
45 defaultSystemPrompt,
46 appendSystemPrompt,
47 overrideSystemPrompt,
48}: {
49 mainThreadAgentDefinition: AgentDefinition | undefined
50 toolUseContext: Pick<ToolUseContext, 'options'>
51 customSystemPrompt: string | undefined
52 defaultSystemPrompt: string[]
53 appendSystemPrompt: string | undefined
54 overrideSystemPrompt?: string | null
55}): SystemPrompt {
56 if (overrideSystemPrompt) {
57 return asSystemPrompt([overrideSystemPrompt])
58 }
59 // Coordinator mode: use coordinator prompt instead of default
60 // Use inline env check instead of coordinatorModule to avoid circular
61 // dependency issues during test module loading.
62 if (
63 feature('COORDINATOR_MODE') &&
64 isEnvTruthy(process.env.CLAUDE_CODE_COORDINATOR_MODE) &&
65 !mainThreadAgentDefinition
66 ) {
67 // Lazy require to avoid circular dependency at module load time
68 const { getCoordinatorSystemPrompt } =
69 // eslint-disable-next-line @typescript-eslint/no-require-imports
70 require('../coordinator/coordinatorMode.js') as typeof import('../coordinator/coordinatorMode.js')
71 return asSystemPrompt([
72 getCoordinatorSystemPrompt(),
73 ...(appendSystemPrompt ? [appendSystemPrompt] : []),
74 ])
75 }
76
77 const agentSystemPrompt = mainThreadAgentDefinition
78 ? isBuiltInAgent(mainThreadAgentDefinition)
79 ? mainThreadAgentDefinition.getSystemPrompt({
80 toolUseContext: { options: toolUseContext.options },
81 })
82 : mainThreadAgentDefinition.getSystemPrompt()
83 : undefined
84
85 // Log agent memory loaded event for main loop agents
86 if (mainThreadAgentDefinition?.memory) {
87 logEvent('tengu_agent_memory_loaded', {
88 ...(process.env.USER_TYPE === 'ant' && {
89 agent_type:
90 mainThreadAgentDefinition.agentType as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
91 }),
92 scope:
93 mainThreadAgentDefinition.memory as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
94 source:
95 'main-thread' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
96 })
97 }
98

Callers 7

buildPromptFunction · 0.90
resumeAgentBackgroundFunction · 0.85
callFunction · 0.85
analyzeContextUsageFunction · 0.85
getCacheSharingParamsFunction · 0.85
REPLFunction · 0.85

Calls 6

asSystemPromptFunction · 0.85
isBuiltInAgentFunction · 0.85
logEventFunction · 0.85
isEnvTruthyFunction · 0.70

Tested by 1

buildPromptFunction · 0.72