Skip to content

Prompt, context, and memory

This page maps the main sources that can become model-visible context in the extracted Claude Code runtime.

Source anchors

Semantic aliasSourceApproximate locationString or symbolMeaning
ManagedMemorySchemacli.jsline ~185, byte 0x11e1cbCLAUDE.md-style instructions injected as organization-managed memoryManaged/policy memory schema surface.
MemoryPathResolvercli.jsline ~446, byte 0x304aecCLAUDE.local.md, CLAUDE.mdMemory-file path resolver for local/project/managed scopes.
RuleMemoryLoadercli.jsline ~1231, byte 0x49b032.claude/rules, CLAUDE.local.mdProject/local rule and memory loading path.
SettingsOverlaySchemacli.jsline ~185, byte 0x11b83b.claude/settings.jsonSettings schema mentions project/user overlay behavior.
SystemPromptOverrideFlagcli.jsline ~19525, byte 0xdc0c89--system-prompt <prompt>Root flag replacing the system prompt for a session.
SystemPromptAppendFlagcli.jsline ~19525, byte 0xdc0d5f--append-system-prompt <prompt>Root flag appending to the default system prompt.
DynamicPromptBoundaryFlagcli.jsline ~19525, byte 0xdc0fb6--exclude-dynamic-system-prompt-sectionsMoves per-machine sections out of the system prompt.
AddDirectoryContextFlagcli.jsline ~19525, byte 0xdc1db3--add-dir <directories...>Adds directories to tool/context access.
OutputStyleContextcli.jsline ~185, byte 0x11087doutputStylesPlugin/settings-provided output styles.
SlashCommandContextcli.jsline ~4965, byte 0x924930slashCommandsContext accounting for loaded slash commands.
DynamicPromptBoundarycli.jsline ~185, byte 0x10b67c__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__Sentinel separating stable and dynamic system-prompt sections.
UserPromptExpansionHookcli.jsline ~185, byte 0x10b716UserPromptExpansionHook/event surface for expanding a submitted user prompt.
PromptCacheMetadatacli.jsline ~1161, byte 0x485689cache_controlPrompt-cache metadata stripping/hashing surface.
MemoryRelevancePrefixSkipcli.jsline ~1975, byte 0x50d590skipSystemPromptPrefixMemory relevance calls can intentionally omit the normal system-prompt prefix.
ApiSystemMessageShapecli.jsline ~2013api_system, <system-reminder>Runtime extracts provider-system and reminder-style system messages.
SystemReminderWrappercli.jsline ~5271-5273N2(), kf5(), api_systemHelper cluster that wraps system reminders and constructs API-system blocks.
TeamContextRemindercli.jsline ~5400-5557team, mailbox, side-question system remindersTeam/task context and side questions can be injected as reminder blocks.

Context-source map

flowchart TD
Args[CLI flags] --> Prompt[System prompt inputs]
Settings[settings JSON / managed settings] --> Prompt
ClaudeMd[CLAUDE.md / CLAUDE.local.md / .claude/rules] --> Prompt
Plugins[Plugins] --> OutputStyles[Output styles]
Plugins --> Slash[Slash commands]
Agents[Custom agents] --> Prompt
MCP[MCP prompts/resources/tools] --> Prompt
Prompt --> Request[Model-visible request]

Confirmed context families

FamilyEvidenceRuntime implication
Memory filesCLAUDE.md, CLAUDE.local.md, .claude/rulesProject, local, managed, and rule-file instructions can feed session context.
Managed memoryclaudeMd settings schema textOrg-managed memory can inject CLAUDE.md-style instructions; managed/policy settings are treated specially.
Explicit system prompt--system-prompt, --system-prompt-fileCan replace the session system prompt.
Appended system prompt--append-system-prompt, --append-system-prompt-fileAdds to the default prompt rather than replacing it.
Dynamic prompt boundaries--exclude-dynamic-system-prompt-sectionsSeparates per-machine data such as cwd/env/memory paths/git status from cache-sensitive system-prompt sections.
Additional directories--add-dir, /add-dir stringsAdds tool-access roots and contributes workspace context.
Output stylesoutputStyles schemaPlugins or settings can contribute output-style definitions.
Slash commands and skillsslashCommands, skills, Skill tool constantCommands and skills are context and automation surfaces; they can also trigger tool/agent behavior.
Custom agents--agents <json>Session can receive custom agent definitions with descriptions/prompts/tools.

Prompt/template extraction catalog

Prompt template catalog now enumerates the long prompt/template-like literals extracted from cli.js. It groups matched surfaces into system/context/memory, tool descriptions and guards, slash-command or agent files, task/subagent prompts, MCP/plugin/hook prompts, security/permission prompts, structured-output prompts, and embedded SDK docs/skills.

The catalog records source anchors, byte offsets, hashes, and short previews for every matched candidate. It intentionally distinguishes static extraction from runtime prompt rendering: mode selection, settings, tool availability, MCP/plugin state, agent configuration, and template interpolation still decide which fragments are assembled for a specific session.

Runtime system prompt assembly and dynamic injection

cli.js treats the system prompt as a layered request structure, not a single static string. The relevant runtime distinction is:

