Complete technical reference for the /next-task workflow.
TL;DR: 12 phases, 13 agents, 3 human interactions (policy, task selection, plan approval). After plan approval, fully autonomous until merged PR.
| Section | Jump to |
|---|---|
| Workflow Phases | All 12 phases explained |
| State Management | tasks.json, flow.json, resume |
| Workflow Enforcement | How gates are enforced |
| Agent Model Allocation | Why opus/sonnet/haiku |
| Cleanup | Success and abort handling |
| Example Flow | Full walkthrough |
Related docs:
- Agent Reference - Detailed agent documentation
- /ship Workflow - The shipping phase in detail
- Slop Patterns - What deslop detects
/next-task is a master orchestrator that takes a task from discovery to merged PR. It coordinates 13 specialized agents across 12 phases with 3 human interaction points.
Why this design: You shouldn't have to ask for the same workflow every session. The orchestrator handles the coordination—launching agents, tracking state, enforcing gates—so you can approve a plan and walk away. Human judgment is only required at meaningful decision points: what to work on, whether the plan is correct, and reviewing the final output. Everything between is automated.
Human interaction: Yes
You configure how the workflow will run:
| Question | Options |
|---|---|
| Task Source | GitHub Issues, GitHub Projects, GitLab Issues, Local tasks.md, Custom source |
| Priority Filter | Bugs, Security, Features, All |
| Stopping Point | Implemented, PR Created, All Green, Merged, Deployed, Production |
Your selection is cached in {state-dir}/sources/preference.json so subsequent runs skip this step.
Agent: task-discoverer (sonnet) Human interaction: Yes
The agent:
- Loads
tasks.jsonto find already-claimed tasks (excludes them) - Fetches tasks from your configured source
- Applies priority scoring based on:
- Labels (bug, security, priority)
- Blockers (blocking other issues)
- Age (older issues score higher)
- Reactions (engagement signals importance)
- Validates tasks against codebase (filters out already-implemented)
- Presents top 5 as checkboxes via AskUserQuestion
- Posts "Workflow Started" comment to the selected GitHub issue
Agent: worktree-manager (haiku) Human interaction: No
The agent:
- Creates
../worktrees/{task-slug}/directory - Creates
feature/{task-slug}branch from main - Claims task in
tasks.json(prevents parallel workflows on same task) - Creates
flow.jsonin worktree for state tracking - Changes working directory to worktree
Agent: exploration-agent (opus) Human interaction: No
The agent:
- Extracts keywords from task title and description
- Searches codebase for related files using Grep and Glob
- Traces dependency graphs
- Analyzes existing patterns and conventions
- Outputs exploration report with:
- Key files identified
- Patterns discovered
- Risks and considerations
- Suggested approach
Agent: planning-agent (opus) Human interaction: No
The agent:
- Synthesizes exploration findings
- Creates step-by-step implementation plan
- Identifies critical paths and risks
- Outputs structured JSON between delimiters:
=== PLAN_START ===
{
"steps": [...],
"files": [...],
"risks": [...],
"complexity": "medium"
}
=== PLAN_END ===
- Posts plan summary to GitHub issue as comment
Human interaction: Yes (last one)
The workflow:
- Enters Plan Mode
- Presents formatted plan from planning-agent
- You can request changes or ask questions
- You approve via ExitPlanMode
After this point, the workflow runs autonomously until delivery.
Agent: implementation-agent (opus) Human interaction: No
The agent:
- Executes approved plan step-by-step
- Creates atomic commits per logical step
- Runs type checks, linting, and tests after each step
- Updates
flow.jsonafter each step (for resume capability)
Restrictions enforced:
- MUST NOT create PR
- MUST NOT push to remote
- MUST NOT invoke review agents (handled by workflow)
Agents: deslop:deslop-agent (sonnet), prepare-delivery:test-coverage-checker (sonnet) Human interaction: No Triggered by: SubagentStop hook after implementation
Both agents run in parallel:
deslop:deslop-agent:
- Analyzes git diff (only new changes)
- Invokes
/desloppipeline - Applies HIGH certainty fixes automatically
- Flags LOW certainty for manual review
prepare-delivery:test-coverage-checker:
- Validates tests exist for new code
- Checks tests are meaningful (not just path matching)
- Advisory only - does not block workflow
Execution: Inline in main orchestrator (uses orchestrate-review skill) Human interaction: No
CRITICAL: The orchestrator MUST spawn multiple parallel reviewer agents. A single generic reviewer is NOT acceptable.
The orchestrator:
- Gets changed files via
git diff --name-only main...HEAD - Detects signals for conditional specialists:
- Database files → database specialist
- API/routes/handlers → api designer
- .tsx/.jsx/.vue/.svelte → frontend specialist
- server/backend/services → backend specialist
- workflows/Dockerfile/k8s → devops reviewer
- 20+ files → architecture reviewer
- MUST spawn 4 core reviewers in parallel (always):
- code quality reviewer
- security reviewer
- performance reviewer
- test coverage reviewer
- Adds conditional specialists based on detected signals
- Each reviewer returns JSON findings:
{file, line, severity, description, suggestion} - Aggregates findings by severity (critical/high/medium/low)
- Fixes all non-false-positive issues
- Commits fixes
- Runs deslop:deslop-agent after each iteration
- Re-reviews changed files with ALL reviewers again
- Repeats until no open issues remain (max 5 iterations)
The loop continues until clean, but stops early if iteration limits or stall detection trigger.
Restrictions enforced:
- MUST NOT create PR
- MUST NOT push to remote
- MUST NOT skip review loop
Agent: prepare-delivery:delivery-validator (sonnet) Human interaction: No
Five checks run:
- Review status - no open issues remaining (or explicit override)
- Tests pass
- Build passes
- Task requirements met (extracts from task description, maps to changes)
- No regressions
On failure: Returns to implementation with fix instructions (automatic retry)
Restrictions enforced:
- MUST NOT create PR
- MUST NOT push
- MUST NOT skip sync-docs:sync-docs-agent
Agent: sync-docs:sync-docs-agent (sonnet) Helper: simple-fixer (haiku) Human interaction: No
The agent:
- Finds documentation referencing changed files
- Updates CHANGELOG with entry
- Updates outdated imports/versions
- Delegates simple mechanical edits to simple-fixer
- Explicitly invokes
/ship(does not rely on hooks alone)
Command: /ship
Agents: ci-monitor (haiku), ci-fixer (sonnet)
Human interaction: No
Full shipping workflow:
- Pushes branch to remote
- Creates pull request
- Monitors CI status (polls every 15 seconds)
- Waits 3 minutes for auto-reviewers
- Addresses ALL comments from ALL reviewers
- Merges when CI passes and all threads resolved
- Cleanup:
- Removes worktree
- Removes task from
tasks.json - Closes GitHub issue with completion comment
- Deletes feature branch
| File | Location | Purpose |
|---|---|---|
tasks.json |
Main project {state-dir}/ |
Active task registry |
flow.json |
Worktree {state-dir}/ |
Workflow phase progress |
| Platform | State Directory |
|---|---|
| Claude Code | .claude/ |
| OpenCode | .opencode/ |
| Codex CLI | .codex/ |
Override with AI_STATE_DIR environment variable.
/next-task --resume # Resume active worktree
/next-task --resume 123 # Resume by task ID
/next-task --resume feature/xyz # Resume by branch nameThe workflow:
- Reads
tasks.jsonto find worktree path - Reads
flow.jsonin worktree for last completed step - Maps step to phase and continues
Step-to-phase mapping:
| Step | Resumes at |
|---|---|
| worktree-created | exploration |
| exploration-completed | planning |
| plan-approved | implementation |
| implementation-completed | pre-review-gates |
| deslop-completed | review-loop |
| review-approved | delivery-validation |
| delivery-validation-passed | docs-update |
| docs-updated | ship |
A SubagentStop hook enforces the workflow sequence. When any agent completes, the hook determines what runs next.
Enforced rules:
- Cannot skip deslop:deslop-agent or prepare-delivery:test-coverage-checker
- Cannot skip Phase 9 review loop
- Cannot skip prepare-delivery:delivery-validator
- Cannot skip sync-docs:sync-docs-agent
- Cannot create PR before
/shipis invoked - Cannot push to remote before
/shipis invoked
| Model | Agents | Why |
|---|---|---|
| opus | exploration-agent, planning-agent, implementation-agent | Complex reasoning, quality-critical phases |
| sonnet | task-discoverer, deslop:deslop-agent, prepare-delivery:test-coverage-checker, prepare-delivery:delivery-validator, sync-docs:sync-docs-agent, ci-fixer | Moderate reasoning, structured tasks |
| haiku | worktree-manager, simple-fixer, ci-monitor | Mechanical execution, no judgment needed |
/ship handles cleanup:
- Removes worktree directory
- Removes task entry from
tasks.json - Closes GitHub issue with completion comment
- Deletes feature branch (via
--delete-branchon merge)
/next-task --abortThe abort:
- Updates
flow.jsonstatus to 'aborted' - Clears active task from
tasks.json - Worktree remains (manual cleanup or run worktree-manager)
User: /next-task
[Policy Selection]
→ Task source? GitHub Issues
→ Priority? Bugs
→ Stop at? Merged
[Task Discovery]
→ Analyzing 47 open issues...
→ Top 5:
1. Fix authentication timeout (#142)
2. Handle empty state in dashboard (#89)
...
→ Which task? [1]
[Worktree Setup]
→ Creating ../worktrees/fix-auth-timeout-142/
→ Branch: feature/fix-auth-timeout-142
[Exploration]
→ Found: src/auth/session.ts, src/middleware/auth.ts
→ Pattern: JWT with 5-minute hardcoded timeout
→ Risk: Tests mock the timeout value
[Planning]
→ Step 1: Extract timeout to config
→ Step 2: Update session.ts
→ Step 3: Update tests
→ Step 4: Add documentation
[User Approval]
→ Plan looks good? [approve]
[Implementation]
→ Implementing step 1... [OK]
→ Implementing step 2... [OK]
→ Implementing step 3... [OK]
→ Implementing step 4... [OK]
[Pre-Review Gates]
→ deslop: Removed 2 console.logs
→ prepare-delivery:test-coverage-checker: 94% coverage [OK]
[Review Loop]
→ Round 1: Found 3 issues (1 high, 2 medium)
→ Fixing high issue... [OK]
→ deslop: Clean [OK]
→ Round 2: Found 0 open issues [OK]
[Delivery Validation]
→ Tests pass [OK]
→ Build passes [OK]
→ Requirements met [OK]
[Docs Update]
→ Updated CHANGELOG.md [OK]
[Ship]
→ Creating PR #156...
→ Waiting for CI...
→ Waiting for reviewers...
→ Addressing 2 comments...
→ Merging PR #156... [OK]
→ Cleanup complete [OK]
Done! PR #156 merged to main.
← Back to Documentation Index | Main README
Related:
- /ship Workflow - The shipping phase in detail
- Agent Reference - All agent documentation
- Slop Patterns - What gets detected and cleaned