Skip to content
Visual explainer 3h to learn 5 steps

Hand off a scoped task to a coding agent

Write a scoped plan with review checkpoints for an agent task and stop or roll back the change when validation fails.

By Invicly Tech, , in Prompt Engineering and Vibe Coding. About 10 minutes to read.

Topic 23 of 29

In short

Handing a task to a coding agent works best when you write a small, clear plan first. Say what to change, what not to touch and how you will check it. Keep the work on its own branch or worktree, review at set points, and stop and roll back if validation fails.

Think of it like this: It is like asking a colleague to paint one room: you name the room, the colour and the checkpoint, and you can easily paint over it if it looks wrong.

Explained simply

Handing work to an agent is like giving a task to a new teammate. If you say 'make the app better', you will get surprises. If you say exactly what to change, what to leave alone and how you will check it, you will get something you can review.

So write a short plan before you start. It has a goal, a list of files that are allowed to change, a list of things that are out of scope and the checks that must pass. This takes five minutes and saves hours of cleanup.

Next, protect your own work. Create a new branch, or a separate worktree, which is a second folder tied to the same repository. The agent works there. Your main folder stays clean, and you can throw the whole thing away if it goes badly.

Finally, set checkpoints. After each small step, read the diff and run the checks. If a check fails and you do not know why, stop. If you already merged the change, git revert makes a new commit that cancels it.

Press Play on a diagram to walk through it one step at a time.

FlowA safe handoff
  1. 1
    Plan

    Goal, files in scope, out of scope, checks

  2. 2
    Isolate

    Create a branch or worktree

  3. 3
    Run

    Agent works in small steps

  4. 4
    Review

    You read the diff at each checkpoint

  5. 5
    Merge or revert

    Pass the checks or undo the change

CycleThe review checkpoint loop
  1. 1
    Small step

    Agent makes one change

  2. 2
    Diff

    You read exactly what changed

  3. 3
    Checks

    Tests, lint and types run

  4. 4
    Decide

    Continue, adjust the plan or stop

  5. Back to step 1

In depth

What a good task plan contains

A plan has five parts. The goal says what should be true when you are done. The scope lists the files or folders the agent may change. The out-of-scope list names what it must not touch, such as database migrations or CI config. The checks are the commands that prove success, for example npm test and npm run lint. The checkpoints say when you will review.

Write the goal as something you can test. 'Prices show two decimals' is testable. 'Make prices nicer' is not. If the agent is cloud based, such as GitHub's cloud agent, the same plan goes into the issue or task description.

  • Goal you can test
  • Files in scope
  • Out of scope list
  • Check commands
  • Review checkpoints
CompareVague and scoped task
Vague
  • Improve the shop code
  • No file limits
  • No checks named
  • Review only at the end
Scoped
  • Format prices with two decimals
  • Only src/format.ts and its test
  • npm test and npm run lint must pass
  • Review after each commit

Isolate with a branch or worktree

A branch keeps the agent's commits apart from main. A worktree goes one step further: git worktree add creates a second working folder with its own branch, so you can keep editing in your main folder while the agent works in the other. Both share one repository, so there is no second clone to keep in sync.

When you are done, merge the branch or throw it away. Remove a finished worktree with git worktree remove. Nothing the agent did can leak into your main folder unless you merge it.

  • Branch: separate commits
  • Worktree: separate folder too
  • Discard by deleting the branch
  • git worktree remove for cleanup

Stop when validation fails

Validation means tests, linting and type checks. If they fail, the first question is why. An agent that sees a failing test may change the test to make it pass, or add workarounds on top of a bad change. That hides the cause.

A simple rule helps: one failure, one look. Read the failure yourself. If the cause is clear and small, let the agent fix it. If it is unclear, stop the run, keep the branch for evidence and decide whether to revise the plan or start again. Never merge on red.

Roll back with git revert

If a bad change is only on your branch, you can delete the branch. If it was merged or pushed, use git revert. It creates a new commit that does the opposite of an earlier one, so history stays honest and other people's copies stay valid. git reset would rewrite history, which causes trouble on shared branches.

