Skip to content

Effective Human-AI Collaboration Patterns

Human-in-the-loop development keeps a developer in three roles across a single task: architect while the plan is formed, supervisor while the agent implements, and reviewer before the change is committed. Matching the role to the risk of the task is what separates a rubber stamp from a bottleneck, and what keeps an unreviewed diff out of production.

It is 4pm and the agent has just rewritten your authentication module: fifteen files, 800 lines changed. It compiles, the tests pass, it looks plausible, so you accept all of it. Two weeks later you discover the rewrite silently dropped a CSRF check the original code had. Nobody caught it, because nobody was really reviewing.

The opposite extreme costs just as much. Approve every individual file write and you spend more time supervising the agent than writing the code yourself would have taken. Reading every generated line by hand made sense when a person wrote the diff; it does not survive contact with an agent that writes most of it.

So the answer is neither blind trust nor constant supervision. The teams shipping stable AI-assisted code concentrate at the gates — the accepted plan, the agent’s review findings, the merge, the production authorization — and let the session check its own work in between. Those gates are the ones the AI-native SDLC lays out; this page is about who stands at them and what they actually do there.

  • A plan-execute-review loop with a human decision at every handoff
  • A planning prompt that forces the agent to surface its assumptions before it writes code
  • A scope contract you approve before a single file is touched
  • A supervision prompt that constrains execution to one reviewable step
  • Two review prompts that do different jobs: one inventories the change, one attacks it
  • The per-tool gates — Cursor checkpoints, Claude Code hooks, Codex PR review — that catch what tired eyes miss

Your role shifts during a session, and each shift is a deliberate checkpoint rather than a vibe. Recognizing which one you are in saves time and catches problems while they are still cheap to fix.

1. Architect (planning)

Before any code exists you own the vision and the plan. You hand the agent high-level requirements, have it explore the codebase read-only, and critically evaluate the plan it proposes. Spend the most time here: architectural mistakes are the most expensive to fix, and your experience is what catches a missed requirement while catching it is still free.

2. Supervisor (execution)

The agent implements while you monitor. You break the approved plan into small steps, feed them one at a time, and scan the stream of changes for red flags — files it should not be touching, an approach nobody agreed to. You do not need to understand every line in real time, but you are the hand on the wheel, not a spectator watching an 800-line commit materialize.

3. Reviewer (verification)

The task is finished and you decide whether it ships. You are the gatekeeper of intent and risk, not of every generated line. Routine diffs get layered agent review first (REVIEW.md, Bugbot, claude-code-action, or Codex review); you read the plan, the PR summary, and whatever the agent flagged. Go line by line for regulated or critical code, or when a finding says the change can break behavior, leak data, or breach policy. The agent accelerates creation; merge and production are still yours.

The loop in practice: rate-limiting an API route

Section titled “The loop in practice: rate-limiting an API route”

Here is the loop on a real task — adding per-user rate limiting to a Next.js API route — with the prompt that operationalizes each role.

  1. Architect: ask for a reviewable plan, not code.

    In read-only mode (Cursor Ask, Claude Code plan mode, or codex --sandbox read-only), make the agent plan and mark its guesses before it touches anything. The “Assumptions” section is the part that earns its keep: it turns invisible guesses into a list you can correct in thirty seconds.

  2. Supervisor: execute one step, then stop.

    Approve the plan, switch to execution mode, and constrain the agent to a single step with a hard checkpoint so you review before it continues. This is the cheapest fix for reviewer fatigue: a diff you can actually read beats a diff you skim.

  3. Reviewer: make the agent attack its own diff.

    Before you accept anything, turn the agent into a skeptical reviewer of its own work, then do your own read on top. Naming the specific hazards in the prompt matters more than asking for “a review” — the concrete list is what pulls out findings a generic request never surfaces.

When to intervene and when to stay out of the way

Section titled “When to intervene and when to stay out of the way”

Not every moment deserves equal attention. The practical rule is that interruption is cheap early and expensive late, so spend it on signals rather than on every file write.

Intervene immediately when:

  • The agent starts modifying files outside the agreed scope
  • The agent deletes code without explaining why
  • The agent installs dependencies you did not discuss
  • The agent skips tests or suppresses errors
  • The approach diverges from the plan

Monitor but do not interrupt when:

  • The agent is working through a well-defined task from the todo list
  • Changes are landing in the files you expected
  • The agent is running tests and iterating on failures
  • The agent is following patterns already established in the codebase

Review after completion when:

  • The task is small and well-scoped (single file, clear acceptance criteria)
  • Test coverage for the affected area is strong
  • The agent is working in a sandbox

