Skip to content

fix(sandbox): deny writes to every repository's git hooks and config - #298

Merged
furedea merged 2 commits into
mainfrom
fix/sandbox-git-deny
Oct 22, 2026
Merged

furedea merged 2 commits into
mainfrom
fix/sandbox-git-deny

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

概要

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/hooks 書ける Operation not permitted
コミットと push 動く 動く

範囲外

サブモジュールの .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

@furedea
furedea merged commit 186f885 into main Oct 22, 2026
11 checks passed
@furedea
furedea deleted the fix/sandbox-git-deny branch October 22, 2026 16:18
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]>
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.

Claude の sandbox で全リポジトリの .git の hook と設定への書き込みを禁止する

1 participant