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

Function prependUserContext

src/utils/api.ts:449–474  ·  view source on GitHub ↗
(
  messages: Message[],
  context: { [k: string]: string },
)

Source from the content-addressed store, hash-verified

447}
448
449export function prependUserContext(
450 messages: Message[],
451 context: { [k: string]: string },
452): Message[] {
453 if (process.env.NODE_ENV === 'test') {
454 return messages
455 }
456
457 if (Object.entries(context).length === 0) {
458 return messages
459 }
460
461 return [
462 createUserMessage({
463 content: `<system-reminder>\nAs you answer the user's questions, you can use the following context:\n${Object.entries(
464 context,
465 )
466 .map(([key, value]) => `# ${key}\n${value}`)
467 .join('\n')}
468
469 IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.\n</system-reminder>\n`,
470 isMeta: true,
471 }),
472 ...messages,
473 ]
474}
475
476/**
477 * Log metrics about context and system prompt size

Callers 2

queryLoopFunction · 0.85
generateAgentFunction · 0.85

Calls 2

createUserMessageFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected