Claude Code提示词工程教程(非常详细),从入门到精通,看这一篇就够了!

张开发
2026/4/19 20:24:53 15 分钟阅读

分享文章

Claude Code提示词工程教程(非常详细),从入门到精通,看这一篇就够了!
当 Claude Code 源码意外短暂开源我们得以一窥世界级 AI 编程助手的提示词工程全貌。这不是一个简单的 system prompt而是一套精密的、分层缓存的、条件分支的提示词工程体系。一、为什么提示词工程值得深入研究2026年Claude Code 源码短暂开源事件在 AI 开发者社区引发巨大震动。这个由 世界级的企业打造的 CLI 编程助手其背后不是简单的几行 system prompt而是一个50万行 TypeScript React Ink 代码构建的精密提示词工程体系。项目规模令人震撼维度数据TypeScript 文件1,356 个TSX 组件文件554 个源码总行数~483,000 行工具目录42 个工具提示词文件36 个核心常量文件20 个提示词工程Prompt Engineering的重要性在于——它决定了 AI 产品的行为边界。一个好的提示词系统需要同时做到让模型高效工作减少无效输出提高任务完成率保护用户安全防止执行危险操作优化 API 成本利用缓存减少重复 token适配不同场景内部/外部用户、交互/非交互模式Claude Code 的提示词系统在这四个维度上都做到了极致。接下来让我们一层层拆解。二、整体架构全貌提示词系统的分层设计Claude Code 的提示词系统采用静态/动态分离的分层架构Claude Code 提示词系统架构图┌─────────────────────────────────────────────────┐│ API 请求层 ││ buildSystemPromptBlocks() ││ → TextBlockParam[] with cache_control │├─────────────────────────────────────────────────┤│ 缓存分割层 ││ splitSysPromptPrefix() ││ → global scope (静态) / org scope (动态) │├─────────────────────────────────────────────────┤│ getSystemPrompt() 组装入口 ││ ┌──────────────────┬──────────────────────┐ ││ │ 静态内容区 │ 动态内容区 │ ││ │ (缓存友好) │ (按需计算) │ ││ │ · 身份定义 │ · 会话引导 │ ││ │ · 安全指令 │ · 环境信息 │ ││ │ · 编码风格 │ · MCP 指令 │ ││ │ · 操作谨慎性 │ · 语言偏好 │ ││ │ · 工具优先级 │ · 技能列表 │ ││ │ · 风格指南 │ · Token 预算 │ ││ │ · 输出效率 │ · 输出样式 │ ││ ├──────────────────┴──────────────────────┤ ││ │ SYSTEM_PROMPT_DYNAMIC_BOUNDARY │ ││ │ (缓存边界标记) │ ││ └──────────────────────────────────────────┘ │├─────────────────────────────────────────────────┤│ systemPromptSections 缓存框架 ││ · systemPromptSection() - 静态会话内缓存 ││ · DANGEROUS_uncachedSystemPromptSection() - ││ 每轮重算会破坏缓存 │└─────────────────────────────────────────────────┘这个架构的核心思想是把所有不变的提示词放在前面利用 API 的 prompt caching 机制让它们在多次请求间被复用把每轮可能变化的内容放在后面避免变化时破坏整个缓存。缓存框架的实现在src/constants/systemPromptSections.ts中定义了两种提示词段落// 静态段落计算一次缓存到 /clear 或 /compactexport function systemPromptSection( name: string, compute: ComputeFn,): SystemPromptSection { return { name, compute, cacheBreak: false }}// 动态段落每轮重算变化时会破坏缓存export function DANGEROUS_uncachedSystemPromptSection( name: string, compute: ComputeFn, _reason: string, // 必须说明为什么需要破坏缓存): SystemPromptSection { return { name, compute, cacheBreak: true }}注意DANGEROUS_前缀——这个命名本身就是一种工程规范警告开发者不要轻易使用动态段落因为每次值变化都会导致缓存失效。三、系统提示词组装流程3.1 入口函数getSystemPrompt()src/constants/prompts.ts中的getSystemPrompt()是整个系统提示词的组装入口。它返回一个string[]字符串数组每个元素是一个独立的提示词段落。简化后的核心流程export async function getSystemPrompt( tools: Tools, model: string, additionalWorkingDirectories?: string[], mcpClients?: MCPServerConnection[],): Promisestring[] { // 1. 计算各种运行时信息 const [skillToolCommands, outputStyleConfig, envInfo] await Promise.all([...]) // 2. 构建动态段落列表 const dynamicSections [ systemPromptSection(session_guidance, () getSessionSpecificGuidanceSection(...)), systemPromptSection(memory, () loadMemoryPrompt()), systemPromptSection(env_info_simple, () computeSimpleEnvInfo(...)), systemPromptSection(language, () getLanguageSection(...)), DANGEROUS_uncachedSystemPromptSection(mcp_instructions, () getMcpInstructions(...)), // ... 更多动态段落 ] // 3. 解析所有动态段落 const resolvedDynamicSections await resolveSystemPromptSections(dynamicSections) // 4. 组装最终结果静态在前动态在后 return [ getSimpleIntroSection(outputStyleConfig), // 身份定义 getSimpleSystemSection(), // 系统规则 getSimpleDoingTasksSection(), // 编码风格 getActionsSection(), // 操作谨慎性 getUsingYourToolsSection(enabledTools), // 工具使用 getSimpleToneAndStyleSection(), // 风格指南 getOutputEfficiencySection(), // 输出效率 SYSTEM_PROMPT_DYNAMIC_BOUNDARY, // 缓存边界 ...resolvedDynamicSections, // 动态内容 ]}这个设计的精妙之处在于静态段落是纯函数调用不依赖运行时状态因此它们的输出在不同用户之间是完全一致的这使得 Anthropic 可以利用跨用户的全局缓存cacheScope: global大幅降低 API 成本。3.3 完整请求生命周期系统提示词组装流程当用户输入一条消息时整个提示词的组装和交付流程如下用户输入→ 触发getSystemPrompt()调用静态组装→ 7个静态段落身份、安全、风格等直接返回缓存内容动态计算→ 逐个 resolve 动态段落环境信息、MCP指令等有缓存的用缓存没缓存的重新计算缓存分割→splitSysPromptPrefix()在边界处切分静态部分标global动态部分标org工具注入→ 36个工具的description字段各自携带完整提示词附件注入→ CLAUDE.md、Agent列表、技能发现等通过system-reminder附件注入发送 API→buildSystemPromptBlocks()将所有内容组装为TextBlockParam[]发给 Anthropic API模型响应→ 解析响应执行工具调用循环直到完成3.2 缓存分割splitSysPromptPrefix()当系统提示词被发送到 API 时splitSysPromptPrefix()函数会根据边界标记将其分割为不同的缓存域export function splitSysPromptPrefix( systemPrompt: SystemPrompt,): SystemPromptBlock[] { const boundaryIndex systemPrompt.findIndex( s s SYSTEM_PROMPT_DYNAMIC_BOUNDARY ) // 边界前 → cacheScope: global跨用户共享 // 边界后 → cacheScope: org仅组织内共享}这意味着全球所有 Claude Code 用户共享同一份静态提示词缓存。Anthropic 不需要为每个用户重复发送那几千个 token 的基础指令节省的成本是巨大的。四、核心提示词详解这是本文最重要的部分。我们将逐一拆解 Claude Code 的每一个核心提示词段落给出原文、解释和设计原因。4.1 身份定义Intro Section原文摘录You are Claude Code, Anthropics official CLI for Claude. You are an interactive agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.设计解析这个身份定义非常简洁只做了三件事命名告诉模型你是 Claude Code定位明确是Anthropic 官方 CLI任务域限定在软件工程任务为什么不写得更详细因为身份定义在静态缓存区越简洁越好——冗余信息会浪费缓存空间而具体行为指令放在后面的专门段落中。值得注意的是这个前缀有三种变体根据使用场景自动切换const DEFAULT_PREFIX You are Claude Code, Anthropics official CLI for Claude.const AGENT_SDK_CLAUDE_CODE_PRESET_PREFIX You are Claude Code, Anthropics official CLI for Claude, running within the Claude Agent SDK.const AGENT_SDK_PREFIX You are a Claude agent, built on Anthropics Claude Agent SDK.4.2 安全红线cyberRiskInstruction原文摘录export const CYBER_RISK_INSTRUCTION IMPORTANT: Assist with authorized security testing, defensive security, CTF challenges, and educational contexts. Refuse requests for destructive techniques, DoS attacks, mass targeting, supply chain compromise, or detection evasion for malicious purposes. Dual-use security tools (C2 frameworks, credential testing, exploit development) require clear authorization context: pentesting engagements, CTF competitions, security research, or defensive use cases.设计解析这段安全指令由 Anthropic 的Safeguards 团队David Forsythe, Kyla Guru专门维护文件头注释明确写着IMPORTANT: DO NOT MODIFY THIS INSTRUCTION WITHOUT SAFEGUARDS TEAM REVIEW它的设计哲学是精细化安全边界明确允许渗透测试、CTF、安全研究、防御性安全明确拒绝DoS 攻击、大规模攻击、供应链攻击、检测规避有条件允许双用途工具C2 框架、漏洞利用开发需要明确的授权上下文这种三层分级的安全策略远比简单的不帮助黑客攻击要精妙——它既保护了安全又没有过度限制合法用途。4.3 Doing Tasks 节——编码风格指导这是整个系统提示词中最长的段落之一包含大量编码哲学指导。关键原文摘录# Doing tasks - The user will primarily request you to perform software engineering tasks. - You are highly capable and often allow users to complete ambitious tasks that would otherwise be too complex or take too long. - In general, do not propose changes to code you havent read. - Do not create files unless theyre absolutely necessary. - Be careful not to introduce security vulnerabilities (OWASP top 10).编码风格指导是提示词中最具个性的部分- Dont add features, refactor code, or make improvements beyond what was asked. A bug fix doesnt need surrounding code cleaned up. - Dont add error handling, fallbacks, or validation for scenarios that cant happen. - Dont create helpers, utilities, or abstractions for one-time operations. Three similar lines of code is better than a premature abstraction.设计原因这些指令针对的是大语言模型的常见过度工程倾向——模型倾向于• 添加不必要的注释• 过度抽象• 做顺便改进• 添加不必要的错误处理每一条都是对模型特定不良行为的精准对治。内部用户的额外指令对于 Anthropic 内部用户USER_TYPE ant还有额外的编码哲学- Default to writing no comments. Only add one when the WHY is non-obvious. - Before reporting a task complete, verify it actually works: run the test, execute the script, check the output. - If you notice the users request is based on a misconception, or spot a bug adjacent to what they asked about, say so. Youre a collaborator, not just an executor. - Report outcomes faithfully: if tests fail, say so with the relevant output; if you did not run a verification step, say that rather than implying it succeeded.这些指令反映了 Anthropic 内部的工程文化——诚实胜于讨好验证胜于假设协作者胜于执行者。特别注意这段注释// [MODEL LAUNCH]: Update comment writing for Capybara — remove or soften // once the model stops over-commenting by default这揭示了提示词工程的一个重要事实提示词是对模型缺陷的动态修正。当新模型代号 Capybara不再过度注释时这些指令就可以移除。4.4 Actions 节——操作谨慎性完整原文# Executing actions with careCarefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding.The cost of pausing to confirm is low, while the cost of an unwanted action (lost work, unintended messages sent, deleted branches) can be very high.这段提示词的核心理念是风险分级低风险操作编辑文件、运行测试→ 自由执行高风险操作删除文件、推送代码、发送消息→ 需要确认它还特别列出了四类高风险操作的例子Examples of the kind of risky actions that warrant user confirmation:- Destructive operations: deleting files/branches, dropping database tables- Hard-to-reverse operations: force-pushing, git reset --hard- Actions visible to others: pushing code, creating PRs, sending messages- Uploading content to third-party web tools设计哲学“measure twice, cut once”三思而后行。这个指导方针不是通过硬编码规则实现的而是通过给模型一个判断框架让它自己做决策。4.5 Using Tools 节——工具优先级关键原文# Using your tools - Do NOT use the Bash tool to run commands when a relevant dedicated tool is provided: - To read files use Read instead of cat, head, tail, or sed - To edit files use Edit instead of sed or awk - To create files use Write instead of cat with heredoc - To search for files use Glob instead of find or ls - To search the content of files, use Grep instead of grep or rg - Break down and manage your work with the TodoWrite tool. - You can call multiple tools in a single response. If there are no dependencies between them, make all independent tool calls in parallel.设计原因为什么不直接让模型用 Bash因为专用工具提供了更好的用户体验可审计性专用工具的调用有结构化记录用户更容易审查权限控制专用工具可以有更精细的权限模型性能优化专用工具可以优化输出格式如去重、限制行数并行调用的指令也很重要——它告诉模型别傻等能并行的就并行这对于提升效率至关重要。4.6 Tone Style 节原文# Tone and style - Only use emojis if the user explicitly requests it. - Your responses should be short and concise. (外部用户) - When referencing specific functions or pieces of code include the pattern file_path:line_number. - When referencing GitHub issues or pull requests, use the owner/repo#123 format. - Do not use a colon before tool calls.设计原因这些看似简单的指令每一个都解决了实际的用户体验问题•禁止 emoji防止模型变成表情包机器人•file_path:line_number 格式使引用可点击跳转•owner/repo#123 格式使 GitHub 链接可渲染•禁止冒号因为工具调用结果可能不在输出中显示冒号后面没有内容会显得奇怪4.7 输出效率节Claude Code 对内部用户和外部用户有不同的输出效率指导这是一个非常好的提示词 A/B 测试案例。外部用户版本简洁版# Output efficiencyIMPORTANT: Go straight to the point. Try the simplest approach first without going in circles. Do not overdo it. Be extra concise.Keep your text output brief and direct. Lead with the answer or action, not the reasoning. Skip filler words, preamble, and unnecessary transitions.If you can say it in one sentence, dont use three.内部用户版本详细版# Communicating with the userWhen sending user-facing text, youre writing for a person, not logging to a console. Assume users cant see most tool calls or thinking - only your text output.Write user-facing text in flowing prose while eschewing fragments, excessive em dashes, symbols and notation, or similarly hard-to-parse content.Whats most important is the reader understanding your output without mental overhead or follow-ups, not how terse you are.设计洞察外部用户的版本更短、更直接“extra concise”、“one sentence, don’t use three”而内部版本强调的是写作质量——流畅的散文、避免碎片化表达、确保读者理解。这说明 Anthropic 正在内部测试更精细的输出质量指导验证通过后会推送给外部用户。内部版本还有一个细节——数值化的长度锚点systemPromptSection(numeric_length_anchors, () Length limits: keep text between tool calls to ≤25 words. Keep final responses to ≤100 words unless the task requires more detail.)注释解释了原因研究表明数值化长度限制比定性描述“be concise”能减少约 1.2% 的输出 token。4.8 Agent Tool 提示词——Fork vs SubAgentAgent 工具是 Claude Code 最复杂的工具之一其提示词有两种模式。传统 SubAgent 模式Use the Agent tool with specialized agents when the task at hand matches the agents description. Subagents are valuable for parallelizing independent queries or for protecting the main context window from excessive results, but they should not be used excessively when not needed.新 Fork 模式Calling Agent without a subagent_type creates a fork, which runs in the background and keeps its tool output out of your context — so you can keep chatting with the user while it works.## When to forkFork yourself (omit subagent_type) when the intermediate tool output isnt worth keeping in your context. The criterion is qualitative — will I need this output again — not task size.Forks are cheap because they share your prompt cache. Dont set model on a fork — a different model cant reuse the parents cache.Fork 的核心设计理念上下文保护fork 的输出不进入主上下文防止上下文污染缓存共享fork 继承父级上下文共享 prompt cache节省成本并行执行用户可以继续聊天fork 在后台工作还有一段关于不要偷看的有趣指令Dont peek. The tool result includes an output_file path — do not Read or tail it unless the user explicitly asks for a progress check.Dont race. After launching, you know nothing about what the fork found. Never fabricate or predict fork results.这是针对模型的预判倾向——模型倾向于猜测结果而不是等待。这些指令明确告诉模型不知道就说不知道不要编造。4.9 Bash Tool 提示词——Git 安全协议Bash 工具的提示词是最长的工具提示词之一其中 Git 操作部分尤为精细。Git 安全协议原文Git Safety Protocol:- NEVER update the git config- NEVER run destructive git commands (push --force, reset --hard, checkout ., restore ., clean -f, branch -D) unless the user explicitly requests- NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it- NEVER run force push to main/master, warn the user if they request it- CRITICAL: Always create NEW commits rather than amending, unless the user explicitly requests a git amend. When a pre-commit hook fails, the commit did NOT happen — so --amend would modify the PREVIOUS commit- When staging files, prefer adding specific files by name rather than using git add -A or git add .- NEVER commit changes unless the user explicitly asks you to设计原因每条规则背后都有真实的血泪教训•NEVER skip hooks跳过 pre-commit hook 可能导致不符合规范的代码进入仓库•NEVER amend当 pre-commit hook 失败时commit 没有成功此时--amend会修改上一个已经存在的 commit可能丢失工作•git add -A可能意外包含.env、密钥文件等敏感文件•NEVER commit without asking用户可能只是想让模型分析代码而不是立即提交五、缓存优化策略Claude Code 的缓存优化策略是其提示词工程中最精妙的部分。5.1 静态/动态分离┌─────────────────────────────────────────────┐│ 静态区域 (cacheScope: global) ││ 所有用户共享同一份缓存 ││ ││ · 身份定义 (~50 tokens) ││ · 安全指令 (~80 tokens) ││ · 系统规则 (~200 tokens) ││ · 编码风格指导 (~500 tokens) ││ · 操作谨慎性 (~300 tokens) ││ · 工具优先级 (~200 tokens) ││ · 风格指南 (~100 tokens) ││ · 输出效率 (~150 tokens) │├─────────────────────────────────────────────┤│ ≈≈≈≈≈≈≈≈≈≈ 缓存边界 ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈ │├─────────────────────────────────────────────┤│ 动态区域 (cacheScope: org) ││ 每个组织/会话独立缓存 ││ ││ · 环境信息 (操作系统、路径等) ││ · MCP 服务器指令 ││ · 技能列表 ││ · 语言偏好 ││ · 会话特定引导 │└─────────────────────────────────────────────┘5.2 agent_listing_delta工具描述缓存优化这是一个非常聪明的优化。Agent 列表原本嵌入在工具描述中但 MCP 连接变化、插件加载、权限模式切换等都会导致列表变化从而使整个工具 schema 缓存失效。优化方案将 Agent 列表从工具描述中移出通过 system-reminder 附件注入。export function shouldInjectAgentListInMessages(): boolean { // 动态 Agent 列表占 fleet cache_creation tokens 的 ~10.2% // 通过附件注入工具 schema 保持静态不变}这使得工具描述完全静态化不再因为 Agent 列表变化而破坏缓存。5.3 技能列表预算管理技能列表是另一个缓存优化的精彩案例。在src/tools/SkillTool/prompt.ts中// 技能列表只占上下文窗口的 1%export const SKILL_BUDGET_CONTEXT_PERCENT 0.01export const DEFAULT_CHAR_BUDGET 8_000 // 1% of 200k × 4// 每个条目的硬上限export const MAX_LISTING_DESC_CHARS 250当技能总数超过预算时采用优先级截断策略function formatCommandsWithinBudget(commands: Command[], budget: number) { // 1. 尝试完整描述 if (fullTotal budget) return fullDescriptions // 2. 内置技能保留完整描述插件技能截断 const bundledIndices new Set(...) // 内置技能永远不被截断 const maxDescLen Math.floor(availableForDescs / restCommands.length) // 3. 极端情况只显示名称 if (maxDescLen 20) return namesOnly}5.4 MCP 指令的增量更新// 当 MCP 服务器异步连接时每轮重新计算指令会破坏缓存// 优化通过 mcp_instructions_delta 附件注入DANGEROUS_uncachedSystemPromptSection( mcp_instructions, () isMcpInstructionsDeltaEnabled() ? null : getMcpInstructions(...), MCP servers connect/disconnect between turns)当增量更新启用时MCP 指令不再每轮重算而是通过持久化的附件消息传递——这避免了 MCP 服务器连接/断开时破坏整个 prompt cache。六、工具提示词设计36 个工具的提示词模式Claude Code 有 36 个工具提示词文件但它们的提示词设计遵循几个清晰的模式6.1 模式一简洁声明型Glob 和 Grep 等搜索工具采用简洁的声明式提示词// GlobToolexport const DESCRIPTION - Fast file pattern matching tool that works with any codebase size- Supports glob patterns like **/*.js or src/**/*.ts- Returns matching file paths sorted by modification time- When doing open ended search, use the Agent tool instead设计原则简单工具不需要复杂提示词关键是指明什么时候该用和什么时候该用别的。6.2 模式二结构化指令型Bash、PowerShell 等复杂工具采用结构化的分层指令工具简介↓使用说明何时用、何时不该用↓具体指令命令链接、超时、后台执行↓安全协议Git 安全、沙箱规则↓示例6.3 模式三交互指导型工具提示词设计模式TodoWrite、EnterPlanMode 等工具的提示词包含丰富的使用场景指导// TodoWrite 的提示词长达 200 行包含// - 何时使用6 种场景// - 何时不使用4 种场景// - 完整的使用示例4 个正面例子 5 个反面例子// - 任务状态管理规则设计原因任务管理工具是行为引导型工具——它的提示词不仅仅是描述工具功能更重要的是教会模型何时、如何主动使用它。6.4 模式四内部/外部分流型EnterPlanMode 的提示词在内部和外部用户之间有显著差异外部版本倾向于宁多勿少地使用规划模式——只要有一丝不确定就进入规划。内部版本倾向于直接开始——只有在真正模糊的情况下才进入规划// 外部版鼓励多用Prefer using EnterPlanMode for implementation tasks unless theyre simple// 内部版鼓励少用When in doubt, prefer starting work and using AskUserQuestion for specific questions over entering a full planning phase.七、条件分支与 Feature FlagClaude Code 的提示词系统通过多层条件分支实现精细控制。7.1 构建时分支USER_TYPE// USER_TYPE 在构建时通过 --define 注入// 外部构建中所有 ant 分支被 dead-code elimination 删除if (process.env.USER_TYPE ant) { // 内部用户专属逻辑} else { // 外部用户逻辑}这意味着内外版本的二进制文件中包含的提示词是不同的——不是运行时判断而是编译时就分叉了。7.2 运行时 Feature Flagfeature()// 来自 Bun 的 bundle 特性import { feature } from bun:bundle// 编译时特性检查const proactiveModule feature(PROACTIVE) || feature(KAIROS) ? require(../proactive/index.js) : null这些 feature flag 控制着•PROACTIVE/KAIROS自主工作模式•TOKEN_BUDGETToken 预算管理•EXPERIMENTAL_SKILL_SEARCH技能搜索•VERIFICATION_AGENT验证代理•CACHED_MICROCOMPACT缓存微压缩7.3 运行时 A/B 测试GrowthBook// 通过 GrowthBook 进行动态特性开关const getFeatureValue_CACHED_MAY_BE_STALE require(../services/analytics/growthbook.js)// 示例验证代理特性feature(VERIFICATION_AGENT) getFeatureValue_CACHED_MAY_BE_STALE(tengu_hive_evidence, false)这允许 Anthropic在不发版的情况下调整提示词行为——通过 GrowthBook 的 A/B 测试框架可以逐步向不同用户群体推出新的提示词策略。7.4 Undercover 模式当 Anthropic 内部员工使用 Claude Code 贡献开源项目时会自动启用卧底模式Undercover mode — safety utilities for contributing to public/open-source repos.When active, Claude Code:1. Adds safety instructions to commit/PR prompts2. Strips all attribution to avoid leaking internal model codenames3. The model is not told what model it is在 Undercover 模式下系统提示词中所有与模型身份相关的信息都被移除if (process.env.USER_TYPE ant isUndercover()) { // suppress — 不告诉模型它是什么模型 // 不提及 Claude Code、Anthropic、内部代号等}这是安全纵深防御的典型案例——即使模型在对话中生成了内部代号由于 commit/PR 提示词中的安全指令这些信息也不会出现在公开的提交记录中。八、设计哲学总结通过以上分析我们可以总结出 Claude Code 提示词工程的六大设计哲学提示词设计六大哲学1. 缓存至上几乎所有的提示词设计决策都围绕着缓存效率展开• 静态/动态分离• Agent 列表附件化• 技能列表预算控制• MCP 指令增量更新这些优化看起来复杂但每一项都对应着显著的 API 成本节省。Anthropic 的注释中提到了一个具体数字Agent 列表附件化节省了约10.2% 的 fleet cache_creation tokens。2. 精准对治每条提示词指令都是对模型特定不良行为的精准修正模型倾向提示词对治过度注释“Default to writing no comments”过度抽象“Three similar lines is better than a premature abstraction”预判结果“Don’t race. Never fabricate or predict fork results”过度工程“Don’t add features beyond what was asked”不诚实报告“Never claim all tests pass when output shows failures”3. 风险分级不是所有操作都需要同等程度的谨慎。Claude Code 的提示词系统通过定性判断框架而非硬编码规则让模型自己做出风险决策The cost of pausing to confirm is low, while the cost of an unwanted action can be very high.4. 渐进式发布通过USER_TYPE构建时→feature()编译时→GrowthBook运行时的三层特性开关Anthropic 实现了提示词的渐进式发布内部测试 → feature flag 小范围测试 → GrowthBook A/B 测试 → 全量发布每个阶段的反馈数据都会影响下一步决策。5. 注释即文档Claude Code 的提示词代码中充满了珍贵的注释这些注释本身就是一个活的设计文档// [MODEL LAUNCH]: Update comment writing for Capybara — remove or soften // once the model stops over-commenting by default// Dead code elimination: conditional imports for feature-gated modules// WARNING: Do not remove or reorder this marker without updating cache logic// DCE: process.env.USER_TYPE ant is build-time --define. It MUST be// inlined at each callsite (not hoisted to a const) so the bundler can// constant-fold it这些注释告诉我们提示词是活的会随模型能力演进而调整。6. 安全纵深防御安全不是单点措施而是多层防线安全纵深防御六层防线提示词层cyberRiskInstruction 约束安全行为操作层Actions 节要求确认高风险操作Git 层Git Safety Protocol 防止危险 Git 操作沙箱层Sandbox 配置限制文件系统和网络访问隐蔽层Undercover 模式防止内部信息泄露工具层专用工具替代 Bash 提供可审计性九、对提示词工程师的启示Claude Code 的提示词系统为所有 AI 产品开发者提供了宝贵的经验架构比内容更重要单个提示词写得再好如果没有缓存策略和分层架构成本和性能都会成为瓶颈。针对性胜过全面性每条指令应该解决一个具体问题而不是试图用一段话覆盖所有场景。可观测性是关键丰富的注释、命名的段落、显式的缓存边界——这些让提示词系统变得可维护、可调试。提示词是产品的一部分它需要版本管理、A/B 测试、渐进式发布和任何产品功能一样。模型在进化提示词也要进化[MODEL LAUNCH]标注告诉我们每次模型升级都需要重新评估提示词的有效性。学AI大模型的正确顺序千万不要搞错了2026年AI风口已来各行各业的AI渗透肉眼可见超多公司要么转型做AI相关产品要么高薪挖AI技术人才机遇直接摆在眼前有往AI方向发展或者本身有后端编程基础的朋友直接冲AI大模型应用开发转岗超合适就算暂时不打算转岗了解大模型、RAG、Prompt、Agent这些热门概念能上手做简单项目也绝对是求职加分王给大家整理了超全最新的AI大模型应用开发学习清单和资料手把手帮你快速入门学习路线:✅大模型基础认知—大模型核心原理、发展历程、主流模型GPT、文心一言等特点解析✅核心技术模块—RAG检索增强生成、Prompt工程实战、Agent智能体开发逻辑✅开发基础能力—Python进阶、API接口调用、大模型开发框架LangChain等实操✅应用场景开发—智能问答系统、企业知识库、AIGC内容生成工具、行业定制化大模型应用✅项目落地流程—需求拆解、技术选型、模型调优、测试上线、运维迭代✅面试求职冲刺—岗位JD解析、简历AI项目包装、高频面试题汇总、模拟面经以上6大模块看似清晰好上手实则每个部分都有扎实的核心内容需要吃透我把大模型的学习全流程已经整理好了抓住AI时代风口轻松解锁职业新可能希望大家都能把握机遇实现薪资/职业跃迁这份完整版的大模型 AI 学习资料已经上传CSDN朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费】

更多文章