Skip to content

feat(hooks): rename worktree-creation hooks to pre-create/post-create - #2840

Merged
max-sixty merged 8 commits into
mainfrom
post-switch-create
May 21, 2026
Merged

max-sixty merged 8 commits into
mainfrom
post-switch-create

Conversation

@max-sixty

@max-sixty max-sixty commented May 20, 2026 •

Copy link
Copy Markdown
Owner

Phase 1 of the staged hook rename tracked in #2838: the worktree-creation hooks pre-start/post-start become pre-create/post-create. The old names keep working with no deprecation warning yet (Phase 2, months out, adds the warning).

What changes

  • pre-create/post-create are canonical everywhere: the HookType enum, the HooksConfig serde fields, the wt hook CLI, completion, and all docs.
  • Old names keep working: migrate_content() rewrites pre-start/post-start config keys to -create before serde, and parse_hook_type accepts the old CLI names as silent aliases. wt config update rewrites them on disk; wt config show shows the migration diff. wt hook <type> execution and wt hook show both accept the old names; completion and --help advertise only the canonical names.
  • detect_deprecations() flags the old keys so update/show act on them, but format_deprecation_warnings() stays silent (Phase 2 adds the warning). A new empty-warnings guard in check_and_migrate keeps a -start-only config from emitting a stray hint.
  • The dead pre-0.32.0 post-create machinery is removed: the fatal POST_CREATE_REMOVED_MSG load error, the vestigial HooksConfig.post_create merge-fold, and find_post_create_from_doc. post-create is reclaimed as the canonical background creation hook.

Semantic flip

Before v0.32.0, the key post-create named a blocking hook. It now names the background one.

Since v0.44.0, a pre-0.32.0 post-create config is a fatal load error on the check_and_migrate paths: ProjectConfig::load and user/system config loading, which fire on essentially every wt command. A repo carrying one has been unusable ever since. The one path that skips that check is project_config_at_ref (the base-ref read behind wt switch --create), which applies only structural migration. A pre-0.32.0 post-create surviving solely on a base ref, never checked out into a worktree, would now load as a background hook rather than folding into the blocking pre-start. That edge case is accepted: once post-create is valid again, reclaiming the name and detecting the dead key are mutually exclusive.

Reviewing this diff

205 files, but the substance is ~36 files under src/. The rest is regenerated snapshots and auto-synced doc mirrors. Start with:

  • src/config/deprecation.rs — detection (find_renamed_hook_key), migration (rename_hook_key), removal of the fatal block, the empty-warnings guard, and the DEPRECATED_SECTION_KEYS entries that stop unknown-field detection from flagging the migrated keys.
  • src/config/hooks.rs, src/git/mod.rs — the serde field and enum renames.
  • src/config/project.rs — ProjectConfig::load deserializes check_and_migrate's migrated content, so a current-worktree config using the old keys loads into the canonical fields.
  • src/cli/hook.rs, src/commands/hook_commands.rs, src/completion.rs, src/main.rs — the CLI alias layer; wt hook show accepts the old type names as hidden value-parser aliases.
  • src/cli/mod.rs — the wt hook docs, including the soft-deprecation note linking Tracking: rename creation hooks pre-start/post-start → pre-create/post-create #2838.

The ~93 modified snapshots also pick up deterministic env-block lines (GIT_*: "", LLVM_PROFILE_FILE) that pre-existing snapshots already carry. That is stale-snapshot drift surfaced by the regeneration, not a behavior change.

Testing

Full suite green (3799 tests). New coverage: snapshot_migrate_start_to_create (migration preserves value shape and position), test_deprecated_start_hook_key_runs_silently and test_standalone_hook_start_alias_runs_silently (old config and CLI names run with no warning), test_config_show_displays_start_hook_migration (config show reveals the diff without an "unknown field" warning), and test_hook_show_accepts_deprecated_start_hooks (a current-worktree config using the old keys loads, and wt hook show takes both the canonical and the deprecated type arguments).

Part of #2838.

🤖 Generated with Claude Code

