Write tasks an agent can finish

The difference between a task that runs overnight and one that wanders is usually a single sentence — the finish line. A short template and examples.

“Improve the upload flow” is a fine thing to say to a colleague over coffee. Given to an agent at 11 pm with nobody watching, it is an invitation to wander: it might refactor the whole module, rename half the functions and stop when it runs out of ideas — or tokens.

Agents are good at reaching a goal. They are much worse at deciding what the goal is. So give them one they can check.

The finish line

A finish line is a condition the agent can verify itself, with a command, before it stops. Compare:

WandersFinishes
Improve upload error handlingnpm test -- upload passes, including a new test for a 503 response that retries twice
Make the settings page fasterThe settings page renders in under 100 ms in npm run bench:settings
Clean up the date utilssrc/utils/date.ts has no any, npm run typecheck passes, behavior unchanged — all existing tests green
Fix the flaky testupload.retry.test.ts passes ten runs in a row with npm test -- --repeat 10

The right column is longer. That’s the point: the extra words are the ones the agent would otherwise have to guess.

Anthropic’s guidance for Claude Code makes the same argument from the other side: an agent that can check its own work — with a test, a build, a screenshot — does far better than one that has to guess whether it is done, and the single most useful line in an instructions file is the command that runs the tests. A finish line is that idea applied to one task.

A template

Task template
Goal: <one sentence, the outcome, not the activity>

Done when:
- <a command that must pass>
- <a second check, if any>

Scope:
- Only change files in <folder or module>.
- Do not modify, skip or delete existing tests.

Context:
- <the one thing a newcomer wouldn't know>

Four parts, each with a job:

  • Goal keeps the agent pointed in one direction.
  • Done when gives it a way to stop. Without it, agents either stop too early (“I have made the changes”) or too late (“I also refactored…”).
  • Scope keeps the diff reviewable and makes integrity problems less likely.
  • Context saves the agent from rediscovering what you already know — and saves you the tokens.

A worked example

Here is a real-world shaped task, first as it usually gets written:

Before
The upload sometimes fails on slow connections. Can you make it more robust?

An agent can do a lot with this, and most of it won’t be what you wanted: a new retry library, a rewritten progress bar, a changed timeout everywhere. Now the same task with a finish line:

After
Goal: uploads survive a single 503 from the storage API.

Done when:
- npm test -- upload passes.
- A new test "retries once on 503, then succeeds" exists and passes.
- npm run typecheck passes.

Scope:
- Only change src/upload/ and its tests.
- Do not modify, skip or delete existing tests.
- No new dependencies.

Context:
- The storage client is in src/upload/client.ts; it already has a retry
  helper (withRetry) that the upload path doesn't use yet.

The second version takes two minutes longer to write. In exchange you get a diff you can review in five, a test that will catch the bug if it comes back, and an agent that knows when to stop.

Finish lines by kind of work

Different work needs different evidence. These have worked well:

Kind of taskA finish line that holds
Bug fixA new test reproduces the bug, failed before the change and passes after it
RefactorType checker and the full existing suite pass; public functions keep their signatures
PerformanceA benchmark command reports a number below a threshold, on the same machine, three runs in a row
Dependency upgradeInstall from the lock file, build and tests pass; no source changes outside the call sites the upgrade requires
DocumentationEvery code sample in the changed pages runs; links checked by a link checker
MigrationThe migration runs forward and back on a disposable database; tests pass after both

Notice what the column has in common: every line is something a command can decide. “The code is cleaner” is not on the list, because nobody can check it at 3 am.

Make the checks real

A finish line only works if the command exists and works on the starting commit. Before you queue a task overnight, run the command yourself once. If it fails for unrelated reasons, the agent will spend its attempts on the wrong problem.

PaneScale helps here: the autopilot runs your checks on the starting commit first — the baseline — so failures that were already there don’t count. The autopilot preflight refuses to start a night without at least one required check, because “ready” has to be proven.

Mistakes that look like finish lines

Some conditions look checkable but aren’t useful:

  • “All tests pass.” True, but it is the line most easily met by deleting or skipping tests. Name the test that matters, and say that existing tests must not be touched.
  • “No errors in the console.” Which console, which page, which browser? Turn it into a command — a test that loads the page and fails on errors.
  • Lines that depend on the outside world. A finish line that needs a live API or a flaky network turns every failure into a guessing game. Mock it, or record a fixture.
  • Five goals in one task. If the “Done when” list covers unrelated things, it is five tasks. Split them, so one failure doesn’t block four successes.

Split what can’t be finished

Some tasks don’t have a finish line yet — “design a better onboarding” is a conversation, not a task. Have that conversation in Chat or with a teammate in Plan mode, write down the result, and turn each piece into a task with its own finish line. Then queue those.

A useful size test: a task is small enough when its diff can be reviewed in about ten minutes. Larger than that, and you will either skim the review or spend the time you saved.

A quick test

Before handing a task to an agent, ask: if I came back in four hours, could I tell in one minute whether it’s done? If the answer is yes, it’s ready to go.

Questions about finish lines

What if my project has no tests?

Then the first task is to write one. Ask an agent to add a test that reproduces the bug or covers the function you want changed, review it yourself, and commit it. From then on the test is the finish line for every task in that area. A type check, a build or a linter is a weaker but still useful finish line in the meantime.

How long should a task description be?

Long enough that nothing important is left to guess, short enough to read in a minute. In practice that is five to fifteen lines. If it grows beyond that, the task is probably several tasks.

Should the finish line be in the instructions file or the task?

Both, at different levels. The instructions file (AGENTS.md, CLAUDE.md) holds what is always true: how to run the tests, what never to touch. The task holds what is true for this change: which test must pass and which folder is in scope.

Sources

More articles

Five ways an agent can fake a green build

Agents rarely cheat on purpose, but under pressure to make tests pass they find shortcuts. Here is what to look for — and what PaneScale flags automatically.

Bypass mode: a decision table

Skipping an agent’s permission prompts saves hours — and occasionally costs a lot more. When it is reasonable, and what to put in place first.

Every run should leave a receipt

When agents work in multi-step workflows, “it worked” isn’t enough. What a run record should contain, and how PaneScale’s workflow runs provide it.