I'm designing a CLI tool that helps developers track TODO comments across
their codebase. Create an agent team to explore this from different angles: one
teammate on UX, one on technical architecture, one playing devil's advocate.
控制 Agent Team
显示模式
In-process :所有队友在主终端内运行,使用 Shift+Down 循环浏览队友
Split panes :每个队友获得自己的 tmux/iTerm2 窗格
实例
{ "teammateMode":"in-process" }
指定队友数量和模型
Create a team with4 teammates to refactor these modules in parallel.UseSonnetfor each teammate.
Team config: ~/.claude/teams/{team-name}/config.json
Task list: ~/.claude/tasks/{team-name}/
Git Worktree 支持
问题背景
多个 Agent 同时干活时,可能会"打架"。想象一下这个场景:你让 Agent A 去重构数据库模块,让 Agent B 去修复登录页面的 bug。两个任务看起来互不相关,但它们都在同一个代码仓库、同一分支上工作。Agent A 正在修改 utils.py ,Agent B 也在修改 utils.py 。一个保存了一个版本,另一个覆盖了不同的版本,最终导致冲突、报错,甚至数据丢失。
# 让多个 Subagent 同时审查代码的不同方面
Use the security-reviewer subagent to check for security issues
Use the performance-reviewer subagent to analyze performance impact
Use the test-coverage subagent to validate test coverage
使用 Agent Teams
Create an agent team to review PR #142. Spawn three reviewers:
- One focused on security implications
- One checking performance impact
- One validating test coverage
Have them each review and report findings.
示例二:并行研究
Research the authentication, database,and API modules in parallel using separate subagents
示例三:使用竞争假设进行调查
实例
Users report the app exits after one message instead of staying connected.
Spawn 5 agent teammates to investigate different hypotheses. Have them talk to
each other to try to disprove each other's theories, like a scientific
debate. Update the findings doc with whatever consensus emerges.
示例四:多分支开发
# 终端 1:重构用户模块
claude -w feature/user-refactor
# 终端 2:修复登录 bug
claude -w bugfix/login-issue
# 终端 3:开发新功能
claude -w feature/new-dashboard
示例五:链接 Subagent
Use the code-reviewer subagent to find performance issues,thenuse the optimizer subagent to fix them
最佳实践
Subagent 最佳实践
保持专注 :每个 Subagent 应有明确、单一的任务
限制工具 :根据任务需要限制 Subagent 的工具访问权限
选择合适模型 :简单任务使用 Haiku,复杂任务使用 Sonnet 或 Opus
使用后台运行 :长时间任务使用后台 Subagent,避免阻塞主对话
恢复 Subagent :需要继续工作时,要求 Claude 恢复 Subagent
Agent Teams 最佳实践
给队友足够的上下文 :在生成提示中包含特定于任务的详细信息
选择适当的团队规模 :大多数工作流从 3-5 个队友开始
适当调整任务大小 :每个队友 5-6 个任务,保持生产力
等待队友完成 :告诉负责人等待队友完成任务后再进行
从研究和审查开始 :从不需要编写代码的任务开始
避免文件冲突 :分解工作使每个队友拥有不同的文件集
监控和指导 :检查进度,重定向不起作用的方法
Git Worktree 最佳实践
每个任务一个 Worktree :避免在同一个 worktree 中处理多个不相关的任务
使用 tmux 管理 :同时运行多个 Claude 会话时,使用 tmux 便于切换
清理不需要的 Worktree :任务完成后及时删除 worktree
故障排除
Agent Teams 常见问题
问题
解决方案
队友未出现
检查任务是否足够复杂、tmux 是否安装
过多权限提示
在权限设置中预批准常见操作
队友在错误后停止
检查输出并给予额外指示或生成替代队友
负责人提前关闭
告诉负责人继续或等待队友完成
孤立的 tmux 会话
使用 tmux ls 和 tmux kill-session -t <session-name> 清理
You are a senior code reviewer ensuring high standards of code quality and security.
When invoked: 1. Run git diff to see recent changes 2. Focus on modified files 3. Begin review immediately
Review checklist: - Code is clear and readable
- Functions and variables are well-named
- No duplicated code
- Proper error handling
- No exposed secrets or API keys
- Input validation implemented
- Good test coverage
- Performance considerations addressed
Provide feedback organized by priority: - Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)
调试器
实例
---
name: debugger
description: Debugging specialist for errors, test failures, and unexpected behavior.
tools: Read, Edit, Bash, Grep, Glob ---
You are an expert debugger specializing in root cause analysis.
When invoked: 1. Capture error message and stack trace 2. Identify reproduction steps 3. Isolate the failure location 4. Implement minimal fix 5. Verify solution works
Debugging process: - Analyze error messages and logs
- Check recent code changes
- Form and test hypotheses
- Add strategic debug logging
- Inspect variable states
只读数据库查询器
---
name: db-reader
description: Execute read-only database queries. Use when analyzing data or generating reports.
tools: Bash
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-readonly-query.sh" ---
You are a database analyst with read-only access. Execute SELECT queries to answer questions about the data.