Skip to content

claude.sh: make git work from a git worktree - #4836

Merged
vvbandeira merged 5 commits into
The-OpenROAD-Project:masterfrom
vvbandeira:claude-sh-worktree-git
Nov 16, 2026
Merged

vvbandeira merged 5 commits into
The-OpenROAD-Project:masterfrom
vvbandeira:claude-sh-worktree-git

Conversation

@vvbandeira

Copy link
Copy Markdown
Member

claude.sh mounts only its own folder as /workspace.
When that folder is a git worktree, its .git file points to the main checkout's .git directory by host path, and that path is not in the container.
Every git command in the container then fails with fatal: not a git repository, so Claude cannot diff, commit, or check status.

When claude.sh runs from the top of a worktree, it now also mounts the worktree and the main .git directory at their host paths, and starts the shell in the worktree's host path.
The entrypoint sources env.sh from that start directory, so OPENROAD, FLOW_HOME and PATH use the same paths, and relative git links of submodules such as tools/OpenROAD resolve.
A main checkout, or a plain folder inside another repository, gets no extra mount.

The paths of the other worktrees do not exist in the container, so git gc there would prune their records from the shared .git directory.
claude.sh sets gc.worktreePruneExpire=never in the container to stop this.
The docs warn against git worktree prune and repair in the container, and state that hooks and config in the mounted .git run on the host.

env.sh now quotes its own path, because the host path can contain spaces.

Test

bash docker/test-claude-sh.sh checks the docker run arguments with a stub docker, and the env.sh that the entrypoint sources.
It needs no container engine.

In a container with rootless podman, started by claude.sh from a worktree with an initialized submodule:

  • Before: git status failed with fatal: not a git repository.
  • After: git worked in the worktree and the submodule, a commit made in the container showed on the host, and git gc kept the record of an older worktree.

Host paths under /workspace or /home/claude-user would nest inside the container mounts, so claude.sh prints a warning there and adds no mounts.
Rebuild the image with ./claude.sh --build to get the new entrypoint.

This PR and #4791 both change the entrypoint list in docs/user/ClaudeCode.md.
The second one to merge needs a one-line merge fix there.

A worktree's .git file points to the main checkout by absolute path.
claude.sh mounts only the worktree, so git in the container failed with
"not a git repository". claude.sh now also mounts the main .git
directory at the same path.

The paths of the other worktrees do not exist in the container. git gc
there could then prune their records from the shared .git directory.
claude.sh sets gc.worktreePruneExpire=never in the container to stop
this.

Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
Submodule .git files in a worktree hold a relative path to the main
.git directory. That path did not resolve from /workspace, so git
failed for an initialized submodule. The worktree is now also mounted
at its host path, and the shell starts there. The current worktree is
then no longer stale for git in the container.

Git before 2.31 prints the unknown --path-format option as output, so
the mount was wrong on those hosts. Resolve --git-common-dir with cd
and pwd -P instead.

Host paths under /workspace or /home/claude-user would nest inside the
container mounts. Skip the extra mounts there and print a warning.

Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
git rev-parse searches upward. A plain folder inside another
repository, such as a home folder in git, got that repository's .git
mounted read-write. Mount it only when the folder is the top of its
checkout.

The entrypoint sourced /workspace/env.sh, so OPENROAD, FLOW_HOME and
PATH pointed to /workspace even when the shell started in the host
path. Git links in submodules do not resolve from there. Source env.sh
from the start directory when it has one.

The old-git test now passes --path-format only when the caller does,
and the worktree case runs through it too. The docs state the changed
session and build paths.

Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
env.sh split its own path at spaces, because the inner command
substitution was not quoted. The Claude container entrypoint now
sources env.sh from the worktree's host path, which can contain
spaces, so OPENROAD, FLOW_HOME and PATH came out wrong.

The test now checks env.sh in a path with a space, and which env.sh
the entrypoint sources.

Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
@vvbandeira
vvbandeira requested a review from a team as a code owner November 16, 2026 04:35
@vvbandeira
vvbandeira requested review from sombraSoft and removed request for a team November 16, 2026 04:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for running the container from a Git worktree by mounting both the worktree and the main checkout's Git directory at their host paths, and updates the entrypoint to source env.sh from the active directory. It also disables automatic worktree pruning inside the container and adds a comprehensive test script to verify these mounts. The review feedback correctly identifies a potential test failure when GPG signing is globally enabled on the host, suggesting to explicitly disable it during the test commit.

Comment thread docker/test-claude-sh.sh Resolved
@openroad-ci

openroad-ci commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch.

Commit e9f2e9c · Jenkins build #2 · Baseline: build · View build on dashboard

62 design(s) checked — 0 with regression(s), 0 without a comparable baseline.

With commit.gpgsign=true in the user's git config, the fixture commit
tried to sign with a key for the test identity and failed.

Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
@vvbandeira
vvbandeira merged commit d6b4203 into The-OpenROAD-Project:master Nov 16, 2026
12 checks passed
@vvbandeira
vvbandeira deleted the claude-sh-worktree-git branch November 16, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants