Login
Back to Blog
Background Coding Agents Without Lock-In: Recreating the Cursor Pattern with Git Worktrees

Background Coding Agents Without Lock-In: Recreating the Cursor Pattern with Git Worktrees

C
Crazyrouter Team
June 4, 2026
1 viewsEnglishAI Coding
Share:

Background Coding Agents Without Lock-In: Recreating the Cursor Pattern with Git Worktrees#

Background coding agents are one of the most useful ideas in modern AI coding tools.

The pattern is simple:

Instead of asking an agent to mutate your current working tree while you watch, send a scoped task to an isolated branch and review the result later.

Cursor popularized this workflow for many developers. But the underlying primitive is not proprietary.

You can recreate most of the useful pattern with plain git worktrees, task packets, trace logs, and review gates.

That is what we built.

Dynamic workflow routing benchmark

The problem with the local single-branch loop#

Most AI coding starts like this:

text
You: change this feature
Agent: edits files in your current branch
You: run tests, inspect diff, ask for fixes
Agent: edits again

This is fine for small changes.

It gets messy when the task is long-running:

  • dependency migrations;
  • multi-file refactors;
  • test generation across a repo;
  • exploratory fixes where the first approach may fail;
  • parallel implementation attempts;
  • work you want to review after meetings or overnight.

The core issue is not the model. The issue is workspace coupling.

A background agent should not be able to quietly corrupt your active branch.

What a background coding agent actually needs#

Strip away product UI and the workflow has five parts:

  1. Isolation — a separate branch or worktree.
  2. A task packet — scope, constraints, commands, and done criteria.
  3. Async execution — the agent can work while you do something else.
  4. A trace — what happened, where, and when.
  5. A review gate — inspect diff and evidence before merge.

You do not need a new mental model for this.

You need a safer wrapper around normal git.

Reproduction: git worktree background agent launcher#

We created a small reusable tool:

text
tools/agent_workflows/agent_worktree_launcher.sh

It generates a background-agent workspace with:

text
generated/cursor_background_agents_20260604/worktree_reproduction/
├── README.md
├── trace.jsonl
├── commands/
│   ├── create-worktree.sh
│   └── review-before-merge.sh
└── packets/
    └── 01-background-agent.md

The demo command:

bash
tools/agent_workflows/agent_worktree_launcher.sh \
  --repo . \
  --task "Add async billing export validation in an isolated background branch" \
  --base main \
  --out generated/cursor_background_agents_20260604/worktree_reproduction \
  --mode dry-run

We used dry-run for the published demo because it is safer: it creates the packet and command files without mutating the repo.

When you are ready to create the actual worktree, switch to:

bash
tools/agent_workflows/agent_worktree_launcher.sh \
  --repo . \
  --task "Add async billing export validation in an isolated background branch" \
  --base main \
  --out generated/cursor_background_agents_20260604/worktree_reproduction \
  --mode create

What the packet gives the agent#

The generated packet tells the agent:

text
Work only inside this git worktree:

generated/cursor_background_agents_20260604/worktree_reproduction/worktrees/add-async-billing-export-validation-in-an-isolated-background-branch

It also requires:

  • summary of changes;
  • files touched;
  • test/build commands run;
  • risks and assumptions;
  • diff or git diff --stat;
  • merge recommendation: merge, request changes, or abandon.

This matters because background work is dangerous without explicit boundaries.

A background agent is useful only if it returns reviewable evidence.

Review gate before merge#

The generated review command is deliberately boring:

bash
git -C "$WORKTREE_DIR" status --short
git -C "$WORKTREE_DIR" diff --stat "$BASE"...HEAD
git -C "$WORKTREE_DIR" diff "$BASE"...HEAD > review/diff.patch

That boring step is the safety layer.

No matter which agent produced the branch, the merge decision should be based on:

  • the diff;
  • tests;
  • logs;
  • screenshots or API outputs when relevant;
  • explicit unresolved risks.

Do not merge a background agent branch because the final message sounds confident.

Merge it because the evidence is good.

Where Crazyrouter fits#

Background agents multiply model calls.

A single async task may include:

text
planner call
implementation calls
review call
fix calls
verification summary

If you run everything through one expensive model, cost grows quickly. If you route everything to the cheapest model, failures and retries grow quickly.

A gateway lets you route by step:

StepSuggested route
Task planningstronger reasoning model
Routine implementationcoding-optimized model
Adversarial reviewdifferent strong model
Summary / handofffast cheaper model

With Crazyrouter, the base URL stays OpenAI-compatible:

text
https://cn.crazyrouter.com/v1

