Git & Parallel Sessions
Use Claude Code worktrees, checkpoints, git operations, and isolated branches for safe parallel development.
Built-In Git Awareness
Claude Code reads git state, understands branch context, and can help with commits, branches, diffs, and PRs. It can distinguish staged and unstaged changes, inspect history, and respect .gitignore.
Useful prompts:
Summarize the diff since main and suggest a PR title.
Commit only the files related to the auth fix.
Review my staged changes for bugs and missing tests.Always check git status before delegating commits if your worktree may contain unrelated human changes.
Checkpoints and Rewind
Claude Code creates checkpoints around file edits. Press Esc Esc on an empty input to open rewind and choose whether to restore code, conversation, both, or summarize around a point in time.
Checkpoints are not git commits. Use them for local experimentation; use git commits for durable review history.
Claude Code Worktrees
The easiest way to create an isolated parallel session is:
claude --worktreeClaude Code creates a git worktree, switches into it, and starts a session there. Each worktree has its own directory, branch, working tree, and Claude context.
Use this when you want to:
- Explore a risky refactor without touching your main checkout.
- Run a second Claude session on an independent task.
- Let a subagent or teammate edit files without colliding with your main work.
- Compare two approaches before choosing one.
Include Extra Files with .worktreeinclude
Worktrees usually share repository history but not every untracked local file. If your project needs local-only files copied into new worktrees, use .worktreeinclude:
.env.example
.claude/settings.local.json
local-fixtures/
Do not include secrets unless you are sure the new worktree has the same trust boundary.
Manual Worktrees
Manual git worktrees are still useful when you want exact branch names or directory names:
git worktree add ../project-feature-auth feature/auth
git worktree add ../project-fix-perf fix/performance
cd ../project-feature-auth
claudeClean up when done:
git worktree list
git worktree remove ../project-feature-authSubagents and Worktree Isolation
Subagents isolate context. Worktrees isolate files. For parallel edits, combine them.
Custom subagents can request worktree isolation:
---
name: test-fixer
description: Fix isolated test failures in a separate worktree.
tools: Read, Edit, Bash
isolation: worktree
---
If the subagent makes no changes, its worktree can be cleaned up. If it changes files, keep the worktree for human review before merging.
Agent Teams and Worktrees
Agent teams coordinate independent Claude Code instances. Worktrees keep their edits from colliding.
Use clear ownership:
Use an agent team with worktree isolation.
Teammate A owns API routes.
Teammate B owns UI components.
Teammate C owns tests and verification.
No teammate should edit files outside its lane without asking.Do not run several agents against the same files unless the task is research-only.
CI and Headless Git Tasks
For read-only review in CI:
git diff origin/main...HEAD | claude -p \
"Review this diff for bugs, security risks, and missing tests. Output JSON." \
--output-format jsonOnly use --dangerously-skip-permissions in a sandboxed environment where the inputs and filesystem blast radius are controlled.
Practical Workflow
- Start from a clean main worktree:
git status. - Create an isolated worktree:
claude --worktree. - Ask Claude to plan in
planmode. - Implement in the worktree.
- Run tests and review the diff.
- Merge or cherry-pick the useful changes back.
- Remove unused worktrees.
Related Reading
- Subagents — Context-isolated workers
- Dynamic Workflows — Scripted many-agent orchestration
- Agent View — Manage many independent background sessions
- Agent Teams — Coordinated independent sessions
- Plan Mode — Safe exploration before edits
- Workflows — End-to-end development patterns
Continue with practice
You have finished the core ideas of Git & Parallel Sessions.
If you want to turn the idea into something reusable, continue practicing on AgentWay.