← Claude Code Hub
Oct 17, 2026 · 3 min read ✦ Tip #231

Claude Code worktree base branch: why your unpushed commits are missing

worktree.baseRef decides whether a Claude Code worktree gets your unpushed commits. By default it branches from origin/main and leaves them out, subagents included.

Claude Code worktree base branch: with baseRef "fresh" the worktree starts from origin/main and your unpushed commit is missing; with baseRef "head" it starts from your local HEAD and has it, set with worktree.baseRef in .claude/settings.json

TL;DR If your worktrees or subagents need to build on work you haven't pushed yet, put "worktree": { "baseRef": "head" } in .claude/settings.json. If you want every worktree to start clean from main, leave it alone: that's the default.

claude --worktree doesn't branch from the branch you're on. It branches from the remote's default branch, usually origin/main. So if you have three unpushed commits on your feature branch and open a worktree for Claude to pick up from there, those three commits aren't in it. One setting decides this, worktree.baseRef, with two values: fresh (the default) and head.

I tested it on a repo with one pushed commit and one unpushed:

$ git log --oneline
31ef515 unpushed: my local work
a785234 pushed: initial

# baseRef "fresh" (default)
$ claude -w fresh-test -p "git log --oneline"
a785234 pushed: initial

# baseRef "head"
$ claude -w head-test -p "git log --oneline"
31ef515 unpushed: my local work
a785234 pushed: initial

Same repo, same command. With fresh, the worktree starts at a785234 and your commit is left behind. With head, it starts at 31ef515 and has it.

Where it bites

Not only with claude -w. The same setting decides the starting point for:

  • claude --worktree from the terminal.
  • The EnterWorktree tool, when you ask Claude mid-session to "work in a worktree".
  • Subagents with isolation: worktree. This is the expensive one: you hand a subagent something you're halfway through, and it works on main, without your code.

How to change it

1. Add the setting

In .claude/settings.json to apply it to the whole team, or in .claude/settings.local.json for yourself only:

{
  "worktree": {
    "baseRef": "head"
  }
}

2. Open a worktree and check

claude -w test

Ask it for git log --oneline -3 and look for your latest commit.

Which one to pick

Value Branches from Use it when
fresh The remote's default branch (origin/HEAD) Each worktree is a new, independent task
head Your local HEAD, unpushed commits included The worktree or subagent has to continue your in-progress work

It doesn't take a branch name. To start from a specific branch, create the worktree with git worktree add and open Claude inside it.

Three things worth knowing about fresh:

  • It keeps origin/HEAD current. If the repo hasn't been fetched in 24 hours, it runs a fetch capped at five seconds before creating the worktree. If that fails (no network, or git asks for a password), it uses the local copy.
  • No remote means head. If there's no remote, or it can't get origin/HEAD, it branches from your local HEAD.
  • Reused names start clean. Reuse the name of a worktree that has no changes and no commits of its own, or whose PR was merged, and it resets to the default branch instead of reopening at its old tip. With head it doesn't.

And neither value carries uncommitted changes: a worktree is a checkout of a commit. If you need them there, commit first. Ignored files like .env are a different problem, the one .worktreeinclude solves.

If worktrees are new to you, start with putting several Claudes to work at once. And to review a PR, claude --worktree "#123" already fetches the PR's branch, whatever this setting says.

Official docs: Choose the base branch

Requirements

  • A Claude Code release from May 2026 or later: the setting shipped between v2.1.128 and v2.1.136. Tested on v2.1.293.

Found this useful? See more of wmedia.es in your Google results.

Add wmedia.es as a preferred source on Google
FREE GUIDE

Approve less, but better.

Ten minutes in, you're hitting yes without reading. That's not review, that's prayer. A 10-page guide with the five levers in order of risk.

  • 1. Rules the first match wins
  • 2. Mode a dial, not a switch
  • 3. Auto mode a classifier approves for you
  • 4. Sandbox a fence the OS puts up
  • 5. Bypass only inside a container
Are you a professional Web developer?

You'll receive the guide by email · You join the Gravitas newsletter · Unsubscribe anytime

of 10
#

Wmedia · 10 pages
FREE GUIDE · 10 pages · 5 levers

Approve less, but better.

Ten minutes in, you're hitting yes without reading. That's not review, that's prayer. A 10-page guide with the five levers in order of risk.

Are you a professional Web developer? · Unsubscribe anytime
How I use AI

My Claude Code workflow.

The skills, agents and instructions I use as a professional Software Engineer. It's called Craft, and it's a plugin you can install.

See the skills

Tired of approving permissions without reading?