Skip to content

fix(claude-code): trust git worktrees under /workspace - #317

Open
gatezh wants to merge 4 commits into
claude-code/github-mcp-tokenfrom
claude-code/safe-directory-worktrees
Open

gatezh wants to merge 4 commits into
claude-code/github-mcp-tokenfrom
claude-code/safe-directory-worktrees

Conversation

@gatezh

@gatezh gatezh commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What

Trust git worktrees and nested repositories under /workspace in the claude-code image, not just /workspace itself.

Why

safe.directory matches exact paths. The image trusts only /workspace, so a worktree at /workspace/.claude/worktrees/<name> (Claude Code's default location) fails with detected dubious ownership whenever the bind-mount ownership mismatch from #172 is active. That includes Hugo's enableGitInfo git calls, which can't take a -c override (#211). It also includes Claude Code's own --worktree and subagent-isolation checks, which refuse a worktree git can't read.

Changes

  • claude-code/.devcontainer/Dockerfile: add safe.directory '/workspace/*' to /etc/gitconfig next to the existing /workspace entry, in the base stage, so both variants get it.
  • claude-code/verify-image.sh: assert the new entry.
  • claude-code/README.md (Git and GitHub Authentication): describe the second entry, and say that the Dev Containers extension adds only a /workspace entry.

Notes

  • Why both entries: since git 2.46, a value ending in /* trusts every repository under that leading path, but not the directory itself (Documentation/config/safe.txt documents this from v2.46.0 on, not in v2.45.0). The image ships git 2.47.3. I checked this in the published claude-code:latest image with a root-owned /workspace, a real git worktree add .claude/worktrees/x, and a nested repo, running git as node:
    • with both entries, all three are trusted;
    • with only /workspace, the worktree fails with dubious ownership.
  • Why not *: /workspace/* keeps the check for paths outside the bind mount. Everything under /workspace is the user's own repo, which the agent can already write, so this adds no new write path.
  • Other images: no other image or template in the repo sets safe.directory (bun, claude-bun, hugo-bun, hugo-bun-node, ralphex-fe, the repo's own .devcontainer), so nothing else needs this fix.
  • Left as is: the containerEnv comments in both devcontainer.json files still say "the image trusts /workspace". They're accurate, and feat(claude-code): turn off claude.ai connectors in both variants #313 and feat(claude-code): give the GitHub MCP server the gh login's token #316 edit the same block.
  • Wiki: no page mentions safe.directory, gitconfig, or worktrees.

Closes #253

safe.directory matches exact paths, so worktrees under
/workspace/.claude/worktrees/* failed with "detected dubious ownership"
whenever the bind-mount ownership mismatch (#172) was active. Add
'/workspace/*' to /etc/gitconfig next to /workspace: since git 2.46 a
trailing /* trusts every repository under the leading path (the image
has 2.47.3), but not the directory itself, so both entries are needed.

'/workspace/*' rather than '*' keeps the check for paths outside the
bind mount. verify-image.sh asserts the new entry.

Closes #253
@gatezh
gatezh changed the base branch from master to claude-code/github-mcp-token November 27, 2026 20:22
@gatezh
gatezh added this pull request to stack #321 November 27, 2026 20:22
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.

[BUG] safe.directory trusts only /workspace, not worktrees under it

1 participant