-
Notifications
You must be signed in to change notification settings - Fork 0
docs(worktree): add README #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Worktree Plugin | ||
|
|
||
| Git worktree isolation for Claude Code: context injection and parent project access prevention. | ||
|
|
||
| ## Overview | ||
|
|
||
| When Claude Code runs inside a git worktree, it can accidentally read or modify files from the parent project directory. This plugin prevents that by: | ||
|
|
||
| 1. **Injecting context** at session start to inform Claude which path is the worktree and which is off-limits. | ||
| 2. **Blocking file access** to the parent project path via a PreToolUse hook. | ||
|
|
||
| ### How It Works | ||
|
|
||
| ```text | ||
| Session starts | ||
| │ | ||
| ▼ | ||
| SessionStart: worktree-context.ts | ||
| ├── Not a worktree → no-op | ||
| └── Worktree detected → inject additionalContext | ||
| "Use: /path/to/worktree Do NOT access: /path/to/parent" | ||
| │ | ||
| ▼ | ||
| Claude Code tool call (Read/Edit/Grep/…) | ||
| │ | ||
| ▼ | ||
| PreToolUse: deny-parent-access.ts | ||
| ├── Path is safe → pass through | ||
| └── Path is under parent project → deny | ||
| ``` | ||
|
|
||
| ### Worktree Detection | ||
|
|
||
| The hook uses two strategies: | ||
|
|
||
| | Strategy | Condition | How | | ||
| |----------|-----------|-----| | ||
| | Primary | Path contains `/.claude/worktrees/` | String match (Claude Code's `EnterWorktree` convention) | | ||
| | Fallback | Arbitrary `git worktree add` paths | `git rev-parse --show-toplevel` vs `--git-common-dir` | | ||
|
|
||
| ### Scope | ||
|
|
||
| | Tool | Protected | | ||
| |------|-----------| | ||
| | Read | Yes | | ||
| | Edit / Write / MultiEdit | Yes | | ||
| | Grep / Glob | Yes | | ||
| | Bash | No (best-effort only) | | ||
|
|
||
| > **Note:** The hook provides best-effort isolation. It is not a complete security boundary. Bash commands are not intercepted. | ||
|
|
||
| ## Installation | ||
|
|
||
| 1. Start the interactive `claude` shell: | ||
| ```sh | ||
| claude | ||
| ``` | ||
|
|
||
| 2. Within the shell, add the marketplace and install the plugin: | ||
| ```console | ||
| /plugin marketplace add pleaseai/claude-code-plugins | ||
| /plugin install worktree@pleaseai | ||
| ``` | ||
|
|
||
| Alternatively, install directly from the command line (with optional `--scope`: `user` | `project` | `local`): | ||
|
|
||
| ```sh | ||
| claude plugin marketplace add pleaseai/claude-code-plugins --scope project | ||
| claude plugin install worktree@pleaseai --scope project | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| cd plugins/worktree | ||
| bun test | ||
| ``` | ||
|
|
||
| ### Testing hooks manually | ||
|
|
||
| ```bash | ||
| # SessionStart — worktree detected | ||
| echo '{"cwd":"/path/to/project/.claude/worktrees/my-branch"}' | bun run hooks/worktree-context.ts | ||
|
|
||
| # PreToolUse — path denied (parent project access) | ||
| echo '{ | ||
| "tool_name": "Read", | ||
| "tool_input": {"file_path": "/path/to/project/src/secret.ts"}, | ||
| "cwd": "/path/to/project/.claude/worktrees/my-branch" | ||
| }' | bun run hooks/deny-parent-access.ts | ||
|
|
||
| # PreToolUse — path allowed (worktree path) | ||
| echo '{ | ||
| "tool_name": "Read", | ||
| "tool_input": {"file_path": "/path/to/project/.claude/worktrees/my-branch/src/safe.ts"}, | ||
| "cwd": "/path/to/project/.claude/worktrees/my-branch" | ||
| }' | bun run hooks/deny-parent-access.ts | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| MIT | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.