返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

Claude Code 系统提示词和 11个内置 Tool拆解

[复制链接]
链载Ai 显示全部楼层 发表于 昨天 12:44 |阅读模式 打印 上一主题 下一主题

Claude Code 是 Anthropic 开发的一个人工智能代码助手工具,它作为命令行界面 (CLI) 工具直接在你的终端中运行。它被设计为帮助开发人员更快速地编写代码、解决问题和理解代码库。

5c14a5b3-788c-435c-a55d-ae85b1a02e5b.png

Claude Code目前是闭源的,而且使用的话需要单独收费另外充值 Token,因为成本太高,而且封号严重,不太建议直接上手。

为了获取它的系统提示词,本次同样使用了Go起了一个转发后台服务,将原本请求Claude的 API代理到了DeepSeek。

请求转发示意图:

a2438844-9087-4808-bf7c-d3ccab7b4ee5.png

下面是对Claude Code系统提示词和11个功能工具tools参数解析。

API 请求内容结构

{
"model":"deepseek-ai/DeepSeek-V3",
"messages":[
{
"content":"YouareClaudeCode,Anthropic'sofficialCLIforClaude...",
"role":"system"
},
{
"content":"1",
"role":"user"
},
{
"content":[
{
"text":"APIError:400OpenAIAPIerror:{\"code\":20015,\"message\":\"max_tokens:Mustbelessthanorequalto4096\",\"data\":null}\n",
"type":"text"
}
],
"role":"assistant"
},
{
"content":"<bash-input>cd/tmp</bash-input>",
"role":"user"
},
{
"content":[
{
"text":"<bash-stdout>Changeddirectoryto\u001b[1m/tmp/\u001b[22m</bash-stdout>",
"type":"text"
}
],
"role":"assistant"
},
{
"content":"ls",
"role":"user"
},
{
"content":[
{
"text":"APIError:400OpenAIAPIerror:{\"code\":20015,\"message\":\"max_tokens:Mustbelessthanorequalto4096\",\"data\":null}\n",
"type":"text"
}
],
"role":"assistant"
},
{
"content":[
{
"text":"ls",
"type":"text"
}
],
"role":"user"
}
],
"max_tokens":16384,
"temperature":1,
"stream":true,
"tools":[
//这里是工具数组,包含各种工具的定义
]
}


工具数组(tools)定义了模型可以使用的11个功能工具。以下是对每个工具的详细解析:

1. dispatch_agent

{
"function":{"description":"Launchanewagentthathasaccesstothefollowingtools:View,GlobTool,GrepTool,LS,ReadNotebook.Whenyouaresearchingforakeywordorfileandarenotconfidentthatyouwillfindtherightmatchinthefirstfewtries,usetheAgenttooltoperformthesearchforyou...","name":"dispatch_agent","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"prompt":{"description":"Thetaskfortheagenttoperform","type":"string"}},"required":["prompt"],"type":"object"}
},
"type":"function"}

功能: 启动新的代理进程,该代理可以访问View、GlobTool、GrepTool、LS和ReadNotebook工具
适用场景: 搜索关键词或文件,特别是在不确定能否快速找到匹配时
参数:

  • prompt(必需): 字符串,描述代理需要执行的任务

使用注意:

  • 可以并行启动多个代理以提高性能
  • 代理完成后会返回一条消息,该消息对用户不可见
  • 代理调用是无状态的,不能发送额外消息
  • 代理不能使用Bash、Replace、Edit、NotebookEditCell等修改文件的工具

2. Bash

{
"function":{"description":"Executesagivenbashcommandinapersistentshellsessionwithoptionaltimeout,ensuringproperhandlingandsecuritymeasures...","name":"Bash","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"command":{"description":"Thecommandtoexecute","type":"string"},"timeout":{"description":"Optionaltimeoutinmilliseconds(max600000)","type":"number"}},"required":["command"],"type":"object"}
},
"type":"function"}

功能: 在持久化的shell会话中执行bash命令
参数:

  • command(必需): 要执行的命令
  • timeout(可选): 超时时间(毫秒),最大600000ms(10分钟)

