Repository navigation
fix(sandbox): deny writes to every repository's git hooks and config - #298
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Oct 22, 2026
furedea
added a commit
that referenced
this pull request
Oct 23, 2026
## 概要 ユーザーがマージしたあと,親セッションが `~/.claude/hooks/cleanup_worktrees.py` を実行して,マージ済みの worktree とブランチを片付け,`main` を fast-forward する.`herdr worktree remove` で手作業で消すと,ブランチが残り,次の掃除の対象からもリポジトリが外れるため,それをやめる. - `agents/claude/settings.json`: `sandbox.excludedCommands` に絶対パスの 2 件(引数なし,`--dry-run`)だけを追加.ワイルドカードなしの完全一致. - guard hook: 引数なしと `--dry-run` だけを確認なしで許可する.追加引数,連結,パイプ,リダイレクト,ラッパー経由は従来どおり確認になる. - ドキュメント: README の手順表,`branches.md`,`herdr-delegation/SKILL.md` を更新. ## 変更前後 | 項目 | 変更前 | 変更後 | | --- | --- | --- | | sandbox 除外 | なし(他リポジトリの `.git` に書けない) | 絶対パスの引数なしと `--dry-run` のみ | | guard の扱い | 確認が必要 | 引数なしと `--dry-run` は許可,それ以外は従来どおり | | 片付けの手順 | 手作業の `herdr worktree remove` | マージ後に親が `cleanup_worktrees.py` を実行 | ## 受け入れ条件 - [x] `excludedCommands` に 2 件だけ追加されている(テストあり) - [x] guard が引数なしと `--dry-run` を許可する(テストあり) - [x] 他の引数や連結コマンドは許可されない(テストあり) - [x] README,`branches.md`,`herdr-delegation` が更新されている - [x] `lefthook run pre-commit --all-files` と `pytest tests/agents` が通る - [ ] CI が通る ## 既知の制限 - primary ワークスペースを閉じる判定は,セッションの所有権 record を信頼する.state ディレクトリは sandbox 内から書けるため,偽の record を置かれると,エージェントが動いていない user のワークスペースを閉じさせられる可能性がある.閉じられるのは,エージェントが動いていないワークスペースだけである.既存の `herdr workspace close` の所有権判定と同じ信頼モデルとして受け入れる. - レーン worktree の `.git` や config に仕込まれたコマンド(`core.fsmonitor` など)は,スクリプトが primary 側の admin dir を明示して git を実行するため,動かない. - primary の信頼判定は,sandbox で書き込める場所(`sandbox.filesystem.allowWrite`,`/tmp`,`TMPDIR`,`~/.herdr/worktrees`)の外にあり,`.git` が実ディレクトリのものに限る.設定ファイルを読めないときは,レーン由来の primary を飛ばし,呼び出し元自身のリポジトリだけを掃除する. - 次の場合は primary と判定されず,掃除の対象から外れる(受け入れる): `.git` がファイルの primary(separate-git-dir),サブモジュール内の cwd. - primary 自体が `extensions.worktreeConfig=true` の場合,競合して書き換えられた `config.worktree` の読み込みは防げない.どのリポジトリもこれを有効にしておらず,`sandbox.filesystem.denyWrite` が `~/**/.git/worktrees/*/config.worktree` への書き込みをすでに塞いでいる(#298)ため,受け入れる. Closes #299 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
概要
Claude Code のサンドボックスが,セッションを開いたリポジトリだけでなく,ホーム配下のあらゆるリポジトリの Git hooks と config への書き込みを拒否するようにする.
sandbox.filesystem.denyWriteに glob を 3 つ足す.公式ドキュメントでは,denyWriteの wildcard は macOS で有効とされている(Linux では無視される).接頭辞のないパスはユーザー設定では~/.claude基準で解決されるので,~/**/で固定した.変更前後
sandbox.filesystem.denyWrite~/**/.git/hooks,~/**/.git/config,~/**/.git/worktrees/*/config.worktree.git/hooksOperation not permitted範囲外
サブモジュールの
.git/modules/<name>/hooksとconfigは対象外(Issue の 3 パターンに含まれない).受け入れ条件
denyWriteに 3 つの glob が入っているtests/agents/claude/test_settings.pyに仕様テストを足したlefthook run pre-commit --all-filesが通るswitchのあと,入れ子のリポジトリの.git/hooksへの書き込みが拒否されるswitchのあと,レーンがコミットと push をできるCloses #296
🤖 Generated with Claude Code