Repository navigation
fix: worktreeのセッションでは、gitだけrtkに書き換えさせない - #83
Merged
Merged
Conversation
Claude Codeのworktree分離チェックが、rtkが書き換えた `rtk git ...` を拒否する (anthropics/claude-code#99895)。linked worktreeでgitを含むコマンドだけ書き換えを省き、 それ以外は `rtk hook claude` に任せるフックを、テストで先に固定する。 RED: tests.test_rtk_rewrite_hook の9件が、hooks/rtk-rewrite.py が無いため失敗した。 tests.test_jp_doc_review_wiring の2件が、Bashの一覧と、rtkのtimeout欠落で失敗した。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hooks/rtk-rewrite.py を足し、settings.json.template の `rtk hook claude` を置き換えた。 cwdがlinked worktree(`.git` がファイルで、gitdirが worktrees/ を指す)で、 コマンドにgitの語を含むときだけ何も出さずに終える。それ以外は `rtk hook claude` の 出力と終了コードをそのまま返す。ファイルが無いブランチへ戻しても止めないよう、 他のフックと同じ形で包み、timeoutはClaude Codeの既定と同じ60秒にした。 GREEN: tests.test_rtk_rewrite_hook、tests.test_jp_doc_review_wiring、 tests.test_missing_hook_files の34件が通った。実物のrtkでも、worktreeの `git status` は無出力、本体の `git status` は `rtk git status` への書き換えになることを確かめた。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ラッパーを入れた理由、見送った2案、上流のissueとPRを残す。 着手条件は、上流のどれかが直ったとき。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jp-doc-reviewerの指摘を反映した。長い1文を分け、見送った2案の主語と述語をそろえた。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
概要
worktreeに閉じ込めたセッションでgitを使えなくなる問題を回避する。linked worktreeでgitの語を含むコマンドだけ、rtkの書き換えを省く。
背景
rtk hook claudeはgit statusをrtk git statusに書き換える。Claude Code本体のworktree分離チェックは、書き換えた後のコマンドを見て「rtkが何を実行するか読めない」と判定し、拒否する。そのため、worktreeのセッションではgit statusもgit commitも通らず、PR #80 のコンフリクトをそのセッションから解けなかった。上流では既知の不具合で、どれもまだ直っていない(2026-10-13時点)。
bug/has repro)見送った案は2つある。rtkの
hooks.exclude_commandsにgitを足す案は、全セッションでgitがrtkを通らなくなる。worktreeでは書き換えを全コマンドで止める案は、worktreeでrtkが効かなくなる。主な変更点
hooks/rtk-rewrite.pyを足した。payloadのcwdから上へ.gitを探す。.gitがファイルで、gitdir:がworktrees/<名前>を指せばlinked worktreeとみなす。その中でコマンドにgitの語を含むなら、何も出さずに終える。それ以外はrtk hook claudeの出力と終了コードをそのまま返す.gitもファイルだが、modules/を指すので対象外にしたgrep gitのような語も省く。分離チェックがこれらも拒否するためsettings.json.templateのrtk hook claudeを、他のフックと同じ「ファイルが無ければ表示して通す」形に置き換えた。timeoutはClaude Codeの既定と同じ60秒にしたtests/test_jp_doc_review_wiring.py)から、rtkだけtimeoutを除外していた例外を外したテスト
tests/test_rtk_rewrite_hook.py(新規)は、偽のrtkをPATHに置き、実物のgitで作ったworktreeとsubmoduleで判定を確かめるbash tests/run.sh --all: 937 passed(a6f3a51で記録済み)git statusは書き換えず無出力になり、本体のgit statusはrtk git statusに書き換わるマージ後に
bash setup.sh --claudeを実行して、生成済みの~/.claude/settings.jsonに反映する。そのうえで、新しいworktreeセッションでgit statusが通ることを確かめる。関連
🤖 Generated with Claude Code