InkdownInkdown
Start writing

Claude-Code

62 files·4 subfolders

Shared Workspace

Claude-Code
codex

11-system-prompt-constants

Shared from "Claude-Code" on Inkdown

System Prompt & Constants

The "brain" of Claude Code — how it's instructed to think, behave, and use tools.


System Prompt Builder (constants/prompts.ts)

The system prompt is the single most important piece of context sent to the AI model. It's built by getSystemPrompt() and structured in sections.

Dynamic Boundary

The prompt is split at a SYSTEM_PROMPT_DYNAMIC_BOUNDARY marker:

0000_start_here_index_and_recommended_reading_order.md
0100_project_overview_tech_stack_runtime_modes_and_folder_map.md
0200_startup_flow_entry_points_and_cold_start_sequence.md
0300_codebase_modules_layers_state_models_and_schemas.md
0400_system_architecture_and_design_rationale.md
0500_interactive_repl_request_flow_end_to_end.md
0600_headless_sdk_and_print_mode_request_flow_end_to_end.md
0700_mcp_integration_connection_and_tool_call_flow.md
0800_external_services_sdks_storage_and_local_dependencies.md
0900_environment_variables_settings_feature_flags_and_failure_modes.md
1000_non_obvious_patterns_gotchas_and_debugging_traps.md
1100_full_codebase_file_inventory_grouped_by_directory.md
kimi
00-overview.md
01-entrypoints.md
02-state-management.md
03-query-system.md
04-tools-system.md
05-tasks-system.md
06-ui-components.md
07-bridge-remote.md
08-services.md
09-skills-plugins.md
10-commands.md
11-testing-architecture.md
12-permission-system.md
13-build-system.md
14-ink-internals.md
15-git-internals.md
16-context-compaction.md
17-vim-mode.md
18-mailbox-notifications.md
19-session-persistence.md
20-hooks-system.md
21-error-recovery.md
README.md
qwen
00-overview.md
01-entry-points.md
02-query-engine.md
03-tools-and-tasks.md
04-commands-and-skills.md
05-state-management.md
06-ink-rendering.md
07-bridge-remote.md
08-mcp-services.md
09-services-overview.md
10-multi-agent.md
11-system-prompt-constants.md
12-tool-interface.md
13-memory-system.md
14-buddy-companion.md
15-keybindings.md
16-stop-hooks.md
17-vim-mode.md
18-upstreamproxy.md
19-cost-tracking-history.md
20-contexts-styles-onboarding.md
21-hooks.md
22-screens.md
tweets-explain
claude-code-memory-analysis.md
compact
memory-system
agentic-architecture
Plain text
┌─────────────────────────────────────────────┐
│  STATIC (cached across requests)            │
│  - Core instructions                        │
│  - Tool descriptions                        │
│  - Behavioral rules                         │
│  - Output format guidance                   │
├─────────────────────────────────────────────┤
│  SYSTEM_PROMPT_DYNAMIC_BOUNDARY             │
├─────────────────────────────────────────────┤
│  DYNAMIC (per-session, per-request)         │
│  - Environment info                         │
│  - Git status                               │
│  - MCP server info                          │
│  - Token budgets                            │
│  - Active skills                            │
└─────────────────────────────────────────────┘

The static portion is cached by Anthropic's prompt cache (saves ~50-70K tokens of cache creation per request).

Prompt Sections
SectionPurpose
Intro"You are Claude Code, Anthropic's official CLI..."
System RulesCore behavioral constraints (no apologies, be concise, etc.)
Task GuidanceHow to approach coding tasks (understand → plan → execute → verify)
Tool UsageHow and when to use each tool
Tone & StyleCommunication style (professional, direct, no filler)
Output EfficiencyFormat output for terminal (code blocks, diffs, etc.)
Environment InfoOS, shell, project structure, git info
MCP InstructionsHow to use MCP tools and resources
ScratchpadCross-worker file sharing instructions
Token BudgetsBudget constraints and warnings
Brief ModeProactive mode instructions (when enabled)

System Prompt Sections Registry (constants/systemPromptSections.ts)

Memoized/cached section factory:

TypeScript
// Cached section — same content across requests
systemPromptSection(id, content)

// Uncached section — changes per request
DANGEROUS_uncachedSystemPromptSection(id, content)

The cache key is the section ID. When a section's content changes, the cache is invalidated.


Tool Availability Sets (constants/tools.ts)

Defines which tools are available to different agent modes:

TypeScript
// Tools NOT available to any sub-agent
ALL_AGENT_DISALLOWED_TOOLS = [
  'Agent', 'TeamCreate', 'TeamDelete', 'SendMessage', 'SyntheticOutput'
]

// Tools available to async (background) agents
ASYNC_AGENT_ALLOWED_TOOLS = [...]

// Tools available to in-process teammates
IN_PROCESS_TEAMMATE_ALLOWED_TOOLS = [...]

// Tools available in coordinator mode
COORDINATOR_MODE_ALLOWED_TOOLS = [...]

API Beta Headers (constants/betas.ts)

All Anthropic API beta header constants:

TypeScript
// Interleaved thinking (thinking blocks in streaming)
INTERLEAVED_THINKING_BETA = 'interleaved-thinking-2025-11-24'

// 1M token context window
CONTEXT_1M_BETA = 'context-1m-2025-09-22'

// Tool search (defer tools until needed)
TOOL_SEARCH_BETA = 'tool-search-2025-08-15'

// Fast mode (lower latency, lower quality)
FAST_MODE_BETA = 'fast-mode-2025-09-18'

// Advisor model
ADVISOR_BETA = 'advisor-2025-10-22'

API Limits (constants/apiLimits.ts)

Hard limits for API requests:

ResourceLimit
Image (base64)5MB
Image (dimension)2000px
PDF (pages)100 pages
PDF (raw size)20MB
Media per request100 items

Tool Limits (constants/toolLimits.ts)

Output truncation limits for tools:

TypeScript
// Max characters for tool output before truncation
BASH_OUTPUT_MAX_CHARS = 10000
FILE_READ_MAX_CHARS = 20000
// ... etc

Key Constants Files

FilePurpose
constants/prompts.tsSystem prompt builder
constants/systemPromptSections.tsSection registry
constants/toolsLimits.tsTool output limits
constants/tools.tsTool availability sets
constants/betas.tsAPI beta headers
constants/apiLimits.tsAPI resource limits
constants/common.tsDate utilities (memoized for cache stability)
constants/keys.tsKeyboard key mappings
constants/messages.tsUser-facing messages
constants/oauth.tsOAuth configuration
constants/product.tsProduct metadata
constants/figures.tsUnicode figures/symbols
constants/files.tsFile-related constants
constants/github-app.tsGitHub app config
constants/outputStyles.tsOutput style constants
constants/spinnerVerbs.tsSpinner loading messages
constants/system.tsSystem-level constants
constants/turnCompletionVerbs.tsTurn completion indicators
constants/xml.tsXML tag constants
constants/cyberRiskInstruction.tsSecurity instructions
constants/errorIds.tsError ID constants