Skip to content

enh: bind mount original repo when running in a git worktree#19

Merged
yarikoptic merged 4 commits intomainfrom
enh-worktree
Dec 17, 2025
Merged

enh: bind mount original repo when running in a git worktree#19
yarikoptic merged 4 commits intomainfrom
enh-worktree

Conversation

@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Dec 5, 2025

When the workspace is a git worktree (detected via .git being a symlink or a file with gitdir: reference), add a bind mount for the original repository. This allows Claude to access the original repo's git objects and references, and perform git operations (commit, fetch, etc.).

🤖 Generated with Claude Code

note: bind mount 'rw' so we could commit etc


Updates (added by Claude Code)

Addressed review feedback

Per @asmacdo's feedback about security concerns with silent bind mounting, added --worktree option with four modes:

  • ask (default): Prompts user with security warning before bind mounting
  • bind: Automatically bind mounts original repo
  • ok: Skip bind mounting and continue normally
  • error: Exit if worktree detected

Contributors

Usage

# Prompt before mounting (default)
yolo

# Always bind mount
yolo --worktree=bind

# Never bind mount  
yolo --worktree=ok

# Disallow worktrees
yolo --worktree=error

Security note: Bind mounting the original repo exposes more files and allows modifications. The ask prompt helps prevent unintended access.

@yarikoptic yarikoptic requested a review from Copilot December 5, 2025 18:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asmacdo
Copy link
Member

asmacdo commented Dec 5, 2025

I've encountered this also, so I'm very happy to see this! I wonder though if we should consider making it optional and off by default. My reasoning

  • bindmounting anything other than cwd silently might expose something the user doesnt want exposed
  • running in permissions bypass could result in unintended changes to the original repo rather than the worktree

wdyt?

@yarikoptic
Copy link
Member Author

arguments do make sense! I guess we better make it also "explicit" as ask user unless specified... @copilot can improve this PR to add an option --worktree ask,bind,ok,error . So by default -- ask user to either bind or not ('ok') or error out.

Copy link
Contributor

Copilot AI commented Dec 6, 2025

@yarikoptic I've opened a new pull request, #22, to work on those changes. Once the pull request is ready, I'll request review from you.

@yarikoptic
Copy link
Member Author

@copilot please address conflicts

Copy link
Contributor

Copilot AI commented Dec 7, 2025

@yarikoptic I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you.

@asmacdo
Copy link
Member

asmacdo commented Dec 7, 2025

@copilot address conflicts between PR #19 and the main branch

yarikoptic and others added 2 commits December 9, 2025 12:19
When the workspace is a git worktree (detected via .git being a symlink
or a file with gitdir: reference), add a bind mount for the original
repository. This allows Claude to access the original repo's git objects
and references, and perform git operations (commit, fetch, etc.).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Austin Macdonald <austin@dartmouth.edu>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Austin Macdonald <austin@dartmouth.edu>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@asmacdo
Copy link
Member

asmacdo commented Dec 9, 2025

@yarikoptic ready for review. (I couldnt request review, so I've also invited you to join project as admin)

README.md Outdated
yolo --worktree=bind

# Never bind mount, run without error
yolo --worktree=ok
Copy link
Member

Choose a reason for hiding this comment

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

Actually I think this should be "no", ok doesnt match the behavior IMO

Copy link
Member

Choose a reason for hiding this comment

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

went with skip instead

More intuitive name for the option that skips bind mounting.

Co-Authored-By: Austin Macdonald <austin@dartmouth.edu>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yarikoptic yarikoptic merged commit 8e41378 into main Dec 17, 2025
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.

3 participants