Skip to content

Chain the steps or let the plan adapt

Identify which property of a task calls for a fixed prompt chain or adaptive decomposition, and order the steps of a per-file plus cross-file review and of an adaptive investigation plan.

Scenario

Your Claude Code for Continuous Integration job reviews every pull request in one prompt. On a 34-file PR it writes careful comments on the first few files, one-liners on the rest, and misses that pricing.ts renamed applyDiscount while invoice.ts still calls the old name.

The model was not careless. It was given one task too big to attend to evenly, and no step whose job was to look between files.

Explanation

Large tasks go better in pieces. The question is who decides the pieces, and when.

Fixed sequential pipeline (prompt chaining). You write the steps down before you see the input. Each call handles one smaller task and passes its output to the next, and you can add a check between steps. It suits work that splits cleanly into the same subtasks every time, such as a review that always checks the same aspects. Each step is easier, so accuracy goes up, at the cost of more calls.

Dynamic adaptive decomposition. The subtasks can't be predicted; they depend on what each step finds. The agent (or an orchestrator) generates the next subtasks from intermediate findings. It suits open-ended investigation: debugging, exploring a system nobody has mapped, a change whose reach is unknown.

The test: could you list every step before seeing the input? If yes, chain. If the next step depends on what the last one found, adapt. File count and stakes don't decide it.

Large code reviews: per-file passes plus a cross-file pass. One pass over many files dilutes attention: depth is uneven, and nothing checks how files interact. Split it:

  1. A local pass per file: logic, error handling, tests for that file alone.
  2. A separate cross-file integration pass whose only job is interactions: renamed or changed signatures, data contracts, call sites. Feed it what it needs for that, such as each file's changed interfaces, rather than every full diff again.

Open-ended tasks: map, prioritize, adapt. For a task like "add comprehensive tests to a legacy codebase", don't start writing tests file by file. First map the structure, then identify the high-impact areas, then write a prioritized plan, and revise it as dependencies turn up.

Worked example

Before: one CI step.

Review this pull request for bugs, security issues and style. Here is the full diff of all 34 files.

After: a fixed chain, because every PR review has the same parts.

Step 1, once per changed file: review this file's diff for logic errors, missing error handling and missing tests. Also list every exported function, type or schema whose signature changed.
Step 2, once per PR: here are the changed interfaces from step 1, and the files that import them. Report only cross-file problems: callers of changed signatures, broken contracts, mismatched types.
Step 3: merge the findings from steps 1 and 2, remove duplicates, and post one review comment grouped by file.

Each per-file call has one file to attend to. Step 2 is where the applyDiscount rename gets caught, because it has nothing else to do.