编者按: 在 Claude Code 中,我们到底该用 Command、Skill 还是 Agent?这三者究竟是新手到高手的进阶阶梯,还是各司其职的协作组件?
我们今天为大家带来的文章,作者的观点是:Commands、Skills 和 Agents 并非技能等级,而是同一系统中分别负责“何时触发”与“执行什么”的三种协同角色。
文章深入剖析了三者的本质区别:Commands 和 Skills 实质上是“触发器”(手动 vs 自动),决定了“何时”运行;而 Agents 则是拥有独立上下文和工具的“执行者”,决定了“做”什么。作者通过“代码整洁度检查”这一完整示例,清晰展示了如何组合使用 Command + Agent 实现手动流程,或 Skill + Agent 实现智能主动介入,并强调 —— 选择依据不应是“功能复杂度”,而应是“谁来决定执行时机”。
作者 | Ilia Karelin
编译 | 岳扬
“我是该用 Command、Skill 还是 Agent 来处理这件事?”老实说,你以前肯定问过自己这个问题。
答案总是那一套。“Commands 适合初学者,Skills 适合进阶者,Agents 则是高级用法。”或者是“先从 Commands 开始,进阶到 Skills,最后掌握 Agents。”
但事情根本不是这么回事。
Commands、Skills 和 Agents 并不是一个循序渐进的进阶体系。它们属于同一系统中的三个组成部分,彼此协同工作。
Commands 和 Skills 决定某件事何时运行。Agents 决定具体做什么。
没人解释过这一点。所以多数人构建了错误的方案,然后纳闷为什么结果跟预期的不一样。
01 大多数人误解的地方
传统观念把这三者当成游戏里的等级。从 Command 开始入门,然后晋升到 Skill,等“水平够了”再精通 Agent。
这种说法随处可见。网络教程会写“先用简单的 Command”。论坛帖子建议“掌握了基础用法后,再转向 Skill”。高阶用户谈论着“终于搞懂了Agent”。
听起来挺有道理,实则大错特错。
它们不是技能等级,而是系统中的不同角色:
- Commands = 手动触发(由你决定何时执行)
- Skills = 自动识别触发(由 Claude 决定何时执行)
- Agents = 执行者(真正干活的)
Command 可以调用 Agent,Skill 也可以调用 Agent。 Agent 本身可简可繁。这些都和“新手还是高手”毫无关系。
2025 年 10 月,Anthropic 统一了这一架构设计。他们并没有建立三个独立的系统,而是构建了一个可扩展模型,内含三个协同工作的组件。
但大多数人都没理解到这一点。
02 Claude Code Commands、Skills 和 Agents 详解
让我们来解析每个部分的作用:
2.1 Command:手动输入,即刻运行
Command 是手动触发器。你输入 /commit,它就运行;你输入 /codehygiene,它也会运行。执行时机完全由你掌控。
Command 文件的结构如下:
---
description: Run code hygiene check on recent changes
---
Code Hygiene Review
Use the code-hygiene-checker agent to verify recent changes are structurally complete and no technical debt was introduced. Launch the code-hygiene-checker agent to verify:
- Changes are fully integrated across all layers
- Old code and unused implementations are removed
- No development artifacts remain
- Dependencies and configurations are updated consistently
将其保存为 ~/.claude/commands/codehygiene.md。
在 Claude Code 中输入 /codehygiene,它便会马上执行。
就这么简单。手动控制,显式执行。
2.2 Skills:Claude 识别到,便自动加载
Skills 是自动识别触发器。Claude 会读取对话内容,将上下文与 Skill 描述进行匹配,并自动加载。
Skill 文件的结构如下:
---
name: react-patterns
description: Best practices for React components. Use when working with React code or discussing component architecture.
---
When writing React components:
- Prefer composition over prop drilling
- Keep hooks at the top level
- Use descriptive component names
将其保存为 ~/.claude/skills/react-patterns/SKILL.md。
你不需要手动调用它。当你在处理 React 相关内容时,Claude 会自动识别并加载这个 Skill。
2.3 Agents:真正干活的执行者
Agents 是具备独立上下文、工具和指令的专业执行者。
它们在隔离环境中运行,完成后返回结果。
Agent 文件的结构如下:
---
name: code-hygiene-checker
description: Reviews code for structural completeness and cleanliness. Use after refactors or before merging PRs.
tools: Read, Grep, Glob, Bash
model: sonnet
---
Your role is to inspect code changes and prevent technical debt before it accumulates.
[Full agent prompt here - I’ll include the complete version below]
将其保存为 ~/.claude/agents/code-hygiene-checker.md。
Agent 不会自行启动,需要由 Command、Skill 或 Claude 根据需求来调用。
03 它们如何协同工作
Command 调用 Agent 的流程:
你输入 /codehygiene → Command 运行 → Command 指示 Claude 使用 code-hygiene-checker agent → Agent 执行任务 → 返回结果
Skill 调用 Agent 的流程:
Claude 检测到你正在重构代码 → 加载 code-review skill → Skill 指示 Claude 使用 code-hygiene-checker agent → Agent 执行工作 → 返回结果
核心模式:
- Commands/Skills = 触发器(决定何时执行)
- Agents = 执行者(决定执行什么)
文件格式相同,均为 markdown,但在系统中扮演不同角色。
04 一个实际案例:代码健康度检查系统
让我为大家展示一套完整可用的系统。只需两个文件,直接复制粘贴即可。60 秒内,你将拥有一个功能完备的代码审查工具。
文件 1:Command(手动触发器)
将其保存为 ~/.claude/commands/codehygiene.md:
---
description: Run code hygiene check on recent changes
---
Code Hygiene Review
Use the code-hygiene-checker agent to verify recent changes are structurally complete and no technical debt was introduced.
1. Launch Code Hygiene Check
Launch the code-hygiene-checker agent to verify:
- Changes are fully integrated across all layers
- Old code and unused implementations are removed
- No development artifacts remain (TODOs, console.logs, commented code)
- Dependencies and configurations are updated consistently
- Structural integrity is maintained
2. Review Findings and Suggest Fixes
After the agent returns its review results, analyze the findings and provide specific, actionable suggestions for addressing each issue identified. Organize suggestions by priority (blocking issues first, then technical debt risks, then optional improvements).
文件 2:Agent(任务执行者)
将其保存为 ~/.claude/agents/code-hygiene-checker.md:
---
name: code-hygiene-checker
description: Reviews code for structural completeness and cleanliness. Use after refactors, before merging PRs,or when checking for incomplete changes, dead code, development artifacts,and technical debt. Checks dependency hygiene, configuration consistency,and change completeness.
tools:Read, Grep, Glob, Bash
model: sonnet
permissionMode:default
---
Your role isto inspect code changes and prevent technical debt before it accumulates. You verify that modifications are fully complete, temporary artifacts are removed,and structural integrity is maintained. Your mission is catching incomplete implementations, forgotten cleanup,and configuration gaps before they become permanent problems. Every review you conduct protects the codebase from degradation over time.
Review Scope
When invoked, you review:
- Recent changes (last commit or git diff if available)
- Specific files/directories mentioned by the user
-If no scope specified, ask the user what to review
Focus on changed code and its related files,not the entire codebase unless explicitly requested.
Your Review Scope (What You Check)
Your review scope is strictly limited to structural completeness and cleanliness. You explicitly DO NOT review:
- Functional correctness (assumed verified by author and tests)
- Test quality or coverage
- Documentation quality
- Code style or formatting (assumed handled by linters)
Your Tools
Use these tools strategically:
- Grep: Find TODOs, FIXMEs, console.log, debugger statements, commented code
- Glob: Identify files matching patterns (*.test.js,*.config.*, package.json)
-Read: Examine specific files for completeness and dead code
- Bash: Use git commands to check recent changes (git diff, git log, git status)
Your Review Methodology
1. Dead Code Detection
You systematically identify any code that has been replaced or refactored and verify its complete removal. You check for:
- Unused functions, classes,or modules that should have been deleted
- Old implementations left alongside new ones
- Orphaned imports or dependencies
- Obsolete configuration entries
2. Change Completeness Audit
You verify that all components of a change are present:
-If a feature touches multiple layers (API, UI, database), confirm all are included
- Check that related configuration files are updated (build scripts, deployment configs, environment variables)
- Verify that dependency lists reflect additions and removals
- Ensure database migrations or schema changes are included if needed
3. Development Artifact Scan
You identify and flag any temporary development artifacts:
- Commented-out code blocks (unless with clear justification)
- TODO, FIXME,or HACK comments without tickets/tracking
- Debug logging or test data left in production code
- Temporary workarounds that should be proper implementations
- Console.log statements or debug breakpoints
4. Dependency Hygiene
You verify dependency changes are clean:
-New dependencies are actually used and necessary
- Removed features have their dependencies removed from package.json/requirements/etc.
- No duplicate or conflicting dependencies introduced
- Lock files are updated consistently
5. Configuration Consistency
You ensure all configuration updates are complete:
- Build configurations reflect any new compilation requirements
- CI/CD pipelines are updated fornew dependencies or build steps
- Environment-specific configs are updated consistently across all environments
- Feature flags or toggles are properly configured if used
Your Review Output Format
Structure your review as a prioritized list of findings:
Blocking Issues
[Issues that will cause immediate problems - broken builds, runtime errors, deployment failures]
If none found, state: “No blocking issues found”
Technical Debt Risks
[Issues that will cause future maintenance problems - confusion, bugs,or slowdowns]
If none found, state: “No technical debt risks identified”
Suggestions
[Optional improvements that would enhance code quality but aren’t required]
If none found, state: “Code hygiene looks good”
Summary Checklist
- Clean Removals:[Old code completely removed OR list what remains]
- Complete Changes:[All required parts present OR list what’s missing]
- No Dev Artifacts:[Clean OR list artifacts found]
- Dependencies Clean:[Verified OR list issues]
- Configs Updated:[Verified OR list missing updates]
Decision Frameworks
- When you find incomplete changes, categorize them as either ”blocking” (will break builds/deployments)or ”debt-inducing” (will cause future confusion/maintenance issues)
-If you’re unsure whether old code should be removed, flag it for author clarification rather than assuming
-For configuration changes, verify both addition AND removal scenarios
- When reviewing refactoring, trace all call sites of modified code to ensure completeness
-If you find 10+ issues in a single category, summarize the pattern rather than listing all instances
- Limit detailed findings to the most impactful 15-20 items to keep the review actionable
如何使用?
1)将这两个文件复制到上述指定位置
2)在 Claude Code 中输入 /codehygiene
3)观察 Agent 自动扫描你最近的代码变更
4)获得一份结构化报告,包含阻塞性问题(blocking issues)、技术债务风险(technical debt risks)和改进建议(suggestions)
Command 让你掌控执行的主动权,Agent 负责实际的检查工作。
这就是整个系统:两个文件,一套工作流。
或者,如果你正在使用 Claude Code —— 你也可以直接让 Claude Code 为你一键生成全部内容!
05 Command、Skill 与 Agent 的核心区别
现在我们已经了解了它们的协作方式,下面给出一个决策框架。
5.1 Command vs Skill:由谁决定执行时机
将 Command 想象成手动变速箱,何时换挡由你掌控。
Skill 则像定速巡航系统,系统会根据路况自动调整。
在以下情况下使用 Command:
1)你需要明确控制执行时机(例如提交代码、项目部署、代码审查)
2)这个操作会产生某些后果,而你希望在这些后果发生之前,先由你自己确认
3)这是一个你会在特定时机反复执行的工作流程,而你希望在自己认为合适的那一刻手动启动它
在以下情况下使用 Skill:
1)Claude 应该在不需要你明确指示的情况下,主动识别当前场景,并应用它所掌握的相关知识(比如编码规范、安全规范等)
2)相关的上下文(比如规则、知识、工具或配置)应当在你没有主动要求的情况下,由系统自动识别并加载进来
3)你希望 Claude 能够自己识别出当前场景中需要某个能力(比如某个 Skill 或规则),并在不需要你明确指示的情况下,主动调用并使用它
错误的选择依据: 看功能“复杂不复杂”。
正确的选择依据: 看“谁来决定什么时候执行”。
5.2 Agent:负责“执行”
Agent 是“执行者”。它们具备:
1)独立的上下文(与主对话隔离)
2)可使用的特定工具(如Read、Grep、Bash等)
3)定义明确的角色和方法论
4)控制其行为方式的权限设置
Command 可以调用 Agent,Skill 也可以调用 Agent,Claude 也能直接调用 Agent。
Agent 并非比 Command “更高级” —— Command 是触发器,Agent 是执行者,它们扮演着不同的角色。
5.3 完整的系统工作流程
以下是整个系统的协作方式:
场景一(通过 Command 触发)
1)你输入 /codehygiene(Command - 手动触发)
2)Command 告知 Claude:“调用 code-hygiene-checker agent”
3)Agent 加载自己的上下文和工具
4)Agent 使用 Grep、Read、Bash 等工具检查你的代码
5)Agent 返回结构化的检查结果
6)你获得可操作的报告
场景二(通过 Skill 触发)
1)你重构了一个大型函数(未输入任何 command)
2)Claude 检测到重构操作(Skill - 自动发现)
3)Skill 告知 Claude:“调用 code-hygiene-checker agent”
4)Agent 加载并执行检查
5)Agent 返回检查结果
6)你在未主动请求的情况下获得了主动的代码审查
同一个 Agent,不同的触发方式。Agent 并不关心自己被如何调用。
06 何时在 Claude Code 中使用 Commands、Skills 或 Agents
大多数开发者基于错误的问题做出选择。他们问的是:“这是初学者用的,还是高级功能?”
真正该问的问题是:
- 谁来决定这个操作何时执行?(Command vs Skill)
- 需要完成什么具体工作?(Agent)
6.1 使用 Command + Agent 的场景
当你希望对多步骤工作流保有手动控制权时:
- 提交 PR 前的代码审查
- 项目部署上线前对照检查清单逐项确认
- 每周复盘
- 安全审计
你输入命令,Agent 执行具体工作。
6.2 使用 Skill + Agent 的场景
当希望 Claude 主动应用领域专业知识时:
- 强制执行编码规范
- 架构模式建议
- 安全漏洞检查
- 性能优化建议
Claude 识别上下文,然后 Skill 自动加载,最后 Agent 执行工作。
6.3 仅使用 Command 的场景
当任务简单,且不需要隔离上下文时:
- 插入代码片段
- 格式化提示词模板
- 运行一个快速的 bash 命令
无需 Agent,Command 本身就是完整的工作流。
6.4 仅使用 Skill 的场景
你提供的是供参考的背景信息,而不是用来触发某个具体操作的指令时:
- API 文档
- 团队会议安排
- 项目专属术语说明
无需 Agent,Skill 仅为 Claude 提供背景上下文。
07 常见问题(FAQ)
问:Claude Code 中 Command 和 Skill 有什么区别?
Command 是你通过输入 /command-name 手动触发的指令。Skill 是 Claude 根据对话上下文自动识别的功能。两者都可以调用 Agent 来执行任务。
问:在使用 Skill 或 Agent 之前,需要先掌握 Command 吗?
不需要。Command、Skill 和 Agent 并非渐进式的技能层级。它们是同一系统的三个组成部分:Command 和 Skill 决定何时执行,Agent决定执行什么任务。
问:我可以将这些代码健康度检查文件用于我的项目吗?
可以。将两个文件(/.claude/commands/codehygiene.md 和 /.claude/agents/code-hygiene-checker.md)复制到你的 ~/.claude/ 目录下。在 Claude Code 中输入 /codehygiene 即可运行。
END
本期互动内容 🍻
❓有没有一次因为“误以为 Agent 是高级功能”而绕了远路的经历?欢迎分享。
原文链接: