InterviewKata
AI engineering · Module 08b · Level 2: Working with AI

Background and parallel agents

Module 08 had you working with one agent in one session, watching it work. Every major coding agent can now also work in the background: you hand over a task, close your laptop, and come back to a pull request. Many engineers run several at once. This module shows how to do that well with any agent, which tasks to hand over, how to write the brief, and why your review, not the number of agents, sets the pace.

A 5-minute conversation: Sam asks, Priya explains
0:00 / 4:38

1. The idea

A site manager renovating a house. Instead of doing every job themselves, they give each crew a written work order for one room: what to do, what not to touch, and how it will be inspected. The crews work at the same time, in separate rooms, so they don't trip over each other. The manager answers questions when they come up, and inspects each room before signing it off. Hire more crews than one person can inspect, and finished rooms just pile up waiting.

A background agent works on a task without you watching each step. You describe the task, it works in its own copy of the code, and it hands back a pull request. Run several on independent tasks and you have parallel agents. Words you'll need:

TermMeaning
Foreground agentThe interactive session from Module 08: you watch, steer and approve as it goes.
Git worktreeA second (third, fourth…) working folder for the same repository, each on its own branch. Agents in different worktrees can't overwrite each other's files.
Cloud agentAn agent that runs on a remote machine (a VM or sandbox) prepared with your repository and tools. It keeps going when your laptop sleeps.
Task briefThe written work order: goal, context, constraints, and how to know it's done.
Hand-offHow work comes back: a branch and a pull request, with its checks, ready for review (Module 13a).

2. How it works

Three briefs, three agents working at once, each in its own copy of the code. Questions come back to you when they come up; every result comes back as a pull request through the same checks. Your review is the last step for all of them.

On your own machine, the tool that keeps parallel agents apart is git worktrees. They're plain git, so they work with every agent:

A background agent can't ask you to clarify every few minutes, so the brief does the work a conversation would. Compare a vague brief with a good one:

Set up the environment firstAn agent that can't install dependencies, run the tests or reach the services it needs can't check its own work, so it guesses. Cursor's documentation calls environment setup "the most important step" for cloud agents. Every cloud agent has a setup script or image: invest in it once, and every task benefits.

3. Try it yourself

Hand it over?

