Skip to content

feat(hooks): let the parent run cleanup_worktrees.py after merge - #300

Merged
furedea merged 11 commits into
mainfrom
feat/cleanup-after-merge
Oct 23, 2026
Merged

furedea merged 11 commits into
mainfrom
feat/cleanup-after-merge

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

ユーザーがマージしたあと,親セッションが ~/.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 を実行

受け入れ条件

  • excludedCommands に 2 件だけ追加されている(テストあり)
  • guard が引数なしと --dry-run を許可する(テストあり)
  • 他の引数や連結コマンドは許可されない(テストあり)
  • README,branches.md,herdr-delegation が更新されている
  • 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 への書き込みをすでに塞いでいる(fix(sandbox): deny writes to every repository's git hooks and config #298)ため,受け入れる.

Closes #299

🤖 Generated with Claude Code

furedea and others added 10 commits October 23, 2026 02:56
Add exact sandbox exclusions and a guard allow rule for the bare call and
--dry-run only, and document the post-merge cleanup step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Allow only the absolute call form, ask on newline or carriage return, and
treat interpreter and shell wrappers as cleanup invocations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…workspaces

Write the cleanup and Codex companion exclusions as ~/ paths, accept the
tilde and expanded forms in the guard, and close a primary Herdr workspace
that an agent session created once no linked worktree or agent remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… closed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…path

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orktree

Take each worktree and its admin dir from the primary's porcelain list, run
git against a lane with explicit --git-dir/--work-tree from the primary,
disable fsmonitor and hooks, and skip worktrees whose .git file points
elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…T_ env

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reject primaries inside sandbox-writable locations, require a real .git
directory, cross-check gitdir links, and remove lane worktrees with the
isolated git call while herdr only closes the workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry lives

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@furedea-agent
furedea-agent Bot force-pushed the feat/cleanup-after-merge branch from b5d467f to 9880e4b Compare October 22, 2026 18:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@furedea
furedea merged commit a9e94c2 into main Oct 23, 2026
11 checks passed
@furedea
furedea deleted the feat/cleanup-after-merge branch October 23, 2026 04:01
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.

マージ後の片付けで,メインが cleanup_worktrees.py を実行して worktree とブランチをまとめて消す

1 participant