2026年claude code prompt详解

claude code prompt详解claude 的思考能力虽然不错 但是用起 token 消耗非常快 所以尝试自己做一个代理 抓下请求 看看黑盒情况下到底发了哪些东西 不看不知道 抓包后发现竟然发了将近 9000 行的大 json 下面首先分析下发的内容 然后总结下省 token 的建议 整体 json 结构如下 首先是指定模型 然后是 messages 里的提示词 里面包含了所有 skills 的 description system

大家好,我是讯享网,很高兴认识大家。这里提供最前沿的Ai技术和互联网信息。



claude的思考能力虽然不错,但是用起token消耗非常快,所以尝试自己做一个代理,抓下请求,看看黑盒情况下到底发了哪些东西,不看不知道,抓包后发现竟然发了将近9000行的大json。下面首先分析下发的内容,然后总结下省token的建议。

整体json结构如下,首先是指定模型,然后是messages里的提示词,里面包含了所有skills的description,system 里包含了系统相关的描述。紧接着是tools里面是所有的mcp等工具,然后metada里,用户的ID,最大token数量,是否是流式传输。

 { "model": "claude-xx", "messages": [], "system": [], "tools": [], "metadata": {

GPT plus 代充 只需 145"user_id": "user_9e197bc9a8f0823f64cea967c70df2d2eb08492b8f_account__session_e93a69e9-3d39-4c8f-82c1-dc64d7b288a3" 

}, "max_tokens": 32000, "stream": true }

接着详细看messages的内容

1, 里Skill的名字到对应的说明

2,对话的上下文信息context,里面包含了用户配置的md文件名称。mcp的说明文档,skill 或者插件命令的说明,这部分内容非常长。

3,当前会话的历史命令列表包括role:user的提示词和 role:assistent的返回值

,

GPT plus 代充 只需 145 { 

"type": "text", "text": " As you answer the user‘s questions, you can use the following context:

claudeMd

Codebase and user instructions are shown below. Be sure to adhere to these instructions. IMPORTANT: These instructions OVERRIDE any default behavior and you MUST follow them exactly as written.

===================================================

SuperClaude Framework Components

===================================================

Core Framework

@BUSINESS_PANEL_EXAMPLES.md @BUSINESS_SYMBOLS.md @FLAGS.md @PRINCIPLES.md @RULES.md

Behavioral Modes

@MODE_Brainstorming.md @MODE_Business_Panel.md @MODE_Introspection.md @MODE_Orchestration.md @MODE_Task_Management.md @MODE_Token_Efficiency.md

MCP Documentation

@MCP_Context7.md @MCP_Magic.md @MCP_Morphllm.md @MCP_Playwright.md @MCP_Sequential.md @MCP_Serena.md

currentDate

Today’s date is 2026-03-06.

 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. 

"

GPT plus 代充 只需 145 }, { 

"type": "text", "text": " /fast

 
  
    
    
      fast 
     
  
    
    " }, { 

"type": "text", "text": " Fast mode OFF "

GPT plus 代充 只需 145 }, { 

"type": "text", "text": " Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to. "

 }, { 

"type": "text", "text": " /model

GPT plus 代充 只需 145 
  
    
    
      model 
     
  
    
    " }, { 

"type": "text", "text": " Set model to claude-3-7-sonnet-thinking "

 }, { 

"type": "text", "text": "1+1"

GPT plus 代充 只需 145 }, { 

"type": "text", "text": "test"

 } ] }, { 

"role": "assistant", "content": [

GPT plus 代充 只需 145 { 

"type": "text", "text": "(no content)", "citations": []

 } ] }, { 

"role": "user", "content": [

GPT plus 代充 只需 145 { 

"type": "text", "text": "test"

 }, { 

"type": "text", "text": "test"

GPT plus 代充 只需 145 }, { 

"type": "text", "text": "[Request interrupted by user]"

 }, { 

"type": "text", "text": "1+1", "cache_control": { "type": "ephemeral"

GPT plus 代充 只需 145 } } ] } 

],

 {

GPT plus 代充 只需 145 "role": "assistant", "content": [ { "type": "text", "text": "(no content)", "citations": [] } ] },

system里面还包含了cc_version, cache_control控制策略,和系统提示词(超长)。

"system": [ { 

"type": "text", "text": "x-anthropic-billing-header: cc_version=2.1.70.f29; cc_entrypoint=cli; cch=00000;"

GPT plus 代充 只需 145}, { 

"type": "text", "text": "You are Claude Code, Anthropic‘s official CLI for Claude.", "cache_control": { "type": "ephemeral"

 } }, } 

],

tools里有agent、TaskOutput、Bash、EnterWorktree 等内置的功能,以及mcp的信息,并规定了返回值的jsonschema。

GPT plus 代充 只需 145 "tools": [ 
, "block": { "description": "Whether to wait for completion", "default": true, "type": "boolean" }, "timeout": { "description": "Max wait time in ms", "default": 30000, "type": "number", "minimum": 0, "maximum":  } }, "required": [ "task_id", "block", "timeout" ], { "name": "Bash", "description": "Executes a given bash command and returns its output. "additionalProperties": false } },
GPT plus 代充 只需 145, "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false } },

这一部分也巨长,随着mcp安装,快速增长。

综上可以看出,我们的配置文件越多,安装的插件越多,token消耗越多,因为每次请求都需要带上可以使用的skill的说明,mcp的tool说明,还有当前上下文中的配置以及聊天历史。为了减少token用量,我们要随时清理上下文,每个项目的skill要隔离,描述信息尽量简短精炼,不需要的mcp不要安装。长的上下文描述拆分成子任务独立执行。

小讯
上一篇 2026-03-20 08:21
下一篇 2026-03-20 08:19

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/244578.html