cd /news/ai-agents/claude-code-git-worktrees-across-mul… · home › topics › ai-agents › article
[ARTICLE · art-179839] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Claude Code git worktrees across multiple repos

A developer demonstrated how to run Claude Code across multiple repositories by manually creating git worktrees on a shared branch in each repo and linking them with the --add-dir flag, since the built-in --worktree option only covers the current repository. The writeup also covers the ivar 0.21.0 tool, which maintains a manifest of repos in a 'hall' and lets the agent create and promote matching feature branches across them on request, addressing gaps such as the lack of read-only directories and manual worktree cleanup.

recommendation

For changes spanning several repos, create a same-named worktree in each with git worktree add -b, then launch Claude Code with --add-dir for the extra paths, or use a manifest tool to promote repos onto one feature branch.

more in playbook: Working with AI coding agents
by read5 min views4 publishedDec 2, 2026

claude --worktree billing-currency gives a Claude Code session its own checkout. According to the Claude Code worktree docs, the flag creates .claude/worktrees/billing-currency/ at the root of the repository you are in, on a new branch named worktree-billing-currency, cut from the default branch. The session edits that checkout and leaves your main one alone.

That covers a change that stays inside one repository. Adding a currency to invoices does not: the API stores and returns it, the web app shows it, and the invoice type lives in a shared types package that both import. That makes three repositories, and each needs a worktree on the same branch. The single Claude Code session also has to see all three. --worktree creates one worktree in the current repo and has no option for the other two.

The short answer: create the worktrees yourself, or ask the agent for the change and let it run a tool for multi-repo worktrees for coding agents. This post shows both, with ivar 0.21.0 for the second. Why worktrees stop at the repository boundary in the first place is covered in Git worktrees are great. They stop at the repo boundary.

Add a worktree in each repo, on one branch name:

$ git -C api worktree add -b billing-currency ../api-billing-currency
Preparing worktree (new branch 'billing-currency')
HEAD is now at 7dc02b3 init
$ git -C web worktree add -b billing-currency ../web-billing-currency
Preparing worktree (new branch 'billing-currency')
HEAD is now at b38caa4 init
$ git -C types worktree add -b billing-currency ../types-billing-currency
Preparing worktree (new branch 'billing-currency')
HEAD is now at f15f9de init

Then start Claude Code in one of them and hand it the others with --add-dir:

cd api-billing-currency
claude --add-dir ../web-billing-currency ../types-billing-currency

This works, and for a one-off it is enough. It gets harder in these places:

types should only be read on this feature, --add-dir has no read-only mode. The only thing that keeps the session out of it is a sentence in the prompt.main for reading and it turns out to need the change, you cut the branch, add the worktree and hand the new path to the session yourself.git worktree remove and git branch -D when the feature lands or is dropped. A second run of the commands above fails while the first branch still exists: fatal: a branch named 'billing-currency' already exists. People have written tools around this. mwt creates multi-repo worktrees for concurrent Claude Code sessions and starts Claude with each repo passed through --add-dir. A feature request on the Claude Code tracker asked for a workspace mode that spans repositories.

With ivar you describe the change and the agent runs ivar. The only command you type is the install:

curl -fsSL 'https://ivar.run/install?ref=claude-code-git-worktree' | sh

ivar keeps the list of repositories in a hall, a git repo with an ivar.json manifest. The one-time hall setup for api, web and types is in the quickstart. After that, open Claude Code in the hall and ask for the change in your own words:

Add a currency to invoices. The api stores and returns it, the web app shows it.

That spans two repos, so I'll open one feature for it.

Created feature billing-currency (branch: billing-currency) in /tmp/demo/acme

Promoted api onto feature billing-currency (branch: billing-currency)

Promoted web onto feature billing-currency (branch: billing-currency)

Promoting a repo creates the billing-currency branch in it, off that repo's default branch, and a real git worktree for it. types stays on main, because nothing in the request said it changes. session connect attaches the running agent to a session for the feature, so the conversation goes on where it was.

The session works from a view dir: a directory of symlinks to real worktrees, plus a generated CLAUDE.md:

CLAUDE.md
api -> /tmp/demo/acme/.ivar/repos/api/billing-currency
state.json
types -> /tmp/demo/acme/.ivar/repos/types/main
web -> /tmp/demo/acme/.ivar/repos/web/billing-currency

api and web point at their feature worktrees. types points at its main checkout, which is guarded read-only. All three repos sit under one directory, so there is no --add-dir to pass.

Halfway through, the agent finds that the invoice type in types needs the new field. It promotes the repo itself and keeps going:

The invoice type lives in types, so it has to change too.

Promoted types onto feature billing-currency (branch: billing-currency)

The session's types symlink now points at the new worktree:

types -> /tmp/demo/acme/.ivar/repos/types/billing-currency

You did not open a terminal, type a path or restart the session.

Before delivering, the agent checks the feature and previews the delivery:

The status it reads back has one branch in every promoted repo:

Feature `billing-currency` (branch: billing-currency) in /tmp/demo/acme:
REPO   STATE  WORKTREE  BASE  PR
api    ready  present   main
types  ready  present   main
web    ready  present   main

The preview lists one push and one pull request per promoted repo, and a fingerprint that the apply step must match. A feature without an approved plan is blocked here; the agent writes the plan with the ivar-plan skill, which stops for your approval after requirements, analysis and plan. Your part is to read the preview and answer:

ship it

The agent applies the delivery and names the pull requests it opened. The full delivery flow is in One feature, three repos: a walkthrough.

You asked for one change and reviewed one preview. The agent created the branch in every repo that needed it, widened the scope when the work required it and opened the pull requests. The repos the feature changes are writable worktrees on the same branch, billing-currency; the repos it does not change are guarded on their default branch. Branches, worktrees, the plan and the session record stay on disk after the conversation ends, so the next conversation picks the feature up where this one stopped.

ivar session start launches cannot write outside the session's writable set; a shell command gets EACCES too. An agent that was already running and attached itself with ivar session connect, as above, has only the tool guard: a Claude Code hook that denies Edit and Write calls outside the writable set and tells the agent why. A shell command can still write. The same holds on macOS, where there is no kernel sandbox at all. The details are on claude --worktree is enough. Use ivar once a feature needs more than one repo on the same branch.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/claude-code-git-work…] indexed:0 read:5min 2026-12-02 · —