Reference

Claude Code branch workflow

One task, one agent branch, one pull request. Covered in lesson 6 and lesson 7.

The loop

changes needed or checks red → fix on same branch 1 · Start from a fresh main git switch main && git pull 2 · Agent branch (or worktree) for this one task git switch -c NAME · claude -w NAME 3 · Brief Claude: Explore → Plan → Implement → Commit small commits, descriptive messages 4 · Review the diff yourself git diff main...HEAD · /diff · /code-review 5 · Push and open a pull request git push -u origin NAME · gh pr create --fill 6 · CI runs status checks on the merged result gh pr checks --watch 7 · Squash merge, delete the branch gh pr merge --squash --delete-branch 8 · Back to main, pick the next task git switch main && git pull
Blue = main, orange = the agent branch. Nothing reaches main except through step 7.

Prompt templates

Following the Explore → Plan → Implement → Commit pattern from Claude Code's best practices.

# Explore (read only)
Read clean.py and test_clean.py. Explain how missing values are handled. Don't change anything yet.

# Plan
Plan how to add a standardize_columns() function with tests. List the files you'll touch.

# Implement (on the agent branch)
We're on branch add-standardize-columns. Implement the plan, run pytest, and fix failures.

# Commit + PR
Commit with a descriptive message and open a PR against main. Put "Closes #7" in the body.

Claude opens PRs with gh pr create, so install and log in to the gh CLI (docs). By default its commits carry a Co-Authored-By: … <noreply@anthropic.com> trailer and PR bodies say "🤖 Generated with Claude Code". Change this with the attribution setting (docs).

Before you merge

Recovery moves

SituationReach for
Claude's last few edits went wrong, still mid-session/rewind (or Esc Esc) → restore code to a checkpoint. It does not undo Bash-made changes (docs).
One file has bad uncommitted editsgit restore FILE
The whole agent branch is a dead endgit switch main then git branch -D NAME (and git push origin --delete NAME if you pushed it)
A merge hit conflicts you don't want to handle nowgit merge --abort
A bad PR is already merged into mainRevert the pull request on GitHub, which opens a new PR that undoes it (GitHub flow)
You deleted a PR's branch too soonRestore branch on the PR page (docs)

Minimal CI workflow

Save as .github/workflows/ci.yml. It runs tests on every PR into main and on every push to main. The structure follows GitHub's Python tutorial, with action versions current as of October 2026.

name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-python@v7
        with:
          python-version: "3.12"
      - run: pip install -r requirements.txt
      - run: pytest

Gotchas