task - 任务命令
task 命令是 Claude Code 的任务管理工具,提供项目任务的创建、执行、追踪和管理功能。
命令概述
task 命令提供:
- 任务创建和管理
- 任务执行和监控
- 任务状态追踪
- ⏰ 任务调度和自动化
- 任务报告和分析
基本用法
创建任务
bash
# 创建简单任务
claude task create "修复用户登录问题"
# 创建详细任务
claude task create "实现支付功能" \
--description "集成第三方支付API" \
--priority high \
--assignee "张三" \
--due-date "2024-02-01"
# 从模板创建任务
claude task create --template bug-fix --title "修复购物车计算错误"任务管理
bash
# 查看任务列表
claude task list
# 查看指定状态的任务
claude task list --status todo,in-progress
# 查看分配给自己的任务
claude task list --assignee me
# 搜索任务
claude task search "支付"任务执行
bash
# 开始执行任务
claude task start 123
# 更新任务状态
claude task update 123 --status in-progress
# 完成任务
claude task complete 123 --comment "已修复并测试通过"
# 暂停任务
claude task pause 123 --reason "等待第三方API文档"配置选项
任务创建选项
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
--title | string | - | 任务标题 |
--description | string | - | 详细描述 |
--priority | string | medium | 优先级: low, medium, high, urgent |
--assignee | string | - | 指派人员 |
--due-date | string | - | 截止日期 |
--tags | string | - | 标签 (逗号分隔) |
--parent | number | - | 父任务ID |
查询选项
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
--status | string | - | 任务状态筛选 |
--assignee | string | - | 指派人筛选 |
--priority | string | - | 优先级筛选 |
--tag | string | - | 标签筛选 |
--limit | number | 20 | 结果数量限制 |
--sort | string | created_at:desc | 排序方式 |
任务生命周期
任务状态流转
状态详解
1. 待办 (todo)
- 任务已创建但尚未开始
- 可以编辑任务详情
- 可以分配给团队成员
2. 进行中 (in-progress)
- 任务正在执行
- 记录工作时间
- 可以添加进度更新
3. 已完成 (completed)
- 任务执行完成
- 不可再次编辑
- 生成完成报告
4. 已暂停 (paused)
- 临时暂停执行
- 记录暂停原因
- 可以恢复执行
5. 已取消 (cancelled)
- 任务不再执行
- 记录取消原因
- 保留历史记录
任务类型
1. 开发任务 (Development)
功能开发任务
bash
# 创建功能开发任务
claude task create "实现用户注册功能" \
--type feature \
--template feature-development \
--priority high \
--estimate "8h"任务模板内容:
yaml
# feature-development 模板
name: 功能开发
checklist:
- [ ] 需求分析和理解
- [ ] 技术方案设计
- [ ] 数据库设计 (如需要)
- [ ] API 接口设计
- [ ] 前端界面设计
- [ ] 核心逻辑实现
- [ ] 单元测试编写
- [ ] 集成测试
- [ ] 代码审查
- [ ] 文档更新
- [ ] 部署和验证
acceptance_criteria:
- 功能按需求正常工作
- 代码质量符合团队标准
- 测试覆盖率达到80%以上
- 性能满足要求
- 文档完整准确
definition_of_done:
- 代码已合并到主分支
- 自动化测试通过
- 产品验收通过
- 文档已更新Bug修复任务
bash
# 创建Bug修复任务
claude task create "修复支付失败问题" \
--type bug \
--template bug-fix \
--priority urgent \
--severity highBug修复模板:
yaml
# bug-fix 模板
name: Bug修复
fields:
- name: bug_description
label: Bug描述
type: textarea
required: true
- name: steps_to_reproduce
label: 复现步骤
type: textarea
required: true
- name: expected_behavior
label: 期望行为
type: textarea
required: true
- name: actual_behavior
label: 实际行为
type: textarea
required: true
checklist:
- [ ] 问题复现和确认
- [ ] 根因分析
- [ ] 解决方案设计
- [ ] 代码修复
- [ ] 单元测试修复/新增
- [ ] 回归测试
- [ ] 代码审查
- [ ] 部署验证
severity_levels:
- critical: 系统崩溃或核心功能不可用
- high: 重要功能异常
- medium: 一般功能问题
- low: 轻微问题或改进建议2. 运维任务 (Operations)
部署任务
bash
# 创建部署任务
claude task create "生产环境部署 v2.1.0" \
--type deployment \
--template production-deployment \
--assignee "运维团队"监控任务
bash
# 创建监控任务
claude task create "系统性能监控优化" \
--type monitoring \
--schedule "daily" \
--auto-assign3. 文档任务 (Documentation)
文档编写
bash
# 创建文档任务
claude task create "API文档更新" \
--type documentation \
--template api-documentation \
--priority medium任务跟踪和报告
任务详情查看
bash
# 查看任务详情
claude task show 123
# 查看任务历史
claude task history 123
# 查看任务关联的代码变更
claude task commits 123任务详情输出示例:
任务 #123: 实现用户注册功能
=================================
基本信息:
状态: 进行中
优先级: 高
类型: 功能开发
创建时间: 2024-01-15 09:00:00
预计工时: 8小时
实际工时: 5.5小时
分配信息:
指派人: 张三 (zhangsan@example.com)
创建者: 李四 (lisi@example.com)
截止日期: 2024-01-20 18:00:00
任务描述:
实现完整的用户注册流程,包括邮箱验证、密码强度检查、
用户信息保存等功能。需要同时更新前端界面和后端API。
验收标准:
✓ 用户可以通过邮箱注册
✓ 密码强度验证功能正常
✓ 邮箱验证流程完整
◯ 注册成功后自动登录
◯ 错误处理和用户提示
进度清单:
✓ 需求分析和理解
✓ 技术方案设计
✓ 数据库设计
✓ API 接口设计
◯ 前端界面实现 (60%)
◯ 后端逻辑实现 (80%)
◯ 单元测试编写
◯ 集成测试
◯ 代码审查
标签: registration, authentication, frontend, backend
相关任务:
- #124: 用户登录功能 (阻塞)
- #125: 用户个人资料页面 (依赖)
最近活动:
2024-01-18 14:30 张三 更新进度: 后端API基本完成
2024-01-18 10:15 张三 开始前端界面开发
2024-01-17 16:45 张三 完成数据库表设计
2024-01-16 09:30 李四 分配任务给张三
附件:
- 技术方案文档.md
- 数据库设计图.png
- API接口文档.yaml进度更新
bash
# 添加进度更新
claude task update 123 --progress 75 --comment "前端界面开发完成75%"
# 添加工时记录
claude task log-time 123 --hours 2.5 --description "实现注册表单验证"
# 上传附件
claude task attach 123 ./docs/registration-api.md
# 添加评论
claude task comment 123 "遇到邮箱验证的技术问题,需要调研第三方服务"任务报告
bash
# 生成任务报告
claude task report --period week --format html
# 生成个人任务报告
claude task report --assignee me --format json
# 生成项目进度报告
claude task report --project user-management --format pdf周报示例:
本周任务报告 (2024-01-15 至 2024-01-21)
=========================================
总体统计:
新建任务: 12 个
完成任务: 8 个
进行中任务: 15 个
逾期任务: 2 个
完成情况:
计划完成: 10 个
实际完成: 8 个
完成率: 80%
⏰ 时间统计:
计划工时: 85 小时
实际工时: 92 小时
效率: 92.4%
人员分布:
张三: 6 个任务 (25 小时)
李四: 4 个任务 (20 小时)
王五: 5 个任务 (22 小时)
本周亮点:
用户注册功能开发完成
支付系统集成测试通过
性能优化提升30%
需要关注:
🔴 数据备份任务已逾期2天
🟡 API文档更新进度缓慢
🟡 测试环境偶发性问题
下周计划:
- 完成用户登录功能
- 开始移动端适配
- 准备生产环境部署任务自动化
任务模板
bash
# 创建自定义模板
claude task template create feature-template.yaml
# 使用模板创建任务
claude task create --template feature-template --vars '{"feature_name": "支付功能"}'自定义模板示例:
yaml
# feature-template.yaml
name: 功能开发模板
description: 标准功能开发流程
variables:
- name: feature_name
label: 功能名称
type: string
required: true
- name: estimated_hours
label: 预计工时
type: number
default: 8
task:
title: "实现{{feature_name}}"
description: |
开发{{feature_name}}功能,包括前后端实现、测试和文档。
预计工时: {{estimated_hours}} 小时
type: feature
priority: medium
estimate: "{{estimated_hours}}h"
checklist:
- 需求分析
- 技术方案设计
- 数据库设计
- API接口实现
- 前端界面实现
- 单元测试
- 集成测试
- 代码审查
- 文档更新
- 部署验证
acceptance_criteria:
- 功能按需求正常工作
- 代码质量符合标准
- 测试覆盖率达标
- 文档完整
subtasks:
- title: "{{feature_name}} - 后端API开发"
type: backend
estimate: "{{estimated_hours * 0.4}}h"
- title: "{{feature_name}} - 前端界面开发"
type: frontend
estimate: "{{estimated_hours * 0.4}}h"
- title: "{{feature_name}} - 测试用例编写"
type: testing
estimate: "{{estimated_hours * 0.2}}h"自动化规则
bash
# 创建自动化规则
claude task automation create --name "自动分配Bug" \
--trigger "type:bug,priority:high" \
--action "assign:on-call-engineer"
# 定时任务
claude task schedule create --name "每日构建检查" \
--cron "0 9 * * *" \
--template daily-build-check集成配置
javascript
// claude.task.config.js
export default {
// 任务配置
tasks: {
// 默认设置
defaults: {
assignee: 'auto', // 自动分配
priority: 'medium',
estimateUnit: 'hours'
},
// 状态配置
statuses: [
{ key: 'todo', label: '待办', color: '#6c757d' },
{ key: 'in-progress', label: '进行中', color: '#ffc107' },
{ key: 'review', label: '代码审查', color: '#17a2b8' },
{ key: 'testing', label: '测试中', color: '#fd7e14' },
{ key: 'completed', label: '已完成', color: '#28a745' },
{ key: 'cancelled', label: '已取消', color: '#dc3545' }
],
// 优先级配置
priorities: [
{ key: 'low', label: '低', color: '#28a745' },
{ key: 'medium', label: '中', color: '#ffc107' },
{ key: 'high', label: '高', color: '#fd7e14' },
{ key: 'urgent', label: '紧急', color: '#dc3545' }
],
// 任务类型
types: [
{ key: 'feature', label: '功能开发', icon: '' },
{ key: 'bug', label: 'Bug修复', icon: '' },
{ key: 'task', label: '一般任务', icon: '' },
{ key: 'documentation', label: '文档', icon: '' },
{ key: 'deployment', label: '部署', icon: 'deployment' },
{ key: 'maintenance', label: '维护', icon: '' }
]
},
// 自动化规则
automation: {
// 自动分配规则
assignment: {
rules: [
{
condition: 'type:bug AND priority:urgent',
action: 'assign:on-call-engineer'
},
{
condition: 'type:feature AND tag:frontend',
action: 'assign:frontend-team'
}
]
},
// 状态流转规则
transitions: {
'todo -> in-progress': {
requiredFields: ['assignee'],
notifications: ['assignee']
},
'in-progress -> completed': {
requiredFields: ['completion_comment'],
actions: ['close_related_issues']
}
},
// 通知规则
notifications: {
channels: ['email', 'slack', 'webhook'],
events: [
'task_created',
'task_assigned',
'task_completed',
'task_overdue'
]
}
},
// 集成配置
integrations: {
// Git集成
git: {
enabled: true,
branchNaming: 'task/{id}-{slug}',
commitMessage: '#{id}: {title}',
autoClose: true
},
// Slack集成
slack: {
enabled: true,
webhook: process.env.SLACK_WEBHOOK,
channel: '#dev-tasks',
mentions: {
urgent: '@channel',
high: '@here'
}
},
// JIRA同步
jira: {
enabled: false,
url: 'https://company.atlassian.net',
project: 'PROJ',
sync: ['status', 'assignee', 'priority']
}
}
};相关命令
最佳实践
1. 任务粒度控制
- 单个任务工时控制在1-8小时
- 复杂任务拆分为子任务
- 保持任务目标明确
2. 状态管理
- 及时更新任务状态
- 记录阻塞原因和解决方案
- 定期回顾任务进展
3. 团队协作
- 建立清晰的任务模板
- 制定状态流转规范
- 定期进行任务回顾
4. 自动化利用
- 使用模板提高效率
- 设置自动化规则
- 集成开发工具链
task 命令 - 让项目管理井井有条