task-dependency-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Task Dependency Patterns

任务依赖模式

Overview

概述

Claude Code 2.1.16 introduces a native Task Management System with four tools:
  • TaskCreate: Create new tasks with subject, description, and activeForm
  • TaskUpdate: Update status (pending → in_progress → completed), set dependencies
  • TaskGet: Retrieve full task details including blockers
  • TaskList: View all tasks with status and dependency summary
Tasks enable structured work tracking, parallel coordination, and clear progress visibility.
Claude Code 2.1.16 引入了原生任务管理系统,包含四个工具:
  • TaskCreate:创建包含主题、描述和activeForm的新任务
  • TaskUpdate:更新状态(pending → in_progress → completed),设置依赖关系
  • TaskGet:检索包含阻塞项的完整任务详情
  • TaskList:查看所有任务的状态和依赖关系摘要
任务支持结构化工作跟踪、并行协调以及清晰的进度可视化。

When to Use

适用场景

  • Breaking down complex multi-step implementations
  • Coordinating parallel work across multiple files
  • Tracking progress on large features
  • Managing dependencies between related changes
  • Providing visibility into work status
  • 拆分复杂的多步骤实现工作
  • 协调跨多个文件的并行工作
  • 跟踪大型功能的开发进度
  • 管理相关变更之间的依赖关系
  • 提供工作状态的可视化

Key Patterns

核心模式

1. Task Decomposition

1. 任务分解

Break complex work into atomic, trackable units:
Feature: Add user authentication

Tasks:
#1. [pending] Create User model
#2. [pending] Add auth endpoints (blockedBy: #1)
#3. [pending] Implement JWT tokens (blockedBy: #2)
#4. [pending] Add auth middleware (blockedBy: #3)
#5. [pending] Write integration tests (blockedBy: #4)
将复杂工作拆解为原子化、可追踪的单元:
Feature: Add user authentication

Tasks:
#1. [pending] Create User model
#2. [pending] Add auth endpoints (blockedBy: #1)
#3. [pending] Implement JWT tokens (blockedBy: #2)
#4. [pending] Add auth middleware (blockedBy: #3)
#5. [pending] Write integration tests (blockedBy: #4)

2. Dependency Chains

2. 依赖链

Use
addBlockedBy
to create execution order:
json
// Task #3 cannot start until #1 and #2 complete
{"taskId": "3", "addBlockedBy": ["1", "2"]}
使用
addBlockedBy
来创建执行顺序:
json
// Task #3 cannot start until #1 and #2 complete
{"taskId": "3", "addBlockedBy": ["1", "2"]}

3. Status Workflow

3. 状态工作流

pending → in_progress → completed
   ↓           ↓
(unblocked)  (active)

pending/in_progress → deleted (CC 2.1.20)
  • pending: Task created but not started
  • in_progress: Actively being worked on
  • completed: Work finished and verified
  • deleted: Task removed (CC 2.1.20) - permanently removes the task
pending → in_progress → completed
   ↓           ↓
(unblocked)  (active)

pending/in_progress → deleted (CC 2.1.20)
  • pending:任务已创建但未启动
  • in_progress:任务正在进行中
  • completed:工作已完成并验证
  • deleted:任务已移除(CC 2.1.20)——永久删除任务

Task Deletion (CC 2.1.20)

任务删除(CC 2.1.20)

CC 2.1.20 adds
status: "deleted"
to permanently remove tasks:
json
// Delete a task
{"taskId": "3", "status": "deleted"}
When to delete:
  • Orphaned tasks whose blockers have all failed
  • Tasks superseded by a different approach
  • Duplicate tasks created in error
  • Tasks from a cancelled pipeline
When NOT to delete:
  • Tasks that might be retried later (keep as pending)
  • Tasks with useful history (mark completed instead)
  • Tasks blocked by in_progress work (wait for resolution)
CC 2.1.20 新增
status: "deleted"
用于永久移除任务:
json
// Delete a task
{"taskId": "3", "status": "deleted"}
删除场景:
  • 所有阻塞项均失败的孤立任务
  • 被其他方案取代的任务
  • 错误创建的重复任务
  • 已取消的流水线中的任务
不建议删除的场景:
  • 可能稍后重试的任务(保留为pending状态)
  • 包含有用历史记录的任务(标记为completed即可)
  • 被in_progress状态的工作阻塞的任务(等待解决)

4. activeForm Pattern

4. activeForm模式

Provide present-continuous form for spinner display:
subject (imperative)activeForm (continuous)
Run testsRunning tests
Update schemaUpdating schema
Fix authenticationFixing authentication
提供现在进行时形式用于加载动画显示:
subject (imperative)activeForm (continuous)
Run testsRunning tests
Update schemaUpdating schema
Fix authenticationFixing authentication

Agent Teams (CC 2.1.33+)

Agent Teams(CC 2.1.33+)

