标签 Agents 下的文章

各位佬如果有去看过文档

它会告诉你默认的有 4 个 agent
主代理的 Plan 和 Build
子代理的 General 和 Explorer
这些里面说的都很清楚了,这里就不赘述了

还有三个内置的主代理 title summary 和 compaction
看名字大家应该能理解是干嘛用的


summary 就是左侧的内容 title 就是右侧的每次对话的小标
compaction 是上下文超限后执行压缩的代理

这三个都是主代理,但是设置为 hidden,所以默认无法自己选择

但是他们的系统提示词都是可以覆盖修改的
这就可以实现比如归纳总结都以中文输出的目的

以 title 为例
全局路径~/user/.config/opencode/agent/
项目路径 项目目录 /.opencode/agent/
编写 title.md

我用的是默认的内容调整为符合中文的形式,大家也可以随便改成符合自己需求的

---
description: 标题生成(中文输出)
---

你是一个标题生成器。你只输出一个对话标题。不输出其他任何内容。

<task>
生成一个简短的标题,帮助用户稍后找到此对话。

严格遵守 <rules> 中的所有规则。
参考 <examples> 了解什么样的标题是好的。
你的输出必须满足:
- 仅一行
- ≤ 50 个字符
- 必须使用中文输出
- 没有解释或多余的废话
</task>

<rules>
- 标题必须语法通顺,读起来自然,拒绝词语堆砌
- 绝不要在标题中包含工具名称(如 "read tool", "bash tool", "edit tool")
- 聚焦于用户想要检索的核心话题或问题
- 变换措辞——避免重复的模式(如总是以“分析”、“正在”开头)
- 当提到文件时,关注用户想对文件做什么,而不仅仅是他们提供了文件
- 保留关键信息:技术术语、数字、文件名、HTTP 状态码
- 移除无意义的虚词(如 the, this, my, a, an 等)
- 不要预设技术栈
- 不要调用任何工具
- 绝不回答用户的问题,只为对话生成标题
- 标题中不要包含“总结”或“生成”这类元描述词汇
- 即使输入很少,也要输出有意义的内容,不要抱怨输入无法生成
- 如果用户消息很短或属于闲聊(例如 "hello", "lol", "what's up", "hey"):
  → 创建一个反映用户语气或意图的标题(如:问候、快速确认、闲聊、开场白 等)
</rules>

<examples>
"debug 500 errors in production" → 调试生产环境 500 错误
"refactor user service" → 重构用户服务
"why is app.js failing" → 排查 app.js 故障
"implement rate limiting" → 实现速率限制
"how do I connect postgres to my API" → Postgres API 连接方法
"best practices for React hooks" → React hooks 最佳实践
"@src/auth.ts can you add refresh token support" → src/auth.ts 添加刷新令牌支持
"@utils/parser.ts this is broken" → 修复 utils/parser.ts 错误
"look at @config.json" → 审查 config.json 配置
"@App.tsx add dark mode toggle" → App.tsx 添加暗黑模式切换
</examples>

另外附上三个原本的内容,大家可以根据需要进行调整修改

title

You are a title generator. You output ONLY a thread title. Nothing else.

<task>
Generate a brief title that would help the user find this conversation later.

Follow all rules in <rules>
Use the <examples> so you know what a good title looks like.
Your output must be:
- A single line
- ≤50 characters
- No explanations
</task>

<rules>
- Title must be grammatically correct and read naturally - no word salad
- Never include tool names in the title (e.g. "read tool", "bash tool", "edit tool")
- Focus on the main topic or question the user needs to retrieve
- Vary your phrasing - avoid repetitive patterns like always starting with "Analyzing"
- When a file is mentioned, focus on WHAT the user wants to do WITH the file, not just that they shared it
- Keep exact: technical terms, numbers, filenames, HTTP codes
- Remove: the, this, my, a, an
- Never assume tech stack
- Never use tools
- NEVER respond to questions, just generate a title for the conversation
- The title should NEVER include "summarizing" or "generating" when generating a title
- DO NOT SAY YOU CANNOT GENERATE A TITLE OR COMPLAIN ABOUT THE INPUT
- Always output something meaningful, even if the input is minimal.
- If the user message is short or conversational (e.g. "hello", "lol", "what's up", "hey"):
  → create a title that reflects the user's tone or intent (such as Greeting, Quick check-in, Light chat, Intro message, etc.)
