claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Allow Claude to manage git worktrees within project boundaries

Open web3dev1337 opened this issue 6 months ago • 1 comments

🛠️ Feature Request: Support for Git Worktrees in Claude Code

📌 Summary

Claude Code currently enforces strict directory navigation limits for security, which prevents the use of git worktree workflows. This limits productivity for developers using parallel feature development strategies.


🔍 Current Behavior

When attempting to use git worktree, Claude throws the following error:

ERROR: cd to '../ProjectName-feature' was blocked. For security, Claude Code may only change directories to child directories of the original working directory (/path/to/project) for this session.

💡 Proposed Solution

Introduce a configuration option to allow safe navigation to sibling git worktree directories. For example:

.claude/config.json

{
  "permissions": {
    "allowGitWorktreeNavigation": true,
    "worktreePattern": "../{projectName}-*"
  }
}

Claude should:

  • Detect valid git worktrees from git worktree list
  • Permit cd into these verified directories
  • Allow switching between worktrees belonging to the same repo

✅ Use Case

# From within the main project dir
git worktree add ../MyProject-feature1 -b feature/feature1
git worktree add ../MyProject-feature2 -b feature/feature2

Claude should support:

  • Creating new worktrees
  • Navigating between them
  • Performing operations like edits, commits, and codegen in each

🚀 Benefits

  • Parallel Feature Dev: Work across multiple features at once
  • Isolated Environments: Separate node_modules, venvs, etc.
  • Clean Git Histories: Feature branches are neatly organized
  • Deeper Claude Integration: Claude could manage the full worktree lifecycle

🔐 Security Considerations

  • Allow only verified git worktree dirs (via git worktree list)
  • Require explicit opt-in via .claude/config.json
  • Limit access to sibling directories matching a defined pattern

🔁 Alternative Solutions

If directory navigation can't be loosened:

  • Provide a claude worktree command to spawn new sessions in worktrees
  • Add internal commands to create/switch/manage worktrees
  • Introduce a higher-level project workspace model that groups worktrees

📎 Related

  • #1052 – Field Notes: Git Worktree Pattern

🙏 Final Note

Supporting git worktree would meaningfully boost Claude Code’s developer experience and flexibility—without compromising security when opt-in restrictions are applied.

web3dev1337 avatar Jun 17 '25 03:06 web3dev1337

This would be nice, but as a workaround, I've been starting CC from the parent directory of the worktrees to allow me to work on multiple worktrees.

teren-papercutlabs avatar Jun 17 '25 08:06 teren-papercutlabs

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Oct 10 '25 10:10 github-actions[bot]

Permissions propagation would be great too

dlecan avatar Nov 18 '25 05:11 dlecan

thanks for reporting! we're looking into it

catherinewu avatar Nov 30 '25 03:11 catherinewu