For each task, decide: hand it to a background agent now, write a brief (or spec) first, or keep it in an interactive session where you can steer.

    How many agents?

    More agents produce more pull requests, but somebody has to review them. Move the sliders and watch where the bottleneck moves.

    4. Why it matters at work

    Background agents are good at work that is well defined, easy to verify and doesn't overlap with other work. They are poor at work where the hard part is deciding what to do.

    Good to hand overKeep interactive (or spec it first)
    Tests for existing code; a bug with a reproduction; dependency upgrades; docs; a mechanical change across many files; fixing CI failures on a PRNew design decisions; vague features; changes that touch many teams' code; security-sensitive work; anything you can't easily check

    Best practices

    PracticeWhy
    One task, one branch, one pull requestSmall, reviewable results; Copilot's cloud agent enforces exactly this.
    Write the brief like a work orderGoal, links to context, constraints, "done when", and how to verify. A spec (Module 08a) for anything bigger.
    Pick independent tasksTwo agents editing the same files means merge conflicts and wasted work.
    Prepare the environmentDependencies, test commands and services ready, so the agent can run its own checks (Module 12a).
    Sandbox by defaultThoughtworks' Radar (Trial, April 2026): isolated file system, controlled network, bounded resources, "a sensible default rather than an optional enhancement". No production secrets.
    Match parallelism to review capacityUnreviewed pull requests are inventory, not progress. Start with two or three agents.
    Time-box and budgetLimits on minutes, turns and cost per task; parallel sessions share your plan's rate limits.
    Same checks as everyoneEvery agent PR goes through CI and review (Module 13a), with a named owner.

    The portable recipe

    On your machine: one worktree per task, any agent in each. AGENT_CMD is your tool's headless command (Module 13).

    #!/usr/bin/env bash
    # run-tasks.sh: one worktree and one background agent per task brief in tasks/*.md
    AGENT_CMD="${AGENT_CMD:-claude -p}"   # or "codex exec", "copilot -p", "agent -p", "agy -p"
    for brief in tasks/*.md; do
      name=$(basename "$brief" .md)
      git worktree add "../wt-$name" -b "agent/$name"          # a separate folder and branch
      ( cd "../wt-$name" &&
        $AGENT_CMD "$(cat "$OLDPWD/$brief") Run ./scripts/check before finishing. Commit your work." \
          > "agent.log" 2>&1 &&
        git push -u origin "agent/$name" &&
        gh pr create --draft --fill ) &                            # each runs in the background
    done
    wait   # then review the draft PRs; remove a worktree with: git worktree remove ../wt-NAME
    # tasks/upgrade-date-lib.md: a brief that works without a conversation
    Goal: upgrade date-fns from 2.x to 3.x.
    Context: docs/dependencies.md; the breaking changes list at the date-fns changelog.
    Constraints: no behaviour changes; don't touch src/billing/ (owned by another team).
    Done when: ./scripts/check passes and no date-fns 2.x imports remain.
    If unsure: stop and write your question at the top of the PR description.

    In CI instead, the same brief can start a job (for example a GitHub Actions workflow triggered by an issue label) that runs AGENT_CMD on a fresh runner and opens a draft PR. That is roughly what the built-in cloud agents do for you, with a prepared environment.

    The honest caveatsParallel agents multiply cost and share your plan's rate limits. They also multiply review: the bottleneck moves from writing code to reading it, and rushed review is how bad changes get in. Overlapping tasks produce merge conflicts. And more isn't always better: Thoughtworks' Radar puts "coding agent swarms" (many agents with little structure) in Caution, while "team of coding agents" with clear roles is in Assess (Module 16a). Start with a few independent, well-briefed tasks and measure how many PRs you merge, not how many agents you run.

    5. In your five tools

    Every tool can run agents away from your screen; they differ in where. Git worktrees plus the headless command work locally with all of them. Checked 31 October 2026.

    ToolBackground or cloud agentsParallel on your machine
    GitHub CopilotCloud agent: assign work from an issue, a pull request, the Copilot panel or a repository's Agents tab. Runs in GitHub Actions (59-minute limit per session) or a cloud sandbox; one branch and one pull request per task. "Watch and fix" works on failed checks and merge conflictscopilot -p in separate worktrees
    Claude CodeCloud sessions from the browser, the app or claude --cloud "task"; each runs in its own VM and keeps going when your laptop is closed. --teleport pulls one back to your terminal; Auto-fix watches a PR for failed checks and review commentsclaude --worktree NAME starts an isolated session in its own worktree
    CodexCodex cloud: tasks start from a published environment; "each task has its own workspace and can keep working while your computer is asleep". Review the diff, ask for changes, then open a PRcodex exec in separate worktrees
    CursorCloud Agents in isolated VMs, as many in parallel as you like; start them from the desktop app, the web, Slack, Linear, a GitHub comment (@cursor) or the API. Environment in .cursor/environment.json or a Dockerfile; can open PRs across several repositoriesagent -p in separate worktrees
    Antigravity CLIBackground subagents for long builds, searches and multi-file edits; the /agents panel shows each one's state, /tasks tracks background commands. In the app, a subagent can get its own git worktreeagy -p in separate worktrees

    6. Remember it

    Memory hook: "Work orders, separate rooms, one inspector"Write a clear work order, give each crew its own room, and remember that every room still goes past one inspector: you.
    How this hook works: what “Work orders, separate rooms, one inspector” means

    What the slogan means, phrase by phrase

    “Work orders”
    The task brief: goal, context, constraints, done-when. It replaces the conversation you won't be having.
    “separate rooms”
    A worktree, branch or sandbox per agent, and tasks that don't overlap.
    “one inspector”
    Your review. It caps how many agents are worth running.

    Why this picture fits: renovation crews work in parallel only because each has its own room and a written job; and a building isn't finished until it passes inspection.

    The story → the concept

    RenovationBackground agents
    Work orderTask brief or spec
    A crewOne agent
    Its own roomA git worktree or cloud sandbox, on its own branch
    Tools and materials on siteThe prepared environment
    Room ready for inspectionA pull request with green checks
    The inspectorYou (plus the checks in Module 13a)

    The trap it saves you from

    Hiring more crews than you can inspect. Ten agents and one hour of review a day means a growing pile of unreviewed pull requests, and a temptation to approve them without reading.

    7. Common mistakes

    A one-line brief"Fix the date bug" leaves the agent to guess which bug, which fix and when it's done. Write the work order.
    Overlapping tasksTwo agents in the same files produce conflicts and duplicate work. Split by area, or run them one after the other.
    No working environmentIf the agent can't run the tests, it can't check its work. Fix the setup script before adding agents.
    More agents than reviewsUnreviewed pull requests aren't progress. Size parallelism to your review time.
    Secrets in the sandboxA background agent reading issues or web pages can be prompt-injected. No production credentials; restrict network access (Module 18).
    No limitsAn agent stuck in a loop for hours burns budget and rate limits for everyone. Time-box every task.
    Forgetting the clean-upOld worktrees and stale agent branches pile up. Remove them when the PR merges or closes.

    8. Hands-on lab (roadmap week 8)

    1. Pick three small, independent tasks from your backlog: for example a test gap, a dependency bump and a docs fix.
    2. Write a brief for each with goal, context, constraints, done-when and "if unsure".
    3. Run them in parallel locally: one git worktree each, tool A in all three (or the script above).
    4. Run one in the cloud with your tool's cloud agent, and compare the experience.
    5. Review all four PRs and time yourself. Which brief produced the best result, and why?
    6. Find your number: using your real review times in the calculator above, how many agents are worth running for you?

    9. Self-check quiz

    How do you stop two local agents from overwriting each other's files?

    A worktree is a separate folder on its own branch; edits can't collide. Two tabs in one folder share every file.

    Which task suits a background agent best?

    Clear, checkable, independent. Design choices and vague goals need you in the loop.

    You go from 3 to 10 parallel agents, and merged PRs per day barely change. The most likely limit?

    Past the point where review is the bottleneck, more agents just grow the queue of unreviewed PRs.

    Which line makes a brief checkable?

    A definition of done the agent can verify itself, and so can you.

    A cloud agent's PRs often break tests it says it ran. First thing to check?

    Without a working setup, the agent can't run its own checks. Environment setup is the most important step.

    What's the current advice on sandboxing background agents?

    Thoughtworks' Radar (Trial, April 2026): sandboxing is "a sensible default rather than an optional enhancement".

    10. Go deeper

    ResourceTimeWhy
    About Copilot cloud agent (GitHub Docs)10 minWhere it runs, its limits, and how to assign work.
    Use Claude Code in the cloud and parallel sessions with worktrees (Claude Code docs)20 minCloud sessions, teleport, Auto-fix, and --worktree.
    Codex cloud (OpenAI docs)5 minEnvironments and parallel tasks.
    Cloud Agents (Cursor docs)10 minEnvironment setup, network controls and the many ways to start an agent.
    Subagents (Antigravity docs)10 minBackground subagents and the Agent Manager.
    Sandboxed execution for coding agents (Thoughtworks Radar, April 2026)3 minWhy sandboxing is the default, and the options.
    git worktree (Git documentation)10 minThe plain-git tool behind local parallel agents.