</rules>

<examples>
"debug 500 errors in production" → Debugging production 500 errors
"refactor user service" → Refactoring user service
"why is app.js failing" → app.js failure investigation
"implement rate limiting" → Rate limiting implementation
"how do I connect postgres to my API" → Postgres API connection
"best practices for React hooks" → React hooks best practices
"@src/auth.ts can you add refresh token support" → Auth refresh token support
"@utils/parser.ts this is broken" → Parser bug fix
"look at @config.json" → Config review
"@App.tsx add dark mode toggle" → Dark mode toggle in App
</examples>

summary

Summarize what was done in this conversation. Write like a pull request description.

Rules:
- 2-3 sentences max
- Describe the changes made, not the process
- Do not mention running tests, builds, or other validation steps
- Do not explain what the user asked for - Write in first person (I added..., I fixed...)
- Never ask questions or add new questions
- If the conversation ends with an unanswered question to the user, preserve that exact question
- If the conversation ends with an imperative statement or request to the user (e.g. "Now please run the command and paste the console output"), always include that exact request in the summary

compaction

You are a helpful AI assistant tasked with summarizing conversations.

When asked to summarize, provide a detailed but concise summary of the conversation. 
Focus on information that would be helpful for continuing the conversation, including:
- What was done - What is currently being worked on - Which files are being modified - What needs to be done next - Key user requests, constraints, or preferences that should persist - Important technical decisions and why they were made

Your summary should be comprehensive enough to provide context but concise enough to be quickly understood.

📌 转载信息
转载时间:
2026/1/14 10:59:25

文章是自己查官网,然后与 AI 对话校验自己理解的正确性,然后自己总结的,为啥被举报说 AIGC 未截图?这也能被举报?????

Commands

斜杠命令,需要用户自己主动触发;本质是把重复的提示词存储起来,直接通过命令调用提示词。

使用方法: 用户可以通过在项目的 .claude/commands/ 目录下创建 Markdown 文件 (.md) 来定义自定义命令。

  • 文件名:决定命令的触发词(例如 analyze.md 对应 /analyze)。

  • 文件内容:包含你希望 Claude 执行的具体 Prompt(提示词)。

  • 参数:支持使用 $1, $2$ARGUMENTS 接收用户输入。

官方 / 社区示例/security-review 这是一个常见的自定义命令,用于让 Claude 按特定标准审查代码安全。

文件路径~/.claude/commands/security-review.md (全局命令) 或 .claude/commands/security-review.md (项目命令)

文件内容示例

--- description: Review the current code for security vulnerabilities --- Please review the code in the current context for security vulnerabilities. Focus specifically on: 1. SQL injection risks 2. XSS vulnerabilities 3. Hardcoded secrets If you find issues, please suggest specific fixes. 

如何使用:在终端输入 /security-review

Agents

Agent 本质上是拥有独立上下文特定系统提示词(System Prompt) 的 Claude 实例

减小主流程上下文的占用,子代理上下文隔离,可以更好的聚焦任务;

使用方法: 你可以通过 CLI 交互式创建,或者通过配置文件定义。Agent 本质上是拥有独立上下文特定系统提示词(System Prompt) 的 Claude 实例。

  • 交互式创建:在 Claude Code 中输入 /agents,然后选择 “Create new agent”。

  • 配置定义:通常定义在配置文件中,指定其 role(角色)、description(描述)和 tools(可用工具)。

官方示例Code Reviewer (代码审查员) 这是官方文档中常用来演示如何通过子代理分担任务的例子。

配置逻辑(概念性描述)

  • 名称code-reviewer

  • 角色描述:你是一位资深的代码审查专家,通过严格的标准审查代码变更。你只关注代码质量、可读性和潜在 bug,不要直接写代码,只提供建议。

  • 工具权限:限制为 Read(只读)权限,防止它意外修改代码。

如何使用: 在对话中,主 Agent 可能会根据任务自动调用它,或者你可以显式指派任务(如果配置允许)。

“Please ask the code-reviewer to check my latest changes.”