Phase 1 of a staged deprecation (#2838): the worktree-creation hooks
pre-start and post-start are renamed to pre-create and post-create.

Old configs keep working with no warning yet. migrate_content()
rewrites the old keys silently on load, wt config update rewrites them
on disk, and wt hook pre-start/post-start still run. The dead
pre-0.32.0 post-create machinery (fatal load error, vestigial field)
is removed, and post-create is reclaimed as the canonical background
hook.

Co-Authored-By: Claude Opus 4.7 (1M context) <[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.

Blocker — CI is failing on every OS because of the .config/wt.toml change.

.github/workflows/ci.yaml installs [email protected] from crates.io and runs wt hook pre-merge --yes insta doctest doc with that binary. v0.50.0 still treats [post-create] as the pre-0.32.0 alias and rejects it as a fatal load error before any tests run:

✗ Failed to load project config
Project config: post-create hook was renamed to pre-start in v0.32.0 and the silent rewrite has been removed. Rename post-create to pre-start in your config.

That message comes from the POST_CREATE_REMOVED_MSG machinery this PR removes — but the bootstrap binary in CI is the older version that still has it. Net effect: linux / macos / windows all fail in <2 minutes with zero tests actually executed, so the new migration paths aren't exercised on CI either.

Simplest fix is to keep .config/wt.toml using [post-start] until a new worktrunk release ships and the CI pin can move. The new binary will silently migrate it to pre-create in memory (the whole point of Phase 1), and v0.50.0 keeps treating it as canonical. Inline suggestion below.

Once CI is unblocked, one smaller observation worth flagging: wt hook show pre-start now errors at clap parse time (HOOK_TYPE_NAMES in src/cli/hook.rs:54 only lists canonical names, and Show.hook_type uses PossibleValuesParser::new(HOOK_TYPE_NAMES)), even though parse_hook_type accepts the deprecated alias for wt hook pre-start itself. The PR description says "old names keep working … on the command line"; this one CLI surface is a small inconsistency with that claim. Probably fine to leave (the in-memory migration means the hook still shows up under pre-create in wt hook show), but worth a sentence in the PR description if it's intentional.

Otherwise the structure of the change is clean: detection (find_renamed_hook_key), migration (rename_hook_key), the DEPRECATED_SECTION_KEYS entries that route warn_unknown_fields away, the empty-warnings guard in check_and_migrate, and the symmetric parse_hook_type aliasing. Good docstrings on the silent-migration / table-form ordering invariant.

Comment thread .config/wt.toml Resolved
CI runs `wt hook pre-merge` with a pinned older `wt` installed from
crates.io, which predates the pre-create rename and rejects a
`post-create` hook section as the removed pre-0.32.0 alias. Keep the
repo's own config on `post-start` (the new code migrates it silently)
until a release ships the rename and the CI pin moves.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty and others added 4 commits May 20, 2026 16:04
… show`

Two gaps in the pre-create/post-create rename (#2838), found in review:

- ProjectConfig::load discarded check_and_migrate's migrated_content and
  deserialized the raw file, so a current-worktree .config/wt.toml using
  [pre-start]/[post-start] silently dropped those hooks from `wt hook
  show`, standalone `wt hook` runs, and completion. Deserialize the
  migrated content, matching the user-config loader.
- `wt hook show <type>` rejected pre-start/post-start at clap parse,
  before parse_hook_type could map the aliases. Accept them as hidden
  PossibleValue aliases (help and completion still list canonical names
  only) and route the parsed value through parse_hook_type.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The merge of main pulled in a new `HookType::PostStart` reference (a
test added by #2841); this branch renamed that variant to `PostCreate`.
Textual auto-merge took main's line verbatim, breaking the build.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty and others added 2 commits May 20, 2026 18:49
# Conflicts:
#	src/commands/hook_commands.rs
The merge of #2844 ("merge per-project user hooks into display") brought
in a new test whose config uses `[post-start]` — canonical on main, a
deprecated alias on this branch. Switch it to `post-create` (the test
exercises the per-project merge, not deprecation) and regenerate the
snapshot, which now shows both hooks under `post-create`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit d7e3f88 into main May 21, 2026
35 checks passed
@max-sixty
max-sixty deleted the post-switch-create branch May 21, 2026 02:31
max-sixty pushed a commit that referenced this pull request May 21, 2026
…2857)

Per @max-sixty's [direction in
#2838](#2838 (comment)):
revert the docs portion of #2840 and keep the code. Docs continue to
recommend `pre-start`/`post-start`; both names work in code so anyone
who already followed the briefly-changed docs (e.g. @EcksDy) isn't
stranded once a release ships these aliases.

## User-visible — back to `pre-start`/`post-start`

- README, docs site, skill mirrors, `dev/*.example.toml`,
`plugins/worktrunk/README.md`, `flake.nix`, `.config/wt.toml`
- `src/cli/mod.rs` / `src/cli/config.rs` / `src/cli/step.rs` /
`src/help.rs` after_long_help and example snippets — and the auto-synced
`docs/content/` and `skills/worktrunk/reference/` mirrors
- `wt hook --help` canonical subcommand names; completion advertises
`-start` only
- `HookType` Display via strum, serde `rename`, and clap `ValueEnum`
name — all `pre-start`/`post-start`. The Rust variant identifiers stay
`PreCreate`/`PostCreate` (internal; we already paid for that rename in
#2840, and now the eventual flip is a Display-only change)
- `HooksConfig` serde canonical fields

## `*-create` still works (kept code)

- `wt hook pre-create` / `post-create` — CLI alias on the canonical
subcommand
- `pre-create` / `post-create` in config: top-level, `[hooks.*]`, and
per-project, in string, `[table]`, and `[[array-of-tables]]` form.
Mechanism: serde `alias = ...` on the field, plus a silent in-memory
rename in `migrate_content()` so the round-trip in `unknown_tree`
doesn't flag table forms as schema-unknown.
- The pre-0.32.0 `post-create` fatal-load-error machinery stays removed
— the name is reclaimed, and both forms load without error.

## Smaller bits

- `valid_user_config_keys()` / `valid_project_config_keys()` append
`pre-create` / `post-create` so the unknown-field round-trip skips them.
`test_valid_*_keys_all_deserialize` skips both aliases (they can't sit
alongside the canonical without a duplicate-field error).
- `DEPRECATED_SECTION_KEYS` drops the `pre-start`/`post-start` entries
#2840 added — `pre-start`/`post-start` are canonical again.
- `find_pre_start_from_doc` / `find_post_start_from_doc` /
`find_renamed_hook_key` / `is_non_empty_item` /
`migrate_start_hooks_doc` and their tests are removed; the migration
direction flips via a new `migrate_create_hooks_doc` (silent, mirrors
the prior shape).
- Test files `e2e_shell_post_create.rs` and `post_create_commands.rs`
rename back to `_post_start_` (via `git mv`, so the rename shows as a
rename).

## Testing

`cargo run -- hook pre-merge --yes` — 3806 tests pass; the 10 failures
are all `case_4` of `shell_wrapper::unix_tests::*` (nu-shell case; `nu`
isn't installed in this runner; same failures occur on `main`).

Also manually verified that a fresh `wt switch --create` against a
project config with `[post-create]` loads cleanly with no unknown-field
warning and the hook fires as `post-start`.

## Follow-up

Per @max-sixty: in a couple of weeks, once a release with
both-names-work is out and users have had a chance to upgrade, the docs
flip is straightforward (most of it is in `src/cli/mod.rs`'s
`after_long_help` and the doc-sync test propagates).

Re #2838.

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
max-sixty added a commit that referenced this pull request May 23, 2026
Two small follow-ups noticed while fixing the test comments in #2877.

**`pre_create` docstring was wrong.** It read "Commands to execute
before worktree creation (blocking)", but `pre-start` actually runs
*after* the worktree is created (`switch.rs:1142` executes it against
"the new worktree (created just above)", and the renamed test below
asserts the worktree exists after a failing pre-start). The wrong
wording entered in #2840 as part of the mechanical `pre-start` →
`pre-create` rename — someone "corrected" the docstring to match the new
name. #2857 reverted the name but left the docstring. Restoring "after
worktree creation (blocking, fail-fast)" matches the actual behavior,
`docs/content/hook.md` ("Runs once when a new worktree is created,
blocking…"), and the parallel `post_create` docstring. Because
`HooksConfig` derives `JsonSchema`, this docstring is user-visible in
generated schema descriptions.

**`test_user_post_start_hook_failure` was misnamed.** The fixture is
`[pre-start]`, the comment and assertion describe a failing pre-start,
and only the function name said post-start. Renamed to
`test_user_pre_start_hook_failure` along with its snapshot name and file
(`git mv`, so the rename shows as a rename).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty pushed a commit that referenced this pull request May 23, 2026
…2857)

Per @max-sixty's [direction in
#2838](#2838 (comment)):
revert the docs portion of #2840 and keep the code. Docs continue to
recommend `pre-start`/`post-start`; both names work in code so anyone
who already followed the briefly-changed docs (e.g. @EcksDy) isn't
stranded once a release ships these aliases.

## User-visible — back to `pre-start`/`post-start`

- README, docs site, skill mirrors, `dev/*.example.toml`,
`plugins/worktrunk/README.md`, `flake.nix`, `.config/wt.toml`
- `src/cli/mod.rs` / `src/cli/config.rs` / `src/cli/step.rs` /
`src/help.rs` after_long_help and example snippets — and the auto-synced
`docs/content/` and `skills/worktrunk/reference/` mirrors
- `wt hook --help` canonical subcommand names; completion advertises
`-start` only
- `HookType` Display via strum, serde `rename`, and clap `ValueEnum`
name — all `pre-start`/`post-start`. The Rust variant identifiers stay
`PreCreate`/`PostCreate` (internal; we already paid for that rename in
#2840, and now the eventual flip is a Display-only change)
- `HooksConfig` serde canonical fields

## `*-create` still works (kept code)

- `wt hook pre-create` / `post-create` — CLI alias on the canonical
subcommand
- `pre-create` / `post-create` in config: top-level, `[hooks.*]`, and
per-project, in string, `[table]`, and `[[array-of-tables]]` form.
Mechanism: serde `alias = ...` on the field, plus a silent in-memory
rename in `migrate_content()` so the round-trip in `unknown_tree`
doesn't flag table forms as schema-unknown.
- The pre-0.32.0 `post-create` fatal-load-error machinery stays removed
— the name is reclaimed, and both forms load without error.

## Smaller bits

- `valid_user_config_keys()` / `valid_project_config_keys()` append
`pre-create` / `post-create` so the unknown-field round-trip skips them.
`test_valid_*_keys_all_deserialize` skips both aliases (they can't sit
alongside the canonical without a duplicate-field error).
- `DEPRECATED_SECTION_KEYS` drops the `pre-start`/`post-start` entries
#2840 added — `pre-start`/`post-start` are canonical again.
- `find_pre_start_from_doc` / `find_post_start_from_doc` /
`find_renamed_hook_key` / `is_non_empty_item` /
`migrate_start_hooks_doc` and their tests are removed; the migration
direction flips via a new `migrate_create_hooks_doc` (silent, mirrors
the prior shape).
- Test files `e2e_shell_post_create.rs` and `post_create_commands.rs`
rename back to `_post_start_` (via `git mv`, so the rename shows as a
rename).

## Testing

`cargo run -- hook pre-merge --yes` — 3806 tests pass; the 10 failures
are all `case_4` of `shell_wrapper::unix_tests::*` (nu-shell case; `nu`
isn't installed in this runner; same failures occur on `main`).

Also manually verified that a fresh `wt switch --create` against a
project config with `[post-create]` loads cleanly with no unknown-field
warning and the hook fires as `post-start`.

## Follow-up

Per @max-sixty: in a couple of weeks, once a release with
both-names-work is out and users have had a chance to upgrade, the docs
flip is straightforward (most of it is in `src/cli/mod.rs`'s
`after_long_help` and the doc-sync test propagates).

Re #2838.

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
max-sixty added a commit that referenced this pull request May 23, 2026
Two small follow-ups noticed while fixing the test comments in #2877.

**`pre_create` docstring was wrong.** It read "Commands to execute
before worktree creation (blocking)", but `pre-start` actually runs
*after* the worktree is created (`switch.rs:1142` executes it against
"the new worktree (created just above)", and the renamed test below
asserts the worktree exists after a failing pre-start). The wrong
wording entered in #2840 as part of the mechanical `pre-start` →
`pre-create` rename — someone "corrected" the docstring to match the new
name. #2857 reverted the name but left the docstring. Restoring "after
worktree creation (blocking, fail-fast)" matches the actual behavior,
`docs/content/hook.md` ("Runs once when a new worktree is created,
blocking…"), and the parallel `post_create` docstring. Because
`HooksConfig` derives `JsonSchema`, this docstring is user-visible in
generated schema descriptions.

**`test_user_post_start_hook_failure` was misnamed.** The fixture is
`[pre-start]`, the comment and assertion describe a failing pre-start,
and only the function name said post-start. Renamed to
`test_user_pre_start_hook_failure` along with its snapshot name and file
(`git mv`, so the rename shows as a rename).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 (1M context) <[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