Every developer using an AI coding assistant has lived this failure mode: you are forty minutes into refactoring an authentication or payment flow. You have three files modified with unstaged, half-tested edits. You ask the assistant for a small fix on a related screen.
The agent reads your workspace and immediately begins writing directly to disk. It reformats imports, touches five files you never asked it to touch, introduces broken syntax, and fails a type check. Suddenly your git status is contaminated with a dozen mixed changes. If you want to abandon the attempt, running git reset or git checkout will wipe out your own uncommitted work alongside the agent's mistakes.
The three hazards of in-place file mutation
Most coding tools execute agents directly inside your active repository folder. In pristine demo repositories this looks smooth, but in real development workflows it creates three chronic points of failure:
- Work contamination: Agent edits interlock with your in-progress unstaged changes, forcing tedious interactive staging (git add -p) to separate your work from agent hallucinations.
- Blind component blast radius: When asked to handle an error state on one page, an agent may alter a shared root hook or global context provider rather than scoping the change locally, breaking distant screens without warning.
- No zero-cost discard: When an agent produces messy code, you cannot roll back cleanly without risking your own uncommitted modifications. Discarding should be an instant, consequence-free decision.
Why git stash is not a safety net
Some tools attempt to paper over this by stashing your changes before the agent runs. In practice, manual stash workflows break down quickly. If an agent modifies files that overlap with your stashed changes, popping the stash triggers merge conflict markers inside your uncommitted work.
Worse, if a developer is actively writing code while an agent is running in the background, a stash-and-write pattern will overwrite newly typed keystrokes or fail entirely. A working tree should never be shared between a human developer and an autonomous agent.
| Strategy | Uncommitted edits | Preview isolation | Discard cost |
|---|---|---|---|
| In-place writes | Mixed with agent edits | Shares active dev server | Manual git reset / add -p |
| Manual git stash | Conflict risk on stash pop | Shares working tree | Stash pop conflicts |
| Git worktree sandbox | Completely untouched | Isolated sandbox server | Instant folder removal |
How Git worktrees provide isolated execution
To solve this, Wirefold runs every agent session inside an isolated Git worktree under .intent/worktrees/<runId>. Unlike a slow git clone, a worktree creates a lightweight directory checkout linked directly to your existing .git/objects database with zero duplicate storage overhead.
The agent runs its trial edits, builds, and local development servers entirely inside this isolated directory. Your primary checkout, branch state, and uncommitted edits remain untouched and completely private.
# Your primary working tree stays clean and untouched
# The agent executes trials exclusively inside the worktree sandbox
cd .intent/worktrees/run_01j8af
pnpm buildReviewing the sandbox diff before applying
Instead of trusting conversational summaries, Wirefold generates an exact diff between your baseline checkout and the sandbox worktree. You evaluate the change exactly like a peer review on a pull request.
- const handleCheckout = async () => {
- await processPayment(cart.id);
- navigate("/receipt");
- };
+ const handleCheckout = async () => {
+ try {
+ await processPayment(cart.id);
+ navigate("/receipt");
+ } catch (err) {
+ setError(err instanceof Error ? err.message : "Payment declined");
+ }
+ };You can test the resulting behavior directly in the live sandbox preview before any code touches your project. If the diff touches files outside the requested scope or violates your project patterns, you reject the run with one click.
Guarded writes with SHA-256 hash checks
Even inside an isolated worktree, uncontrolled file overwrites are dangerous. Wirefold routes all file modifications through a guarded patch application interface that validates the SHA-256 hash of the target file before applying changes.
if (sha256(currentContent) !== expectedContentHash) {
throw new Error("STALE_CONTENT_HASH");
}If concurrent modifications occurred or the agent generated code against a stale revision of the file, the patch is rejected immediately. The agent cannot silently overwrite changes it has not verified.
Safe merging with index-aware auto-stash
When you are satisfied with the diff and click Apply, Wirefold merges the reviewed sandbox changes into your checkout. Wirefold uses Git 2.38 or newer to ensure your staged and unstaged edits remain distinctly separated throughout the merge.
If you want to see this workflow in action on a quick component restyle, take a look at our step-by-step tutorial on changing a React button color without an editor.
Zero-cost discarding on failure
Autonomous agents make mistakes. The mark of a reliable developer harness is not whether the model is infallible, but how gracefully failure is handled. With a sandbox, discarding a bad attempt deletes a disposable folder in .intent/worktrees. Your active branch remains pristine, your uncommitted changes stay intact, and your flow is uninterrupted.