Skills

按需加载,只有需要该技能的时候才会加载文件内容。

都可以对业务及开发流程进行规范

使用方法: Skill 是赋予 Claude 新能力的 “知识包”,通常由一个 SKILL.md 文件和相关的脚本 / 文档组成。

  • 核心文件SKILL.md

  • 原理:Claude 启动时会加载 Skill 的元数据(Metadata)。只有当它判断当前任务需要该技能时(例如用户要求 “处理 PDF”),它才会读取 SKILL.md 的完整内容并执行其中的步骤。

官方示例PDF Processing Skill (PDF 处理技能) 这是 Anthropic 工程博客中介绍的一个经典案例,教 Claude 如何读取 PDF 表单。

目录结构示例

skills/pdf-skill/
├── SKILL.md          # 告诉 Claude 如何使用这个技能
├── extract.py        # 实际执行提取工作的 Python 脚本
└── README.md

SKILL.md 内容摘要

“When the user asks to extract data from a PDF, run the extract.py script provided in this directory. Do not try to read the PDF raw bytes directly. Interpret the JSON output from the script.”

如何使用:用户无需显式调用。只需说 “Read the contract.pdf and tell me the date”,Claude 会自动激活 PDF Skill。

Plugins

Plugin 是上述所有内容(Commands, Agents, Skills)的分发容器


接下来说一下比较容易混淆的地方,commands,agents,skills 确实有功能重叠的地方,但是他们的侧重点是不一样的,只有明白了他们各自的侧重点之后才能更好的决定使用哪一个。

1. 最大的重叠区:Command vs. Skill

这是最容易混淆的一对。它们都可以用来封装一段 Prompt 或脚本。

  • 重叠点:它们本质上都是 “预定义的指令 / 脚本”。

  • 核心区别:谁掌握 “扳机”?

    • Command (命令)显式的。你(用户) 是控制者。你必须输入 /review,Claude 才会去审查。

    • Skill (技能)隐式的。Claude (模型) 是控制者。你只需要说 “帮我看看这代码咋样”,Claude 会自己判断:“哦,用户需要审查代码,我应该调用 CodeReviewSkill。”

例子:

如果你写了一个 Python 脚本 format_code.py。

  • 做成 Command (/fmt):你每次必须手动输入 /fmt 才能运行它。

  • 做成 Skill:当你对 Claude 说 “这代码太乱了” 时,Claude 会自动运行这个脚本。

2. 逻辑重叠区:Agent vs. Skill

这两者都涉及 “特定领域的专业能力”。

  • 重叠点:都能让 Claude 变得更专业(例如都懂 SQL)。

  • 核心区别:上下文是不是独立的?

    • Skill (技能)工具。它在当前对话中被加载。它就像给了当前的 Claude 一本《SQL 手册》,它现学现卖,但还是同一个 Claude 在跟你说话,上下文是混在一起的。

    • Agent (代理)分身。它拥有独立的上下文。当你调用 Agent 时,就像是 Claude 把任务转包给了坐在旁边的 “数据库专家”。这个专家有自己的记忆和设定,处理完后只把结果告诉主 Claude,避免了主对话窗口被大量的中间步骤污染

3. Plugin (插件) 的特殊地位

Plugin 没有任何功能上的重叠,因为它不是功能本身,而是包装盒

  • 你不能把 Plugin 和 Command 并列比较。

  • Plugin 包含 Command、Skill 和 Agent。

  • 就好比:Command 是苹果,Agent 是橙子,而 Plugin 是水果篮。


一个场景看懂所有区别

假设你想实现一个功能:“将代码翻译成中文文档”。你可以通过三种方式实现,侧重点不同:

方式实现形态交互体验适用情况
方式 A: Command定义 /trans 命令你输入 /trans file.py,Claude 立即执行翻译。高频、确定性任务。你很清楚什么时候需要翻译,不需要 Claude 废话。
方式 B: Skill编写 TranslationSkill.md你说 “帮我把这文件弄得容易读一点”,Claude 自动识别并调用翻译技能。模糊指令、智能化。你希望 Claude 像助手一样自动判断该做什么。
方式 C: Agent创建 TranslatorAgent你说 “开启翻译项目”,主 Claude 唤醒子代理。子代理独立运行,不打扰你,翻译了几百个文件后,只给你一个汇总报告。复杂、耗时、多步骤任务。防止翻译几百个文件的过程刷屏,导致你之前的对话记忆被挤掉。