The risk of the task sets the default, and the default is worth writing down for your team:

Risk levelTask typeRecommended approach
HighAuth changes, data migrations, security codeApprove every file write. Review diffs line by line.
MediumNew features, API endpoints, UI componentsLet the agent work, review the complete change before commit.
LowFormatting, renaming, documentation, test additionsAuto-approve or use headless mode. Review the commit message.

The scope contract below is the cheapest version of all three lists: it makes the agent declare what it is about to touch, so “outside the agreed scope” becomes something you can actually check rather than something you notice afterwards.

The loop is the same everywhere; the mechanical gates that enforce it are not. Use the ones your tool already ships.

  • Ask mode holds the Architect phase — review the plan there before switching to Agent
  • Escape stops the agent mid-action while preserving context
  • Checkpoints are written before each set of edits, so a bad step is a restore rather than an untangling job
  • The review pane accepts or rejects per hunk; bulk-accepting is how off-plan changes slip in
  • Cloud Agent (formerly Background Agent) runs a task asynchronously while you work on something else, with review before merge

Open an agent session with the scope-contract prompt above — it is the fuller version of the “list the files you plan to modify” one-liner, and it also catches new dependencies and destructive edits.

Reviewing agent output is not reviewing human output. The agent does not get tired, cut corners, or have bad days — but it has systematic blind spots, and those are where your attention belongs.

  1. Scope check. Did it modify only the files it should have? git diff --stat gives you the shape of the change before you open a single file.
  2. Deleted code. Every removal needs a justification. Deletions are the highest-risk part of a diff because they are the easiest to miss — the CSRF check at the top of this page went out in a deletion.
  3. Security. Look for hardcoded secrets, missing input validation, weakened authentication, and unescaped user input. Models are trained on a lot of code that does not follow security best practice.
  4. Error handling. Check that errors are handled rather than silently swallowed: empty catch blocks, missing null checks, ignored return values.
  5. Test coverage. Are the new tests meaningful, or do they pass trivially? Spot-check that a test actually fails when you break the implementation — agent-written tests can be tautological, and a green suite proves the cases someone thought of, not the ones they didn’t.

Two prompts do different halves of this work. The self-review below inventories the change and flags what the agent is unsure about; the hostile-review prompt in the loop above attacks the same diff looking for what it got wrong. Run the inventory first, the attack second — the inventory tells you where to point the attack.

A third option removes the self-interest entirely: have one session write and a second, context-free session review. The reviewer has no memory of why a shortcut seemed reasonable at the time.

The most productive developers correct early. A nudge after the first file is cheaper than a rewrite after fifteen, and cheaper still than a revert after the merge.

Stop. The approach you're taking with the notification service
won't work because it doesn't account for our message queue.
Let me redirect: instead of direct database writes, use the
existing event bus in @src/services/eventBus.ts. Read that file
first, then revise your approach.

If Cursor has gone too far down the wrong path, rewind to the last good checkpoint instead of unpicking the changes by hand.

The agent is excellent at pattern-matching and generation. What it lacks is exactly what the three roles supply:

  • It does not know your business context. It cannot know that a harmless-looking change violates a billing rule or breaks a downstream consumer.
  • It makes confident, subtle mistakes. Code that is 99% right with an off-by-one, a race condition, or a missing auth check is more dangerous than code that is obviously broken.
  • It cannot make strategic trade-offs. Performance versus readability, ship-now versus build-to-scale — those need someone who owns the consequences.

Where human-in-the-loop review breaks down

Section titled “Where human-in-the-loop review breaks down”
  • You become the bottleneck. If you spend more time approving individual file writes than the agent spends generating them, you are over-supervising. Batch the review: let the agent finish the task, then read the full diff.
  • Rubber-stamping. Once the agent has been right ten times, you stop reading the eleventh — and that is the one that ships the bug. Keep the hostile self-review in the loop and lean on gates that do not get tired (hooks, CI, required reviewers).
  • Review fatigue on large diffs. A 600-line diff defeats line-by-line reading. Fix it upstream by constraining execution to small steps, and break large changes into commits that can be reviewed independently.
  • Losing the plan. Long sessions drift. Re-paste the numbered plan and ask “which step are we on, and what changed from the plan?” before continuing. If corrections stop sticking, the problem is usually context overload rather than prompt wording — reference the plan file explicitly and keep sessions to a single task.
  • Bugs from AI code reaching production. That is a signal to tighten the process, not to read harder: add mandatory coverage thresholds, and move routine review to the writer/reviewer pattern with two separate sessions.

Where to go next with human-in-the-loop review

Section titled “Where to go next with human-in-the-loop review”