LayerSource examplesDynamic?Notes
Base system instructionsBundled prompt literals, default tool-use instructions, default behavior rulesMostly stableCan be replaced by --system-prompt or extended by --append-system-prompt.
User/org memoryCLAUDE.md, CLAUDE.local.md, .claude/rules, managed claudeMd, AutoMemSemi-dynamicLoaded from filesystem/settings and can change by project/session.
Tool and capability instructionsBuilt-in tools, MCP tools/prompts/resources, plugin output styles, custom agents/skillsDynamicDepends on enabled tools, MCP server availability, plugins, agents, and policy.
Runtime reminders<system-reminder>...</system-reminder> blocks, permission/sandbox/tool warnings, rate-limit hints, memory-age hintsDynamicInjected around events rather than baked into the base prompt.
Team/task contextteammate mailbox, task notifications, subagent context, side-question remindersDynamicAppears only when those runtime features are active.
Prompt expansion hooksUserPromptExpansion hooks, slash commands, scheduled promptsDynamicCan transform or add context to submitted user prompts.

The __SYSTEM_PROMPT_DYNAMIC_BOUNDARY__ sentinel and --exclude-dynamic-system-prompt-sections flag show that the runtime explicitly separates stable prompt sections from per-machine/per-session sections. This is important for provider prompt caching: stable sections can be cache-friendly while dynamic sections such as cwd, git state, memory paths, MCP state, and task context may be excluded or appended later.

Provider-facing message shapes

The bundle contains two particularly useful message-shape anchors:

  • api_system: provider-facing system blocks assembled by helper code around line ~5271-5273.
  • <system-reminder>...</system-reminder>: model-visible reminder wrappers for runtime facts and warnings.

These wrappers appear in paths for memory age warnings, tool result reminders, GitHub rate-limit hints, team/mailbox context, side-question handling, and sandbox/permission guidance. They are the main dynamic-injection mechanism visible from static source: the runtime does not need to rewrite the base prompt to tell the model about a new runtime fact; it can add a reminder block or API-system block at the relevant turn.

Dynamic prompt sources

flowchart TD
Base[Base bundled prompt text] --> Stable[Stable system sections]
Flags[--system-prompt / --append-system-prompt] --> Stable
Memory[CLAUDE.md / rules / managed claudeMd / AutoMem] --> Dynamic[Dynamic sections]
Tools[Built-in tools / MCP / plugins / agents / skills] --> Dynamic
Hooks[UserPromptExpansion / hooks] --> Dynamic
Runtime[permissions / sandbox / rate limits / tool results] --> Reminders[system-reminder blocks]
Team[team mailbox / tasks / subagents] --> Reminders
Stable --> Request[Provider request]
Dynamic --> Request
Reminders --> Request

Can every prompt be expanded?

There are two different meanings of “expand every prompt”:

GoalWhat is possibleWhy
Enumerate static prompt-like literals embedded in cli.jsYes, as a static documentation catalog. Prompt template catalog lists 330 prompt-like candidates for this build, with hashes/previews/anchors. The generated prompt-catalog/ JSON artifacts and their helper script are no longer retained.The readable bundle contains string/template literals that can be extracted without executing the runtime.
Produce the exact fully expanded provider prompt for all possible sessionsNo, not statically and not globally.The final request depends on runtime mode, cwd, settings precedence, memory files, MCP/plugin availability, agent definitions, tool visibility, hooks, task/team state, transcripts, permissions, sandbox state, auth/provider, and prompt-cache decisions.
Produce the exact prompt for one concrete sessionIn principle yes, with runtime instrumentation or a captured request for that specific session.The assembler needs concrete runtime state and interpolated values. The current repository documents the static and source-level seams, not live request capture.

So the accurate answer is: all static prompt-like templates can be cataloged; a universal fully expanded runtime prompt cannot be precomputed from cli.js alone.

Concrete provider-request trace boundary

The runtime-prompt gap is now narrowed to one precise task: capture a single provider-facing request after runtime interpolation. Static source reading already identifies the boundary markers (__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__, --exclude-dynamic-system-prompt-sections, api_system, and <system-reminder>), but those markers do not by themselves produce the final request body.

Trace stepWhat must be fixed for the runWhy it matters
Mode and flagsInteractive/headless, --system-prompt, --append-system-prompt, --exclude-dynamic-system-prompt-sections, --add-dir, model/provider flagsThese decide whether base prompt text is replaced, extended, or split into dynamic sections.
Settings and policyUser/project/local/managed settings, enabledPlugins, mcpServers, output styles, hooks, tool allow/deny settingsThese decide available capabilities and policy-injected context.
Filesystem contextcwd, git state, CLAUDE.md, .claude/rules, memory paths, added directoriesThese provide the dynamic sections that cannot be reconstructed from cli.js alone.
Runtime capability stateEnabled built-in tools, MCP tools/prompts/resources, plugin contributions, skills, agents, task stateTool schemas and capability instructions are request-level structures, not only prompt prose.
Transcript/session stateCurrent transcript, compaction state, reminders, sidechain/subagent contextThe same static templates can render differently depending on turn history.
Provider boundaryCaptured message array, api_system blocks, <system-reminder> blocks, tool schema array, cache metadataThis is the first point where the concrete request can be compared against the static catalog.

No captured provider request is committed in this repository yet. A future trace should record the exact invocation, settings files, enabled integrations, sanitized request envelope, and source anchors used to interpret each dynamic section.

Runtime interpretation

cli.js treats context as layered state rather than a single prompt string. Command-line flags can override or append prompt material, while settings, plugin payloads, CLAUDE.md files, rules directories, slash commands, skills, tools, MCP, and agents contribute runtime-visible structures that are later assembled into the request.

The --exclude-dynamic-system-prompt-sections flag is a particularly useful anchor: it shows that the runtime distinguishes stable prompt content from machine-specific sections such as current directory, environment info, memory paths, and git status.

Caveats

  • This page identifies major prompt/context sources, not every prompt template embedded in the bundle.
  • Some hits are schema or accounting surfaces; behavior is confirmed when those strings connect to root flags, settings load, or runtime setup paths.

Created and maintained by Yingting Huang.