总结:我该选哪个?

如果你在尝试扩展 Claude Code,可以用这个简单的决策树:

  1. 这个功能需要用户手动且精确地触发吗?

    • Command (/foo)

    • 下一步

  2. 这个任务是否非常复杂,需要大量步骤,且容易污染当前的聊天记录?

    • Agent (独立的子脑)

    • Skill (教会当前大脑新知识)

  3. 你想把这些功能打包发给同事用吗?

    • 把做好的 Command/Agent/Skill 放到一个文件夹里,做成 Plugin


如果内容有误,欢迎指出


📌 转载信息
原作者:
Eddy1
转载时间:
2026/1/4 18:41:57

本文章参考 ClaudeCode 官网以及 AI 总结。

Commands

斜杠命令,需要用户自己主动触发;本质是把重复的提示词存储起来,直接通过命令调用提示词。

使用方法: 用户可以通过在项目的 .claude/commands/ 目录下创建 Markdown 文件 (.md) 来定义自定义命令。

  • 文件名:决定命令的触发词(例如 analyze.md 对应 /analyze)。

  • 文件内容:包含你希望 Claude 执行的具体 Prompt(提示词)。

  • 参数:支持使用 $1, $2$ARGUMENTS 接收用户输入。

官方 / 社区示例/security-review 这是一个常见的自定义命令,用于让 Claude 按特定标准审查代码安全。

文件路径~/.claude/commands/security-review.md (全局命令) 或 .claude/commands/security-review.md (项目命令)

文件内容示例

--- description: Review the current code for security vulnerabilities --- Please review the code in the current context for security vulnerabilities. Focus specifically on: 1. SQL injection risks 2. XSS vulnerabilities 3. Hardcoded secrets If you find issues, please suggest specific fixes. 

如何使用:在终端输入 /security-review

Agents

Agent 本质上是拥有独立上下文特定系统提示词(System Prompt) 的 Claude 实例

减小主流程上下文的占用,子代理上下文隔离,可以更好的聚焦任务;

使用方法: 你可以通过 CLI 交互式创建,或者通过配置文件定义。Agent 本质上是拥有独立上下文特定系统提示词(System Prompt) 的 Claude 实例。

  • 交互式创建:在 Claude Code 中输入 /agents,然后选择 “Create new agent”。

  • 配置定义:通常定义在配置文件中,指定其 role(角色)、description(描述)和 tools(可用工具)。

官方示例Code Reviewer (代码审查员) 这是官方文档中常用来演示如何通过子代理分担任务的例子。

配置逻辑(概念性描述)

  • 名称code-reviewer

  • 角色描述:你是一位资深的代码审查专家,通过严格的标准审查代码变更。你只关注代码质量、可读性和潜在 bug,不要直接写代码,只提供建议。

  • 工具权限:限制为 Read(只读)权限,防止它意外修改代码。

如何使用: 在对话中,主 Agent 可能会根据任务自动调用它,或者你可以显式指派任务(如果配置允许)。

“Please ask the code-reviewer to check my latest changes.”

Skills

按需加载,只有需要该技能的时候才会加载文件内容。

可以对业务知识及开发流程进行规范

使用方法: Skill 是赋予 Claude 新能力的 “知识包”,通常由一个 SKILL.md 文件和相关的脚本 / 文档组成。

  • 核心文件SKILL.md

  • 原理:Claude 启动时会加载 Skill 的元数据(Metadata)。只有当它判断当前任务需要该技能时(例如用户要求 “处理 PDF”),它才会读取 SKILL.md 的完整内容并执行其中的步骤。

官方示例PDF Processing Skill (PDF 处理技能) 这是 Anthropic 工程博客中介绍的一个经典案例,教 Claude 如何读取 PDF 表单。

目录结构示例

Plaintext

plugins/pdf-skill/
├── SKILL.md          # 告诉 Claude 如何使用这个技能
├── extract.py        # 实际执行提取工作的 Python 脚本
└── README.md

