C Claude Code Internals
| EN | ES

系统提示词

系统提示词不是单个静态字符串。它由 src/constants/prompts.ts 中的 getSystemPrompt() 组装,然后由 buildEffectiveSystemPrompt() 处理。它具有最多 6 个层级的优先级层次结构和 7 个独立的内容部分,由缓存边界分隔。

6 优先级层级 7 内容部分 1 缓存边界标记 3 ANT 专属规则

优先级层次结构

层级按优先级顺序评估。更高层级替换其下所有内容。 在主动模式下,代理提示词是追加而不是替换默认值。

1
覆盖提示词 最高
替换整个系统提示词。用于特殊模式,如简单模式(CLAUDE_CODE_SIMPLE 环境变量)。
2
协调器提示词
在多代理 COORDINATOR_MODE 中激活。指导编排者角色。
3
代理提示词
作为子代理运行时:替换默认提示词。在主动模式下:追加在 "# Custom Agent Instructions" 下。
4
自定义提示词
通过 --system-prompt CLI 标志注入。适用于项目特定的覆盖。
5
默认提示词
标准的 Claude Code 系统提示词,包含所有内置行为规则(下面的 7 个部分)。
6
追加提示词
始终添加在最后。携带动态上下文:内存、MCP 工具、语言规则、环境信息。

简单模式

如果设置了 CLAUDE_CODE_SIMPLE 环境变量, 整个系统提示词会折叠为三行:

You are Claude Code, Anthropic's official CLI for Claude.

CWD: /path/to/cwd

Date: 2026-03-31

缓存边界

标记 __SYSTEM_PROMPT_DYNAMIC_BOUNDARY__ 将提示词 分为两半,具有不同的缓存行为。动态部分使用注册表缓存计算值, 直到 /clear/compact。 例外:MCP 指令使用 DANGEROUS_uncachedSystemPromptSection(),因为 MCP 服务器可以在轮次之间连接/断开。

标记之前:静态

可跨组织全局缓存。部分:

  • 1 Intro
  • 2 System
  • 3 Doing Tasks
  • 4 Executing Actions with Care
  • 5 Using Tools
  • 6 Tone and Style
  • 7 Output Efficiency
标记之后:动态

会话特定。不可全局缓存。部分:

  • · Session-specific guidance
  • · Memory (MEMORY.md + memory files)
  • · Environment (cwd, platform, model)
  • · Language preference
  • · Output Style (if configured)
  • · MCP Instructions (always uncached)
  • · Scratchpad directory (if enabled)
  • · Function Result Clearing (if CACHED_MICROCOMPACT)

7 个静态内容部分

这些部分构成默认提示词。标记为 [ANT-ONLY] 的项目仅对内部 Anthropic 用户显示。 标记为 [EXT-ONLY] 的项目仅对外部用户显示。

01

Intro

Defines Claude as an interactive software engineering agent. Includes the security policy (authorized testing / CTF / defensive use OK; destructive / DoS / mass targeting refused) and the no-URL-guessing rule.

02

System

Output rendering rules (GitHub-flavored markdown, monospace). Permission mode mechanics. How to handle denied tool calls, <system-reminder> tags, prompt injection in tool results, hooks, and context compression.

03

Doing Tasks

Engineering task rules: read before proposing changes, prefer editing over creating, no time estimates, diagnose failures before switching tactics, no extras beyond what was asked, no premature abstractions, no backwards-compat hacks. Several rules are ANT-ONLY: spot adjacent bugs, faithful outcome reporting, comment hygiene, verify before claiming done.

04

Executing Actions with Care

Risk classification for actions. Local reversible actions (file edits, tests) are free. Hard-to-reverse or shared-state actions (force push, prod changes, sending messages, uploads to third-party tools) require confirmation. "Measure twice, cut once" principle.

05

Using Tools

Dedicated tool preference (Read over cat, Grep over grep, etc.). TodoWrite for task management. Parallel tool calls where independent.

06

Tone and Style

No emojis. Short and concise responses [EXT-ONLY]. file_path:line_number format for code citations. owner/repo#123 for GitHub references. No colon before tool calls.

07

Output Efficiency

External: lead with action, skip preamble, one sentence over three, no code or tool-call restrictions. ANT (internal): flowing prose, no fragments/em-dashes/symbols, inverted pyramid, explain for the reader's level, never suppress failures or oversell wins.

重要的动态部分

Section When present What it does
会话指导 始终 拒绝工具调用的规则、shell 命令的 ! 前缀、何时使用 Agent vs Glob/Grep、技能调用。
语言 已配置语言 始终用 {LANGUAGE} 响应。技术术语和标识符保持原始形式。
输出样式 已配置样式 内置样式:default(无)、Explanatory(添加 "Insights")、Learning(要求用户编写代码片段)。
长度锚点 仅 ANT 用户 硬限制:工具调用之间 ≤25 词,最终响应 ≤100 词,除非任务需要更多。
Token 预算 TOKEN_BUDGET 标志 显示每轮输出 token 计数。指示 Claude 持续工作直到接近用户指定的 token 目标。
总结工具结果 始终 从工具结果中记录重要信息,因为旧结果会从上下文中清除。

提示词中的关键行为规则

这些规则硬编码在默认提示词中。了解它们有助于你预测和使用 Claude 的默认行为。

Rule What it means for you
无 emoji 除非你明确要求,否则 Claude 不会使用 emoji。
无额外功能 Claude 不会添加超出要求的重构、文档注释或改进。设计上是有意为之。
无过早抽象 "三行相似代码优于过早抽象。" Claude 默认使用简单、直接的代码。
无时间估计 Claude 不会预测任务需要多长时间,无论是对自己还是对你。
使用专用工具 Claude 被明确告知使用 Read 而不是 cat,Grep 而不是 grep 等。Bash 用于没有专用工具的操作。
代码引用 代码引用使用 file_path:line_number 格式以便导航。
GitHub 引用 Issue 和 PR 引用为 owner/repo#123,以便渲染为可点击链接。

影响提示词的功能标志

Flag Effect on system prompt
PROACTIVE / KAIROS 用自主模式提示词替换默认提示词。添加 tick-loop 行为和 SleepTool 要求。
CACHED_MICROCOMPACT 添加"函数结果清除"部分:保留 N 个最近的工具结果,清除更早的结果。
TOKEN_BUDGET 添加 token 预算指令。显示每轮输出计数并强制执行用户指定的最小 token 目标。
CLAUDE.md 被注入到默认提示词层
你的 CLAUDE.md 文件作为默认提示词层的一部分加载,而不是作为单独的机制。 这就是它具有如此强大影响力的原因:它是核心系统提示词的一部分。 在那里放置约定、约束和上下文,Claude 将在每个会话中一致地应用它们。