That means the workflow can be used from Cursor, Claude Code wrappers, Codex-style scripts, OpenClaw, CI jobs, or custom tooling.

Background agents vs dynamic workflows#

Background agents and dynamic workflows are related, but not identical.

PatternBest whenMain risk
Background agentA task can run independently in another branchhidden bad diffs
Dynamic workflowA complex task needs planner, implementer, reviewer, verifieruncontrolled call fan-out
SubagentA scoped research/review task can be delegatedduplicated context
SkillA repeated SOP needs reusable instructionsoverbuilding for one-off work

A background agent is mostly an execution isolation primitive.

A dynamic workflow is an orchestration primitive.

You can combine them: launch a dynamic workflow inside a background worktree, then review the final branch before merge.

A practical rule#

Use a background agent when all three are true:

  1. the task can be expressed as a clear packet;
  2. the work can happen in an isolated branch;
  3. the final result can be judged by diff + tests + evidence.

Do not use a background agent when:

  • the task needs constant product judgment;
  • the repo is too dirty to isolate safely;
  • secrets or production credentials are required;
  • no one will review the diff.

Background agents are not a replacement for review.

They are a way to make reviewable work happen asynchronously.

The reusable tool#

The tool is intentionally small:

text
tools/agent_workflows/agent_worktree_launcher.sh

It does four things:

  1. creates a task packet;
  2. creates worktree/review commands;
  3. writes a JSONL trace;
  4. optionally creates the git worktree in create mode.

That is enough to reproduce the core Cursor-style background-agent pattern without locking your workflow to one product UI.

Final takeaway#

The important idea behind background coding agents is not “let an AI code somewhere else.”

The important idea is:

isolate async work, make it measurable, and require evidence before merge.

Git worktrees give you the isolation.

Task packets give the agent boundaries.

Trace logs give you observability.

Crazyrouter gives you flexible model routing across planning, coding, review, and verification.

That is the workflow worth keeping.

Try it#

Use Crazyrouter as an OpenAI-compatible gateway:

text
https://cn.crazyrouter.com/v1

Learn more:

Implementation Guides

Related Posts

"Claude Plans, Codex Reviews: Rebuilding the Viral Two-Agent Coding Workflow with Crazyrouter"AI Coding

"Claude Plans, Codex Reviews: Rebuilding the Viral Two-Agent Coding Workflow with Crazyrouter"

"Twitter is full of Codex-in-Claude-Code workflows. We rebuilt the useful part: one agent plans or implements, a second agent reviews adversarially, and the whole process becomes reproducible packets instead of copy-paste chaos."

Jun 3
Claude Code Dynamic Workflows, Rebuilt: A Practical Ultracode-Style Orchestration TemplateAI Coding

Claude Code Dynamic Workflows, Rebuilt: A Practical Ultracode-Style Orchestration Template

Dynamic workflows in Claude Code are trending because they turn one prompt into orchestration, subagents, and verification gates. We rebuilt the useful pattern as a reproducible local workflow with model routing through Crazyrouter.

Jun 3
Same Agent Workflow, Three Model Routes: A Real Crazyrouter BenchmarkAI Coding

Same Agent Workflow, Three Model Routes: A Real Crazyrouter Benchmark

We ran the same four-step AI coding workflow through three routing policies: all Claude Opus 4.7, all Claude Opus 4.8, and a mixed 4.7/4.8 route. The result shows why dynamic workflows need model routing and trace logs, not vibes.

Jun 3
Claude Code Skills vs Subagents vs Dynamic Workflows: Which One Should You Use?AI Coding

Claude Code Skills vs Subagents vs Dynamic Workflows: Which One Should You Use?

Claude Code, Codex, Cursor, and modern AI coding tools now expose multiple workflow primitives: skills, subagents, background agents, and dynamic workflows. This guide explains when to use each, with a small selector tool and Crazyrouter model-routing examples.

Jun 3
GitHub Copilot vs Claude vs Cursor: Which AI Coder Wins in 2026?

GitHub Copilot vs Claude vs Cursor: Which AI Coder Wins in 2026?

We tested GitHub Copilot, Claude, Cursor & 5 more AI coding tools. See rankings by code quality, price, and workflow fit. Updated Feb 2026.

Jan 26
AI API Pricing Comparison 2026: GPT, Claude, Gemini, Video, and Agent WorkloadsComparison

AI API Pricing Comparison 2026: GPT, Claude, Gemini, Video, and Agent Workloads

Compare AI API pricing in 2026 for chat, coding agents, image, video, caching, and multi-model routing with Crazyrouter.

May 25