使用规则:

  • 创建文件前先验证目录路径
  • 禁止使用特定命令(alias, curl, wget等)
  • 避免使用搜索命令如findgrep,使用专用工具代替
  • 避免使用catheadtaills等,使用View和LS工具代替
  • 命令共享同一个shell会话,环境变量等状态会持续
  • 提供详细的git提交和PR创建流程指导

3. BatchTool

{
"function":{"description":"Batchexecutiontoolthatrunsmultipletoolinvocationsinasinglerequest...","name":"BatchTool","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"description":{"description":"Ashort(3-5word)descriptionofthebatchoperation","type":"string"},"invocations":{"description":"Thelistoftoolinvocationstoexecute","items":{"additionalProperties":false,"properties":{"input":{"additionalProperties":{},"description":"Theinputtopasstothetool","type":"object"},"tool_name":{"description":"Thenameofthetooltoinvoke","type":"string"}},"required":["tool_name","input"],"type":"object"},"type":"array"}},"required":["description","invocations"],"type":"object"}
},
"type":"function"}

功能: 批量执行多个工具调用
参数:

  • description(必需): 批处理操作的简短描述(3-5个词)
  • invocations(必需): 要执行的工具调用列表,每个包含:
    • tool_name: 工具名称
    • input: 传递给工具的输入参数

特点:

  • 并行执行工具调用
  • 减少上下文使用和延迟
  • 工具输出不直接显示给用户,需要后续消息展示

4. GlobTool

{
"function":{"description":"Fastfilepatternmatchingtoolthatworkswithanycodebasesize...","name":"GlobTool","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"path":{"description":"Thedirectorytosearchin.Defaultstothecurrentworkingdirectory.","type":"string"},"pattern":{"description":"Theglobpatterntomatchfilesagainst","type":"string"}},"required":["pattern"],"type":"object"}
},
"type":"function"}

功能: 文件名模式匹配
参数:

  • pattern(必需): glob模式,如**/*.jssrc/**/*.ts
  • path(可选): 搜索目录,默认为当前工作目录

特点:

  • 适用于任何规模的代码库
  • 按修改时间排序返回匹配的文件路径
  • 适合按名称模式查找文件

5. GrepTool

{
"function":{"description":"Fastcontentsearchtoolthatworkswithanycodebasesize...","name":"GrepTool","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"include":{"description":"Filepatterntoincludeinthesearch(e.g.\"*.js\",\"*.{ts,tsx}\")","type":"string"},"path":{"description":"Thedirectorytosearchin.Defaultstothecurrentworkingdirectory.","type":"string"},"pattern":{"description":"Theregularexpressionpatterntosearchforinfilecontents","type":"string"}},"required":["pattern"],"type":"object"}
},
"type":"function"}

功能: 文件内容搜索
参数:

  • pattern(必需): 正则表达式,如log.*Errorfunction\s+\w+
  • path(可选): 搜索目录,默认为当前工作目录
  • include(可选): 文件模式筛选,如*.js*.{ts,tsx}

特点:

  • 使用正则表达式搜索文件内容
  • 按修改时间排序返回匹配文件
  • 适合查找包含特定内容的文件

6. LS

{
"function":{"description":"Listsfilesanddirectoriesinagivenpath...","name":"LS","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"ignore":{"description":"Listofglobpatternstoignore","items":{"type":"string"},"type":"array"},"path":{"description":"Theabsolutepathtothedirectorytolist(mustbeabsolute,notrelative)","type":"string"}},"required":["path"],"type":"object"}
},
"type":"function"}

功能: 列出目录中的文件和子目录
参数:

  • path(必需): 要列出内容的目录的绝对路径
  • ignore(可选): 要忽略的glob模式列表

注意:

  • 路径必须是绝对路径,不能是相对路径
  • 如果知道要搜索的目录,通常应优先使用GlobTool和GrepTool

7. View

{
"function":{"description":"Readsafilefromthelocalfilesystem...","name":"View","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"file_path":{"description":"Theabsolutepathtothefiletoread","type":"string"},"limit":{"description":"Thenumberoflinestoread.Onlyprovideifthefileistoolargetoreadatonce.","type":"number"},"offset":{"description":"Thelinenumbertostartreadingfrom.Onlyprovideifthefileistoolargetoreadatonce","type":"number"}},"required":["file_path"],"type":"object"}
},
"type":"function"}

