Repository navigation
feat: Add user-level hooks that run for all repositories, add wt hook show - #118
Merged
Merged
Conversation
Implement a new user hooks system that allows developers to define
personal hooks in `~/.config/worktrunk/config.toml` that execute for
all repositories. User hooks complement project hooks with these key
differences:
- **Scope**: Run for all repositories (vs. single repository)
- **Location**: User config file (vs. `.config/wt.toml`)
- **Approval**: Not required (user implicitly approves via config)
- **Execution order**: Run before project hooks
- **Skip behavior**: Skipped together with project hooks via `--no-verify`
### Implementation Details
**Configuration syntax** (same as project hooks):
```toml
[post-create]
setup = "echo 'Setting up worktree...'"
[pre-merge]
notify = "notify-send 'Merging {{ branch }}'"
```
**Hook types supported**: post-create, post-start, pre-commit, pre-merge,
post-merge, pre-remove
**Template variables**: Support all project hook variables plus `remote_url`
for repository-specific conditional logic
**New data structures**:
- `HookSource` enum: Distinguishes user vs. project hooks
- `prepare_user_commands()`: Expands user hook templates without approval
**Updated hook pipeline**:
- `HookPipeline::run_sequential()`: Accepts `HookSource` instead of
`phase` and `label_prefix`
- `HookPipeline::spawn_background()`: Renamed from `spawn_detached()` for
consistency
### Documentation Updates
- Updated help text and documentation to clarify `--no-verify` skips all
hooks (both user and project)
- Added "User hooks" section to config documentation with examples
- Added comparison table showing key differences from project hooks
- Added use cases and filtering examples
### Tests
Added comprehensive integration test suite (`tests/integration_tests/user_hooks.rs`)
covering:
- Basic execution of all hook types
- Execution order (user before project)
- No approval required for user hooks
- `--no-verify` skips all hooks
- Failure handling and behavior
- Template variable expansion
- Background hook execution
- Combined user and project hook scenarios
- Document remote_url template variable in cli.rs (syncs to docs) - Move check_any_hook_configured into run_hook_with_filter - Simplify standalone hook match arms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Project hooks now show "project" prefix (e.g., "Running project pre-merge") for consistency with user hook labeling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- wt hook intro: Mention both user and project hooks - --no-verify: Change "skip project hooks" to "skip all hooks" - User config comment: Clarify verify skips all hooks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…status Adds a new `show` subcommand to `wt hook` that displays all configured hooks from both user and project config files with their approval status. Project hooks show a ❓ indicator when they require approval. Features: - Lists hooks organized by type (post-create, post-start, pre-commit, etc.) - Shows both user-level hooks (run for all repos) and project-specific hooks - Displays approval status for project hooks (❓ = needs approval) - Optional `--expanded` flag to show template variables substituted with current context - Optional hook type filter to show only specific hook types - Output is displayed through a pager (like git help) when available Also reorders hook subcommands to put `show` first, making hook inspection the primary entry point before hook execution commands.
Personal hooks in ~/.config/worktrunk/config.toml now run automatically before project hooks for all worktree operations. User hooks don't require approval and use the same syntax and template variables as project hooks. Changes: - Add user hook support for all hook types (post-create, post-start, pre-commit, pre-merge, post-merge, pre-remove) - User hooks run before project hooks in execution order - Skip all hooks with --no-verify (applies to both user and project) - Add remote_url template variable for repository-aware filtering - Update documentation and help text to reflect user hooks - Refine hook labeling to distinguish "user" vs "project" hooks in output - Add comprehensive integration tests for user hook functionality
- Add user hooks to shell completion for `wt hook <type> <name>`
- Include PreRemove in batch approval during merge (fixes --force bypass)
- Add source prefix to background log filenames to prevent collisions
- Update documentation for new log format: {branch}-{source}-post-start-{name}.log
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
max-sixty
force-pushed
the
user-hooks
branch
from
December 10, 2025 01:39
4803345 to
07d334d
Compare
User hooks enable personal, repository-agnostic automations while maintaining team standards via project hooks. Key improvements: - User hooks defined in ~/.config/worktrunk/config.toml run before project hooks - User hooks don't require approval (user implicitly approves by defining them) - Post-start logs now include source prefix to avoid collisions (user/project) - remote_url template variable added for conditional hook logic - Hook output labels distinguish user vs project hooks for clarity - All hooks skipped together via --no-verify flag - --no-verify help text simplified from "Skip project hooks" to "Skip hooks" Implementation: - HookSource enum tracks whether hooks are user or project - prepare_user_commands() handles user hooks (no approval needed) - Hook pipeline shows source in output: "Running user pre-merge" vs "Running project pre-merge" - Background operation names include source to prevent log file collisions
Add support for ssh:// URL format in git remote parsing to handle SSH URLs alongside existing git@ and https:// formats. Improve branch name escaping for git config keys by using hex encoding (-XX format) instead of percent-encoding, ensuring all non-alphanumeric characters (except . and -) are properly escaped. This handles UTF-8 multi-byte sequences and enables reliable round-trip encoding/decoding of branch names containing /, _, and other special characters.
User hooks enable personal, repository-agnostic automations while maintaining team standards via project hooks. Key improvements: - User hooks defined in ~/.config/worktrunk/config.toml run before project hooks - User hooks don't require approval (user implicitly approves by defining them) - Post-start logs now include source prefix to avoid collisions (user/project) - remote_url template variable added for conditional hook logic - Hook output labels distinguish user vs project hooks for clarity - All hooks skipped together via --no-verify flag - --no-verify help text simplified from "Skip project hooks" to "Skip hooks" Implementation: - HookSource enum tracks whether hooks are user or project - prepare_user_commands() handles user hooks (no approval needed) - Hook pipeline shows source in output: "Running user pre-merge" vs "Running project pre-merge" - Background operation names include source to prevent log file collisions
The pre-remove hook execution was incorrectly using auto_trust=true, bypassing approval prompts. This commit introduces a design pattern where approval happens exactly once at command entry points: - Add collect_and_approve_hooks() helper for upfront approval - wt remove now approves pre-remove hooks before any execution - Add --force flag to skip approval prompts - Thread auto_trust parameter through handle_remove_output The pattern ensures approval happens at the "gate" (command entry), eliminating error-prone threading of auto_trust through execution layers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Integrates user-hooks features:
- Hook command counting (run_sequential returns usize)
- HookCommandNotFound error with available names
- Pre-remove approval fix ("Approve at the Gate" pattern)
- collect_and_approve_hooks function
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
The .statusline.rs.pending-snap file is no longer needed and should not be committed to version control.
Moves approval prompts to command entry points instead of hook execution. Commands are now approved once in a batch before any hooks run, with template expansion so users see actual values (branch names, paths) instead of placeholders. This eliminates redundant prompts and simplifies the execution layer by removing the `auto_trust` parameter threading. Key changes: - Rename `collect_and_approve_hooks()` to `collect_and_approve_hooks_with_context()` and add `expand_commands_for_approval()` for showing expanded templates in prompts - Remove `auto_trust` parameter from hook execution functions - Simplify `HookSource::Project` enum variant (no longer carries approval state) - Add gate approval at `wt switch --create`, `wt remove`, `wt step commit/squash` - Update merge command collection to expand templates before approval batch - Remove binary `rust_out` artifact and test snapshot file
Update documentation and help text to better explain that `wt hook` runs hooks independently of normal worktree operations. Changes emphasize the use cases (testing, CI, re-running after failure) rather than describing it as "manually" running hooks. Also simplify phrasing around user hooks and remove unnecessary markdown formatting for consistency.
wt hook show
Update function names to be more concise and consistent: - `collect_and_approve_hooks_with_context()` → `approve_hooks()` - `handle_standalone_run_hook()` → `run_hook()` - `handle_standalone_commit()` → `step_commit()` - `handle_standalone_add_approvals()` → `add_approvals()` - `handle_standalone_clear_approvals()` → `clear_approvals()` Also update documentation examples to reference the new names.
…operations When users decline command approval, hooks are now skipped but the operation proceeds. This applies consistently across all approval gates: merge, commit, squash, remove, and hook execution. Previously, declined approvals would still attempt hook execution. Now, the verify flag is shadowed based on approval result - if declined, verify becomes false to gate all subsequent hook execution. For explicit hook runs via `wt hook`, a declined approval returns early since the entire purpose is hook execution. This ensures users have clear control: approving runs hooks, declining skips them but continues the workflow.
Two fixes for `wt hook` command: 1. Pass name_filter to approval so `wt hook pre-merge --name foo` only prompts for approval of the "foo" hook, not all hooks of that type. Added `approve_hooks_filtered()` function that accepts optional name filter parameter. 2. Use current branch as target for pre-merge/post-merge approval prompts to match execution. Previously approval used default_branch while execution used current branch, showing misleading command expansions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…ooks
The expand_command_template function now passes hook-specific extra vars:
- PreCommit: target = default branch (for comparison context)
- PreMerge/PostMerge: target = current branch (matches run_hook behavior)
Previously, --expanded would show raw {{ target }} placeholders for these
hook types because extra_vars was always empty.
Also added TODO for pre-remove approval context issue: when removing
another worktree, the approval preview uses current worktree context
instead of the target worktree context.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
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.
(PR description by Claude)
ref #101
Implement a new user hooks system that allows developers to define
personal hooks in
~/.config/worktrunk/config.tomlthat execute forall repositories. User hooks complement project hooks with these key
differences:
.config/wt.toml)--no-verifyImplementation Details
Configuration syntax (same as project hooks):
Hook types supported: post-create, post-start, pre-commit, pre-merge,
post-merge, pre-remove
Template variables: Support all project hook variables plus
remote_urlfor repository-specific conditional logic
New data structures:
HookSourceenum: Distinguishes user vs. project hooksprepare_user_commands(): Expands user hook templates without approvalUpdated hook pipeline:
HookPipeline::run_sequential(): AcceptsHookSourceinstead ofphaseandlabel_prefixHookPipeline::spawn_background(): Renamed fromspawn_detached()forconsistency
Documentation Updates
--no-verifyskips allhooks (both user and project)
Tests
Added comprehensive integration test suite (
tests/integration_tests/user_hooks.rs)covering:
--no-verifyskips all hooks