Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Run automatically on Claude Code events. Claude doesn't decide.
2 cautions to review before installing
A hook runs when Claude uses the Bash tool
A hook runs when Claude writes or edits files
Static checks of hooks, mods, MCP servers and commands. Not a security audit.
1 marketplace, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
git worktree で隔離した作業ディレクトリ (linked worktree) で動く Claude Code の session が、
同じ repo の別の checkout (main 側や他の worktree) を書き換えるのを止める PreToolUse hook です。
複数の agent を worktree で並列に動かすと、次のような事故が起きます。
cd <main 側> && git checkout -b ... のような複合コマンドで、自分の worktree ではなく
main 側の branch を切り替えてしまう目的はうっかりの予防で、意図的なすり抜けを防ぐ仕組みではありません。
cd "$DIR" / git -C "$REPO") などで静的に決まらない操作は、止めずに注意だけ
出します。誤検知で agent の作業が止まるのを避けるためです> / cp / mv / rm などによるファイル書き込みは見ません (git の書き込み操作と
Write / Edit だけが対象です)bash -c "..." / sh -c "..." / eval "..." の文字列の中の git./deploy.sh など) の中の git"$(...)" や `...` の中の gitfor / case などの制御構文で作業ディレクトリが変わる場合/plugin marketplace add Mao-o/cc-mp-worktools
/plugin install worktree-cwd-guard@mao-worktools
hook の入力に含まれる作業ディレクトリ (cwd) が linked worktree の中のときだけ動きます。
main checkout や repo の外で動く session では何もしません。
「自分の worktree」はその linked worktree の root、「別の checkout」は git worktree list に
並ぶ他の root (main checkout を含む) です。worktree が main checkout の中に置かれている
(.claude/worktrees/<name> など) 場合も、パスは最も深い root に属するものとして判定します。
| ツール | 止める条件 |
|---|---|
| Bash | 別の checkout を対象にした git の書き込み操作。対象は cd / chdir / pushd / popd、git -C <dir> / --work-tree / --git-dir、環境変数 GIT_DIR / GIT_WORK_TREE (コマンド前の代入・env・export。env -i / env -u による削除も反映) から決める。--git-dir / GIT_DIR には各 checkout の <root>/.git と .git/worktrees/<name> のどちらの形も読む。--git-dir / GIT_DIR だけが効いて作業ツリーの指定が無いときは、作業ツリーは今の場所になるので、git dir の checkout と今の場所の両方を見る (GIT_DIR=<自分の worktree>/.git git -C <main> reset --hard は main の作業ツリーを上書きする)。git add / git commit のように作業ツリーを書かない操作も同じに読む。&& / ` |
| Bash | git worktree remove / move で別の worktree を対象にしたもの。相対パスは、git dir・作業ツリー・今の場所のどの基点でも別の worktree なら止める |
| Write / Edit / MultiEdit / NotebookEdit | 別の checkout 配下のファイルへの書き込み |
止めないもの:
git log / git diff / git status / git stash list / git apply --check などの読み取り/tmp、ホームの設定ファイルなど) への書き込みgit worktree add (新しい worktree を作るのは別の checkout の書き換えではない)| 環境変数 | 既定 | 内容 |
|---|---|---|
WORKTREE_CWD_GUARD_MODE | enforce | warn = 止めずに伝える / off = 何もしない |
WORKTREE_CWD_GUARD_ALLOW | (空) | 書き込みを許す checkout の root。複数は OS のパス区切り (: / Windows は ;) で並べる |
supervisor 役の session が worktree の中から意図して main 側を操作する場合は、
WORKTREE_CWD_GUARD_ALLOW に main checkout の root を入れてください。
[worktree-cwd-guard] 別の checkout を書き換える操作を止めた。
この session の worktree: /path/to/repo/.claude/worktrees/lane-a
- `git checkout` が別の checkout (/path/to/repo) を対象にしている
自分の worktree の中で作業する。意図した操作なら、対象の checkout を WORKTREE_CWD_GUARD_ALLOW に加えるか WORKTREE_CWD_GUARD_MODE=warn で実行する。
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
npx claudepluginhub mao-o/cc-mp-worktools --plugin worktree-cwd-guardPlugins from other owners that cover similar ground