功能: 读取本地文件系统中的文件
参数:

  • file_path(必需): 要读取的文件的绝对路径
  • offset(可选): 起始行号,仅当文件太大无法一次读取时使用
  • limit(可选): 要读取的行数,仅当文件太大无法一次读取时使用

特点:

  • 默认从文件开始读取最多2000行
  • 任何长度超过2000字符的行会被截断
  • 结果使用cat -n格式返回,行号从1开始
  • 对于图像文件,会显示图像
  • Jupyter笔记本(.ipynb)文件应使用ReadNotebook工具

8. Edit

{
"function":{"description":"Thisisatoolforeditingfiles...","name":"Edit","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"file_path":{"description":"Theabsolutepathtothefiletomodify","type":"string"},"new_string":{"description":"Thetexttoreplaceitwith","type":"string"},"old_string":{"description":"Thetexttoreplace","type":"string"}},"required":["file_path","old_string","new_string"],"type":"object"}
},
"type":"function"}

功能: 编辑文件内容
参数:

  • file_path(必需): 要修改的文件的绝对路径
  • old_string(必需): 要替换的文本
  • new_string(必需): 替换的新文本

关键要求:

  • 唯一性: old_string必须唯一标识要修改的实例,包括至少3-5行上下文
  • 单一实例: 工具每次只能替换一个实例
  • 验证: 使用前检查目标文本的实例数量,确保有足够上下文唯一标识
  • 创建新文件时使用空的old_string和完整内容作为new_string

9. Replace

{
"function":{"description":"Writeafiletothelocalfilesystem.Overwritestheexistingfileifthereisone...","name":"Replace","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"content":{"description":"Thecontenttowritetothefile","type":"string"},"file_path":{"description":"Theabsolutepathtothefiletowrite(mustbeabsolute,notrelative)","type":"string"}},"required":["file_path","content"],"type":"object"}
},
"type":"function"}

功能: 创建或覆盖文件
参数:

  • file_path(必需): 要写入的文件的绝对路径
  • content(必需): 要写入文件的内容

使用前:

  • 使用View工具了解文件内容和上下文
  • 创建新文件时验证父目录是否存在


10. ReadNotebook

{
"function":{"description":"ReadsaJupyternotebook(.ipynbfile)andreturnsallofthecellswiththeiroutputs...","name":"ReadNotebook","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"notebook_path":{"description":"TheabsolutepathtotheJupyternotebookfiletoread(mustbeabsolute,notrelative)","type":"string"}},"required":["notebook_path"],"type":"object"}
},
"type":"function"}

功能: 读取Jupyter笔记本文件
参数:

  • notebook_path(必需): Jupyter笔记本文件的绝对路径

说明:

  • 返回笔记本中所有单元格及其输出
  • 路径必须是绝对路径,不能是相对路径

11. NotebookEditCell

{
"function":{"description":"CompletelyreplacesthecontentsofaspecificcellinaJupyternotebook(.ipynbfile)withnewsource...","name":"NotebookEditCell","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"properties":{"cell_number":{"description":"Theindexofthecelltoedit(0-based)","type":"number"},"cell_type":{"description":"Thetypeofthecell(codeormarkdown).Ifnotspecified,itdefaultstothecurrentcelltype.Ifusingedit_mode=insert,thisisrequired.","enum":["code","markdown"],"type":"string"},"edit_mode":{"description":"Thetypeofedittomake(replace,insert,delete).Defaultstoreplace.","type":"string"},"new_source":{"description":"Thenewsourceforthecell","type":"string"},"notebook_path":{"description":"TheabsolutepathtotheJupyternotebookfiletoedit(mustbeabsolute,notrelative)","type":"string"}},"required":["notebook_path","cell_number","new_source"],"type":"object"}
},
"type":"function"}

功能: 编辑Jupyter笔记本中的特定单元格
参数:

  • notebook_path(必需): 笔记本文件的绝对路径
  • cell_number(必需): 要编辑的单元格索引(从0开始)
  • new_source(必需): 单元格的新内容
  • cell_type(可选): 单元格类型(code或markdown),使用edit_mode=insert时必需
  • edit_mode(可选): 编辑类型(replace, insert, delete),默认为replace

模式说明:

  • replace: 替换现有单元格内容
  • insert: 在指定索引处插入新单元格
  • delete: 删除指定索引处的单元格

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