1.6 Task decomposition strategies
| Pattern | Shape | Use when |
|---|---|---|
| Prompt chaining (fixed sequential pipeline) | Step 1 → Step 2 → Step 3, known in advance | Predictable multi-aspect work: per-file review then a cross-file integration pass |
| Dynamic adaptive decomposition | Subtasks generated from what each step discovers | Open-ended investigation: "add comprehensive tests to a legacy codebase" |
Prompt chaining for reviews
Split a large code review into per-file local analysis passes plus a separate cross-file integration pass. This is the answer to inconsistent depth, missed obvious bugs, and contradictory findings across a 14-file PR — the root cause is attention dilution, not context window size.
pass 1..n : file_i in isolation -> local issues, consistent depth
pass n+1 : all files, data-flow lens -> cross-file integration issues
Dynamic decomposition for open-ended work
For "add comprehensive tests to a legacy codebase":
- Map structure — what modules exist, what is already covered.
- Identify high-impact areas — critical paths, churn, defect history.
- Create a prioritized plan that adapts as dependencies are discovered.
Fixing the subtask list up front, before mapping, is the anti-pattern here.
Quiz
- Question 1
A developer asks the agent to "add comprehensive tests to this legacy service": 60k lines, no existing tests, and a dependency structure nobody on the current team has mapped. Which decomposition strategy fits the task?
- Question 2
Your CI review makes one pass over the whole pull request. Under five files the results are strong; above that the feedback thins out, misses obvious bugs, and contradicts itself — flagging a pattern in one file that it approves in another. The team wants predictable coverage of three aspects, security, error handling and test coverage, on every PR regardless of size. Which decomposition fits?
- Question 3
Two requests arrive. The first: "Summarise the last four quarterly reports of these six companies against the same five metrics." The second: "Work out why margin compression happened in Q3." Which decomposition suits each?
- Question 4
A single prompt asks Claude to refactor a 2,000-line module, add tests, and update the documentation in one pass. The refactor is good; the tests cover the pre-refactor interface; the documentation describes a mixture of both. What decomposition fixes this?
Links
- https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
- https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/overview
- https://code.claude.com/docs/en/agent-sdk/subagents
- https://www.anthropic.com/engineering/building-effective-agents