CC 2.1.33 introduces Agent Teams for multi-agent coordination with shared task lists and peer-to-peer messaging.
CC 2.1.33 引入了Agent Teams,用于多Agent协调,支持共享任务列表和点对点消息传递。

Team Workflow

团队工作流

1. TeamCreate("my-feature")           → Creates team + shared task list
2. TaskCreate(subject, description)    → Add tasks to shared list
3. Task(prompt, team_name, name)       → Spawn teammates
4. TaskUpdate(owner: "teammate-name")  → Assign tasks
5. SendMessage(type: "message")        → Direct teammate communication
6. SendMessage(type: "shutdown_request") → Graceful shutdown
1. TeamCreate("my-feature")           → 创建团队 + 共享任务列表
2. TaskCreate(subject, description)    → 向共享列表添加任务
3. Task(prompt, team_name, name)       → 生成团队成员
4. TaskUpdate(owner: "teammate-name")  → 分配任务
5. SendMessage(type: "message")        → 与团队成员直接沟通
6. SendMessage(type: "shutdown_request") → 优雅关闭

When to Use Teams vs Task Tool

何时使用团队 vs 任务工具

CriteriaTask Tool (subagents)Agent Teams
Independent tasksYesOverkill
Cross-cutting changesLimitedYes
Agents need to talkNo (star topology)Yes (mesh)
Cost sensitivityLower (~1x)Higher (~2.5x)
Complexity < 3.0YesNo
Complexity > 3.5PossibleRecommended
评估标准任务工具(子Agent)Agent Teams
独立任务大材小用
跨模块变更有限支持
Agent需要沟通否(星型拓扑)是(网状拓扑)
成本敏感度较低(约1倍)较高(约2.5倍)
复杂度 < 3.0
复杂度 > 3.5可行推荐

Team Task Patterns

团队任务模式

undefined
undefined

Spawn teammate into shared task list

Spawn teammate into shared task list

Task( prompt="You are the backend architect...", team_name="my-feature", name="backend-architect", subagent_type="backend-system-architect" )
Task( prompt="You are the backend architect...", team_name="my-feature", name="backend-architect", subagent_type="backend-system-architect" )

Teammate claims and works tasks

Teammate claims and works tasks

TaskList → find unblocked, unowned tasks TaskUpdate(taskId, owner: "backend-architect", status: "in_progress")
TaskList → find unblocked, unowned tasks TaskUpdate(taskId, owner: "backend-architect", status: "in_progress")

... do work ...

... do work ...

TaskUpdate(taskId, status: "completed") TaskList → find next task
undefined
TaskUpdate(taskId, status: "completed") TaskList → find next task
undefined

Peer Messaging

点对点消息传递

undefined
undefined

Direct message between teammates

Direct message between teammates

SendMessage(type: "message", recipient: "frontend-dev", content: "API contract ready: GET /users/:id returns {...}", summary: "API contract shared")
SendMessage(type: "message", recipient: "frontend-dev", content: "API contract ready: GET /users/:id returns {...}", summary: "API contract shared")

Broadcast to all (use sparingly)

Broadcast to all (use sparingly)

SendMessage(type: "broadcast", content: "Breaking change: auth header format changed", summary: "Breaking auth change")
undefined
SendMessage(type: "broadcast", content: "Breaking change: auth header format changed", summary: "Breaking auth change")
undefined

Anti-Patterns

反模式

  • Creating tasks for trivial single-step work
  • Circular dependencies (A blocks B, B blocks A)
  • Leaving tasks in_progress when blocked
  • Not marking tasks completed after finishing
  • Using broadcast for messages that only concern one teammate
  • Spawning teams for simple sequential work (use Task tool instead)
  • 为琐碎的单步骤工作创建任务
  • 循环依赖(A阻塞B,B阻塞A)
  • 任务被阻塞时仍处于in_progress状态
  • 完成后不标记任务为completed
  • 针对单个团队成员的消息使用广播
  • 为简单的顺序工作创建团队(改用任务工具即可)

Related Skills

相关技能

  • worktree-coordination
    - Multi-instance task coordination across git worktrees
  • implement
    - Implementation workflow with task tracking and progress updates
  • verify
    - Verification tasks and completion checklists
  • fix-issue
    - Issue resolution with hypothesis-based RCA tracking
  • brainstorming
    - Design exploration with parallel agent tasks
  • worktree-coordination
    - 跨Git工作树的多实例任务协调
  • implement
    - 带有任务跟踪和进度更新的实现工作流
  • verify
    - 验证任务和完成检查清单
  • fix-issue
    - 基于假设的根因分析跟踪的问题解决
  • brainstorming
    - 带有并行Agent任务的设计探索

References

参考资料

  • Dependency Tracking
  • Status Workflow
  • Multi-Agent Coordination
  • Dependency Tracking
  • Status Workflow
  • Multi-Agent Coordination