Cannot work with git worktrees due to directory restriction
Status Fixed / completed
Maintainer reply None cached
Workaround ✓ Mentioned in description ↑
Activity 10 comments · opened Jul 2, 2025 · closed Aug 17, 2026
Description
When working with git worktrees for feature development, Claude Code cannot navigate to worktree directories that are siblings to the main repository. This blocks a common development workflow.
Steps to Reproduce
- Have a main repository at
/path/to/project - Create git worktrees in
/path/to/project-worktrees/ - Start Claude Code in the main repository
- Try to navigate to worktree:
cd ../project-worktrees/feature-branch - Get error: "For security, Claude Code may only change directories to child directories of the allowed working directories"
Expected Behavior
Should be able to work with git worktrees, which are a standard git feature for isolated development.
Actual Behavior
Cannot navigate to worktree directories, making it impossible to use Claude Code with git worktrees.
Workarounds Attempted
- Adding directories via
/add-dirslash command - directories are added but navigation still blocked - Adding "../", "../project-worktrees" to ".claude/settings.json" and "./claude/settings.local.json"
- Starting from parent directory - not practical for project-specific work
Impact
This prevents using Claude Code for feature development workflows that rely on git worktrees for isolation. Worktrees are essential for:
- Working on multiple features simultaneously
- Keeping main branch clean
- Testing changes in isolation
Related Issues
- #1628 (general directory change request)
Suggested Solution
Either:
- Allow navigation to sibling directories that have been explicitly added via
/add-dir - Add specific support for git worktree directories
- Provide an explicit
/cdcommand as suggested in #1628
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
Additional Context: svelte-check Integration Issue
This limitation is particularly problematic when using TypeScript validation tools like svelte-check. The issue:
Technical Analysis & Root Cause
I've reverse-engineered the cd protection implementation from the compiled CLI and identified the exact root cause and solution.
Code Location & Implementation
The issue is in the cd validation logic around line 1578 in the compiled CLI. Here's what I found:
Path Validation Function (decompiled as
isChildDirectory):Working Directories Function (decompiled as
getAllowedDirs):Permission Check Function (decompiled as
checkDirectoryPermission):CD Command Validation (decompiled as
validateCdCommand):The Bug
The
isChildDirectoryfunction only allows navigation to subdirectories of allowed working directories. However, directories added via/add-diroradditionalDirectoriesshould be directly accessible, not just their children.Current Logic:
targetPathmust be a child of an allowed directoryNeeded Logic:
targetPathcan be a child of an allowed directory OR exactly match an allowed directoryThe Fix
The
checkDirectoryPermissionfunction needs to be updated to allow both:Proposed Fix:
Verification
This analysis is based on decompiled code from the CLI binary. The variable names are logical replacements for minified names, but the logic flow is exactly as implemented.
The fix would allow
cdto work properly with:/add-diradditionalDirectoriesconfiguration--add-dirargument directoriesWhile maintaining security by still restricting access to child directories of the current working directory only.
For the record this was all written by Claude, so I can't speak for the validity of the decompiled code or analysis (it seems flawed to me, because I do have a parent of a directory I'm trying to CD to in allowedDirectories). This is a very serious problem for me right now. I am also working on proposing a solution for the much larger problem in
svelte-check, but it would be nice if these configuration options worked as expected within claude-code too.I have the same issue - no matter how I try to define
additionalDirectories, my orchestrator Claude Code instance (in/repos/main-worktree) cannot access the worktree directories in/worktrees/.Found 1 possible duplicate issue:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This request is for worktrees OUTSIDE of the working directory and is therefore not duplicated
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.
This is still a valid request that would benefit at least a few users.
Related issue with Jujutsu (jj) shared repos:
Setup:
Tried:
Error:
Operation not permitted when jj tries to create temp file in sibling directory.
This is the same underlying restriction but manifesting as sandbox file write denial rather than cd denial. The allowedDirectories config doesn't seem to actually allow writes to those directories.