Recipe-Inhalt ist auf Englisch. Englisches Original lesen →
← Alle Recipes
Phase 3 · Basic Workflows·6 min·6 steps

Branch-per-Ask — give every AI task its own sandbox

Stop letting Claude or Cursor experiment on your working state. One branch per meaningful AI task. Throwaway when bad, merge when good.

6 steps0%
Du liest ohne Account. Mit Login speichern wir Step-Fortschritt + Notes.

Branch-per-Ask

The single most underrated habit when building with Claude Code or Cursor. Every meaningful AI task gets its own Git branch. Tiny merge surface, instant rollback, zero pollution of your working state. The cost is one extra command before each prompt. The payoff is that you stop being afraid of letting the AI try things.

The pattern shows up in almost every "what experienced AI-augmented devs actually do" guide. It is also what stops the most painful failure mode: AI changes touching files across modules, refactor mixing with bug fix mixing with formatting, and a diff that nobody can review confidently.

Step 1: Make sure you have a clean main

Before you start, your working tree should be clean. In your terminal:

git status

If anything is uncommitted, commit it now (even with a rough message like "checkpoint before AI work"). The branch you are about to create will inherit your current state, so a clean baseline matters.

Step 2: Create the branch

Pick a name that says what the AI is going to do. Not what it might end up doing.

git checkout -b feature/dark-mode

Or in GitHub Desktop: the branch dropdown at the top, "New branch", name it, click. You are now on feature/dark-mode. Anything you or the AI does here is isolated from main.

Naming conventions worth using even solo:

  • feature/short-name for new functionality
  • fix/short-name for bug fixes
  • experiment/short-name for "this might not work and that is fine"
  • refactor/short-name for refactors

Use the experiment prefix liberally. Branches are cheap.

Step 3: Run the AI task

Now you let Claude Code (or Cursor) do its thing. Whatever it changes happens on the branch.

The discipline here is to stay on the branch until the task is done. Do not switch back to main mid-flow, do not start a second AI task in parallel on the same branch — you lose the merge surface clarity.

When the AI says it is done, run your build or test:

npm run build && npm test

Or whatever your project uses. Do not skip this — broken-on-branch is fine, broken-on-main is not.

Step 4: Decide

Three outcomes:

A. Works and you like it. Read the diff (git diff main or in GitHub Desktop), commit, switch to main, merge:

git checkout main
git merge feature/dark-mode
git branch -d feature/dark-mode

B. Half works, you want to keep iterating. Commit on the branch with an honest message ("dark mode draft, theme switch works, contrast still off"). Keep working. Merge later when it sits.

C. Garbage. Switch back to main and delete the branch:

git checkout main
git branch -D feature/dark-mode

That capital -D forces the delete even if the branch was not merged. Your main is untouched. Time spent: 2 minutes including the AI prompt.

Step 5: Why this beats every alternative

  • Editor undo only works per file and per session. Eight-file AI edit, browser closed, undo is gone.
  • Cursor checkpoints cover Composer interactions only, do not persist across sessions, and revert manual edits made afterwards too.
  • Claude Code /rewind is great for in-session fine-grained undo, but it is not a substitute for branches when the task is bigger than one prompt.
  • Stash works for quick switches, but stashes have no structure. After three stashes you do not know what is in them.

A branch is structured, named, persistent, and inspectable. Plus it is the same primitive Git uses everywhere else, so once you have the habit, you can review, merge, rebase, push, and PR like normal software work.

Step 6: Add it to your CLAUDE.md

So the AI itself reminds you (and works inside the pattern):

## Workflow

Before any non-trivial change: commit current state, create a feature branch
(feature/{slug}, fix/{slug}, experiment/{slug}, refactor/{slug}). Work on the
branch. Run build + tests before declaring "done". Read the full diff before
merging. Merge to main only after the build is green and the diff scans clean.

Drop that into your project CLAUDE.md and the AI will follow it on its own most of the time. Reinforce it the first few times by saying "switch to a new branch first" before bigger asks.

Multi-tool setup — Claude CodeSafe AI rollback — never let C