Repository navigation
Description
Summary
The image trusts only the exact path /workspace (git config --system --add safe.directory /workspace, added in #211). safe.directory matches exact paths, so git worktrees under /workspace/.claude/worktrees/* are not trusted. The intermittent bind-mount ownership mismatch from #172 still makes git fail there with fatal: detected dubious ownership. That includes Hugo's enableGitInfo calls, which can't take a -c override (#211).
As a workaround, Claude Code sessions now start every git call with git -c safe.directory=…. The Bash tool runs zsh, which doesn't word-split variables, so sessions that save the prefix as G="git -c …"; $G log fail with exit 127. A function named g() fails too, because oh-my-zsh's git plugin aliases g. One downstream project saw this wasted retry in 7 sessions.
Reproduction
- In the claude-code devcontainer, create a worktree:
git worktree add .claude/worktrees/x -b x. - Run git in it while the ownership mismatch is active (intermittent, claude-code template: VS Code's Git extension intermittently hits "dubious ownership" on /workspace, and SSH GitHub remotes can't use the container's gh login #172), e.g.
git -C .claude/worktrees/x status, or a Hugo build withenableGitInfo: true.
fatal: detected dubious ownership in repository at '/workspace/.claude/worktrees/x'
Verification
Deterministic, with no dependence on the flake. Make a root-owned repo with a nested repo and test which safe.directory values trust the nested one (git 2.47.3 in the image):
S=$(mktemp -d); sudo mkdir -p $S/ws/wt; sudo git init -q $S/ws; sudo git init -q $S/ws/wt
t(){ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0="$1" \
git -C "$2" rev-parse --git-dir >/dev/null 2>&1 && echo trusted || echo DUBIOUS; }
t "$S/ws" $S/ws/wt # DUBIOUS <- current image behaviour for worktrees
t "$S/ws/*" $S/ws/wt # trusted
t "$S/ws/*" $S/ws # DUBIOUS <- "/*" does not cover the directory itselfSo both entries are needed. Leading-path /* matching has been supported since git 2.46.
Suggested fix
claude-code/.devcontainer/Dockerfile, in the base stage (shared by default and sandbox):
-RUN git config --system --add safe.directory /workspace
+RUN git config --system --add safe.directory /workspace \
+ && git config --system --add safe.directory '/workspace/*'/workspace/* is preferred over *: it covers worktrees and nested repos without turning off the check for paths outside the bind mount.
Affected files in this repo
claude-code/.devcontainer/Dockerfile:146
Related
- claude-code template: VS Code's Git extension intermittently hits "dubious ownership" on /workspace, and SSH GitHub remotes can't use the container's gh login #172: intermittent bind-mount ownership mismatch (root cause of the flake)
- fix(claude-code): set git safe.directory and gh credential helper via env #203, [BUG] Hugo ≥0.166 strips GIT_CONFIG_* env, defeating safe.directory (#203) #211:
safe.directorymoved fromGIT_CONFIG_*env to/etc/gitconfigbecause Hugo strips the env. AGIT_CONFIG_*entry for worktrees would hit the same problem, so the fix belongs in/etc/gitconfig.
Activity