SKILL.md 内容摘要

“When the user asks to extract data from a PDF, run the extract.py script provided in this directory. Do not try to read the PDF raw bytes directly. Interpret the JSON output from the script.”

如何使用:用户无需显式调用。只需说 “Read the contract.pdf and tell me the date”,Claude 会自动激活 PDF Skill。

Plugins

Plugin 是上述所有内容(Commands, Agents, Skills)的分发容器


接下来说一下比较容易混淆的地方,commands,agents,skills 确实有功能重叠的地方,但是他们的侧重点是不一样的,只有明白了他们各自的侧重点之后才能更好的决定使用哪一个。

1. 最大的重叠区:Command vs. Skill

这是最容易混淆的一对。它们都可以用来封装一段 Prompt 或脚本。

  • 重叠点:它们本质上都是 “预定义的指令 / 脚本”。

  • 核心区别:谁掌握 “扳机”?

    • Command (命令)显式的。你(用户) 是控制者。你必须输入 /review,Claude 才会去审查。

    • Skill (技能)隐式的。Claude (模型) 是控制者。你只需要说 “帮我看看这代码咋样”,Claude 会自己判断:“哦,用户需要审查代码,我应该调用 CodeReviewSkill。”

例子:

如果你写了一个 Python 脚本 format_code.py。

  • 做成 Command (/fmt):你每次必须手动输入 /fmt 才能运行它。

  • 做成 Skill:当你对 Claude 说 “这代码太乱了” 时,Claude 会自动运行这个脚本。

2. 逻辑重叠区:Agent vs. Skill

这两者都涉及 “特定领域的专业能力”。

  • 重叠点:都能让 Claude 变得更专业(例如都懂 SQL)。

  • 核心区别:上下文是不是独立的?

    • Skill (技能)工具。它在当前对话中被加载。它就像给了当前的 Claude 一本《SQL 手册》,它现学现卖,但还是同一个 Claude 在跟你说话,上下文是混在一起的。

    • Agent (代理)分身。它拥有独立的上下文。当你调用 Agent 时,就像是 Claude 把任务转包给了坐在旁边的 “数据库专家”。这个专家有自己的记忆和设定,处理完后只把结果告诉主 Claude,避免了主对话窗口被大量的中间步骤污染

3. Plugin (插件) 的特殊地位

Plugin 没有任何功能上的重叠,因为它不是功能本身,而是包装盒

  • 你不能把 Plugin 和 Command 并列比较。

  • Plugin 包含 Command、Skill 和 Agent。

  • 就好比:Command 是苹果,Agent 是橙子,而 Plugin 是水果篮。


一个场景看懂所有区别

假设你想实现一个功能:“将代码翻译成中文文档”。你可以通过三种方式实现,侧重点不同:

方式实现形态交互体验适用情况
方式 A: Command定义 /trans 命令你输入 /trans file.py,Claude 立即执行翻译。高频、确定性任务。你很清楚什么时候需要翻译,不需要 Claude 废话。
方式 B: Skill编写 TranslationSkill.md你说 “帮我把这文件弄得容易读一点”,Claude 自动识别并调用翻译技能。模糊指令、智能化。你希望 Claude 像助手一样自动判断该做什么。
方式 C: Agent创建 TranslatorAgent你说 “开启翻译项目”,主 Claude 唤醒子代理。子代理独立运行,不打扰你,翻译了几百个文件后,只给你一个汇总报告。复杂、耗时、多步骤任务。防止翻译几百个文件的过程刷屏,导致你之前的对话记忆被挤掉。

总结:我该选哪个?

如果你在尝试扩展 Claude Code,可以用这个简单的决策树:

  1. 这个功能需要用户手动且精确地触发吗?

    • Command (/foo)

    • 下一步

  2. 这个任务是否非常复杂,需要大量步骤,且容易污染当前的聊天记录?

    • Agent (独立的子脑)

    • Skill (教会当前大脑新知识)

  3. 你想把这些功能打包发给同事用吗?

    • 把做好的 Command/Agent/Skill 放到一个文件夹里,做成 Plugin


如果内容有误,欢迎指出


📌 转载信息
原作者:
Eddy1
转载时间:
2026/1/4 17:00:04