Repository navigation
feat(switch): expose destination branch in pre-switch hooks - #1497
Conversation
… hooks
Move branch resolution (plan_switch) before pre-switch hook execution so
hooks can inspect or validate the target branch. Previously, {{ branch }}
in pre-switch hooks was the source branch; now it's the destination.
Closes #1494 (discussion)
Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The reordering logic is correct — plan_switch is side-effect-free (no state mutation), so moving it before hooks is safe. The behavioral change that hooks now skip when branch resolution fails (e.g., invalid branch) is actually an improvement over the previous behavior.
One issue: the hook documentation now contradicts the code.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@worktrunk-bot please fix |
## Summary - Explicitly bans `gh pr checks --watch` in the `running-in-ci` skill, alongside the existing `gh run watch` ban ## Evidence [Run 23077253025](https://github.com/max-sixty/worktrunk/actions/runs/23077253025) (`claude-review` for PR #1497) used `gh pr checks 1497 --watch` with a 600000ms timeout, which hung for ~55 minutes until the workflow was cancelled. Session log excerpt: ``` Bash: {"command":"gh pr checks 1497 --watch 2>&1 | tail -5","description":"Wait for CI checks to complete","timeout":600000} ``` After the `--watch` call timed out/was cancelled, the bot tried `sleep 60 && gh pr checks 1497` — then the workflow was cancelled entirely. ## Root cause The `running-in-ci` skill says: > Avoid `gh run watch` — it can hang indefinitely. But `gh pr checks --watch` has the same blocking behavior and wasn't explicitly banned. The bot followed the letter of the rule (didn't use `gh run watch`) while violating its spirit (used an equivalent blocking command). This is a recurrence of the pattern from #1402 and #1316 — CI polling commands that block indefinitely. ## Test plan - [x] Verify the updated text is clear and covers both commands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
Update the pre-switch hook documentation to reflect the new behavior:
{{ branch }} is now the destination branch, resolved before hook execution.
Also change assert! to assert_eq! for better failure output in tests.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Fixed both review comments:
CI is green on all platforms (linux, macos, windows), plus lint, code-coverage, and check-docs. |
… ordering in review-pr skill
Two recurring behavioral issues in review sessions:
1. Bot attempts `gh pr review --approve` on self-authored PRs despite the skill
saying not to. Root cause: the approval instructions follow the self-authored
caveat without an explicit gate, so the model reads past the caveat. Fix:
add bold "Never attempt" instruction and gate approval bullets under
"For non-self-authored PRs" heading.
2. Bot resolves review threads before CI passes (step 6 before step 5). The
ordering was implicit ("After submitting the review"). Fix: add explicit
"Only after CI passes in step 5" prerequisite to step 6.
Evidence:
- Self-approval: run 23095864243 (PR #1520 review) — bot tried --approve,
got "Can not approve your own pull request", fell back to comment.
Recurrence of #1254.
- Thread ordering: run 23095864428 (PR #1497 re-review) — bot resolved
threads at step 5, then started CI monitoring at step 6.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
| ## pre-switch | ||
|
|
||
| Runs before every `wt switch` — before branch validation or worktree creation. Useful for ensuring the repository is up to date before switching. Template variables reflect the current worktree (the source), not the destination. Failure aborts the switch. | ||
| Runs before every `wt switch` — after branch resolution but before worktree creation. `{{ branch }}` reflects the destination branch, so hooks can inspect or validate the target. Failure aborts the switch. |
There was a problem hiding this comment.
OK, I think this is slightly off — actually we should include branch but before resolution; is that viable?
There was a problem hiding this comment.
Yes, that's viable. We'd pass the raw branch argument (the user's input) to the hook instead of the resolved one, and move the hooks back to before plan_switch.
The tradeoff is that {{ branch }} would be the raw input rather than the resolved name, so it'd be - instead of the actual previous branch, pr:123 instead of the PR's branch name, @ instead of the current branch, etc. For the common case (wt switch feature-branch) it's identical.
This would also restore the original benefit that pre-switch hooks like git pull run before we validate the branch exists — which matters for --create off a remote ref that hasn't been fetched yet.
Want me to make that change? I'd:
- Move hooks back to before
plan_switch - Pass the raw
branchstring as{{ branch }}in the hook context - Update the docs to reflect "user-supplied branch name (before resolution)"
There was a problem hiding this comment.
Done — moved hooks back to before plan_switch and {{ branch }} now receives the raw user input (before resolution). Pushed in 9c24d2f.
Move pre-switch hooks back to before `plan_switch` so they run before
branch resolution. `{{ branch }}` now receives the user's raw input
rather than the resolved branch name.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Code looks correct — the reordering is clean and both call sites (handle_switch and select/mod.rs) consistently pass the raw branch argument before resolution.
One thing to fix before merging: the PR description is stale. It says "Moves branch resolution (plan_switch) before pre-switch hook execution" but the final implementation (after the review iteration) does the opposite — hooks now run before plan_switch, passing the raw user input. Worth updating so the merge commit summary isn't misleading.
Summary
plan_switch) beforepre-switchhook execution, so{{ branch }}in pre-switch hooks is the destination branch rather than the sourcewt switchand the interactive picker (wt switchwithout args){{ branch }}expands to the destinationDiscussed in #1494 —
{{ branch }}was chosen over{{ target }}per this comment.Test plan
🤖 Generated with Claude Code