Skip to content

feat: add directional template vars to all two-worktree hooks - #1655

Merged
max-sixty merged 2 commits into
mainfrom
template-vars
Mar 22, 2026
Merged

max-sixty merged 2 commits into
mainfrom
template-vars

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Phase 1 of the template variable redesign discussed in #1633. Adds directional vars (base, target, target_worktree_path, cwd) to all two-worktree hooks — non-breaking additions only, no existing behavior changes.

New variables

  • cwd — execution directory, always exists on disk (all hooks). Enables the Active model in Phase 2 where worktree_path becomes identity rather than execution context.
  • target_worktree_path — target worktree path, added alongside existing target for merge hooks (pre-merge, post-merge) and remove hooks (pre-remove, post-remove).
  • base / base_worktree_path — source branch/worktree, added to pre-switch hooks. For existing destinations, target / target_worktree_path are also provided.

These follow the "Active" model where each two-worktree operation has a base (source/origin) and target (destination) side:

  • Arriving ops (switch, create): Active = destination. base = where you came from.
  • Departing ops (merge, remove): Active = source. target = where it's going.

Mnemonic: "Are you going there, or is it going away?"

Phase 2 (separate PR) will change bare var semantics so worktree_path consistently points to the Active worktree, with cwd as the execution-context escape hatch.

Ref #1633

This was written by Claude Code on behalf of @max-sixty

Adds `cwd`, `target_worktree_path`, and expands `base`/`target` vars to all
hook types that involve two worktrees. This is Phase 1 of the template variable
redesign — non-breaking additions only, no existing behavior changes.

New variables:
- `cwd`: execution directory, always exists on disk (all hooks)
- `target_worktree_path`: target worktree path (merge and remove hooks)
- `target` + `target_worktree_path`: added to pre-remove and post-remove hooks
- `base` + `base_worktree_path`: added to pre-switch hooks
- `target` + `target_worktree_path`: added to pre-switch (when dest exists)

These directional vars follow the "Active" model where each operation has a
base (source/origin) and target (destination) side. Phase 2 will change bare
var semantics to consistently point to the Active worktree.

Co-Authored-By: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template variable table and prose in the hook docs need updating to reflect this PR's changes. Three issues:

  1. target description says "merge hooks only" — now also available in pre-remove, post-remove, and pre-switch (when target worktree exists).
  2. base / base_worktree_path say "creation hooks only" — now also available in pre-switch.
  3. New variables cwd and target_worktree_path are missing from the table entirely.
  4. The prose paragraph at line 1310 ("target", "base", and "base_worktree_path" are hook-specific") should mention cwd and target_worktree_path too.

These are the primary source (src/cli/mod.rs after_long_help) — the docs and skill files auto-sync from them.

Comment thread src/config/expansion.rs Resolved
Update hook docs to reflect that `target`, `target_worktree_path`, `base`,
and `base_worktree_path` are now available in more hook types, and add the
new `cwd` variable to the table.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot added a commit that referenced this pull request Mar 22, 2026
The review-pr skill assumed the prior bot review was always APPROVED when
skipping trivial incremental changes. When the prior review was COMMENTED
(requesting changes), the bot said "existing approval stands" but no
approval existed, leaving the PR without bot approval.

Extract LAST_REVIEW_STATE alongside LAST_REVIEW_SHA in the preflight, and
after resolving threads on trivial follow-ups, submit an approval when the
prior state was non-APPROVED.

Evidence: 2 occurrences (PR #1655 run 23401754507, plus 1 historical).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty
max-sixty merged commit 113a2dd into main Mar 22, 2026
22 checks passed
@max-sixty
max-sixty deleted the template-vars branch March 22, 2026 20:44
max-sixty added a commit that referenced this pull request Mar 22, 2026
Follow-up fixes and documentation for the template variable redesign
(#1655, #1660).

**Code fixes:**
- `commit` derivation now uses `rev-parse <branch>` instead of
`rev-parse HEAD`, so `{{ commit }}` follows the Active branch
- `base` / `base_worktree_path` now available in post-switch for
existing switches (previously only creates)
- post-remove `{{ target }}` now correctly resolves to the destination
branch, not the removed branch

**Documentation:**
- Restructured template variable table — Active vars grouped first,
directional vars second, repo-level vars last
- Added arrive/depart table explaining what bare vars, `base`, and
`target` point to per operation
- Documented when `cwd` differs from `worktree_path` (pre-switch
existing, post-remove, post-merge with removal)

**Tests:** 4 new integration tests for directional var semantics.

Ref #1633

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[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.

2 participants