For a merge commit you must tell git which side to keep with the -m option, usually git revert -m 1 the merge SHA. After a revert, run the checks again to confirm you are back to a good state.

  • Unmerged: delete the branch
  • Merged: git revert SHA
  • Merge commit: git revert -m 1 SHA
  • Run checks after the revert
SequenceRevert after a failed release
You
Git
Checks
  1. 1git revert SHA
    You to Git: git revert SHA
  2. 2New commit that cancels the change
    Git to You: New commit that cancels the change
  3. 3Run npm test and npm run lint
    You to Checks: Run npm test and npm run lint
  4. 4All green again
    Checks to You: All green again

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Write a scoped task plan~35m
  2. 2
    Set review checkpoints~35m
  3. 3
    Isolate work on a branch or worktree~35m
  4. 4
    Stop when validation fails~35m
  5. 5
    Roll back with git revert~35m

Key points

  • A task plan names the goal, the files in scope, what is out of scope and the checks that prove it works.
  • Break big tasks into small steps with a review checkpoint after each one.
  • Work on a branch, or in a separate worktree, so your main work stays untouched.
  • If tests, linting or a type check fail and the cause is unclear, stop. Do not let the agent pile more changes on a broken base.
  • Use git revert to undo a commit that is already shared. It adds a new commit and keeps history intact.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
git worktree add ../shop-agent -b agent/format-price
# agent works in ../shop-agent; you review the diff
git -C ../shop-agent diff --stat
# if validation fails and you merged it:
git revert <commit-sha>
# cleanup
git worktree remove ../shop-agent

Isolate the work, review, then undo or clean up.

A scoped plan and a worktree

Task: format prices in a demo shop. Step 1: write the plan with scope src/format.ts and src/format.test.ts only. Step 2: create a worktree on a new branch. Step 3: hand the plan to the agent. Step 4: after each commit, read the diff and run the checks. Evidence: only the two files changed, the tests pass. Cleanup: merge or remove the worktree and delete the branch.

bash
git worktree add ../shop-agent -b agent/format-price
cd ../shop-agent
# agent works here; review each commit
git diff --stat main...HEAD
npm test && npm run lint
# cleanup when done
cd ../shop && git worktree remove ../shop-agent
git branch -D agent/format-price

Stopping on a failure and reverting

The agent's change passes locally but a later check fails, and you already merged it to a practice branch. Step 1: stop the agent and read the failing output. Step 2: find the commit that caused it with git log. Step 3: revert it. Step 4: rerun the checks. Step 5: write a note in the plan about why it failed before you try again.

bash
git log --oneline -5
git revert <commit-sha>
npm test
git log --oneline -3   # the revert is a new commit

Quick reference

  • A task plan: goal, files in scope, out of scope, checks, checkpoints.
  • Write goals you can test, not goals like 'make it nicer'.
  • git worktree add ../dir -b branch gives the agent its own folder.
  • Review the diff after every small step.
  • Never merge on red; stop when a failure cause is unclear.
  • Shared history: git revert SHA. Merge commit: git revert -m 1 SHA.
  • Clean up with git worktree remove and git branch -D.

Common mistakes

  • A vague task such as 'improve the app' with no scope and no check.
  • Letting an agent keep going after a failed test, which hides the original cause.
  • Using git reset on shared history instead of git revert.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which is the best goal for an agent task?

Question 2

2What does git worktree add give you beyond a branch?

Question 3

3Tests fail and the cause is unclear. What should you do?

Question 4

4Why prefer git revert over git reset on a shared branch?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Rewrite 'tidy the app' as a scoped task with a goal, one file in scope and one check.

  2. Exercise 2medium

    Create a worktree on a new branch, make a one-line change, then remove the worktree and branch cleanly.

  3. Exercise 3hard

    In a throwaway repo, let an agent make a change with a deliberate failing check. Stop, record the failure, revert the commit and show the checks pass again.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need a worktree, or is a branch enough?
A branch is enough for most tasks. A worktree helps when you want to keep working in your main folder while the agent runs.
What if the agent changes files outside my scope?
Review the diff, discard those changes and tighten the plan. Out-of-scope edits are a sign the plan was too loose.
Is git revert the same as git reset?
No. Revert adds a new commit that undoes an old one. Reset moves the branch pointer and can rewrite history, which is risky on shared branches.

Go deeper

ShareXLinkedInWhatsApp