Honor chamber.config default_base + hooks for EnterWorktree-created worktrees#2
Draft
echochamber wants to merge 1 commit into
Draft
Honor chamber.config default_base + hooks for EnterWorktree-created worktrees#2echochamber wants to merge 1 commit into
echochamber wants to merge 1 commit into
Conversation
Claude Code's built-in EnterWorktree tool creates worktrees off its own worktree.baseRef (default `fresh` = origin/<default-branch> = main) and ignores the per-repo .claude/chamber.config default_base, post-create hooks, and symlink_files. In repos whose integration branch is not the default branch (e.g. manabot-alpha: default_base=origin/dev), every EnterWorktree branch was based on main — polluting PRs with ~25 dev->main promotion merges — and deps were never installed. Add wtutils/enterworktree-reconcile.sh, a PostToolUse hook on EnterWorktree that, for a freshly-created EMPTY worktree only (clean tree + no commits of its own beyond the base it was cut from), re-points the branch onto chamber.config default_base via `git reset --hard`, then runs the chamber post-create hooks + symlinks by reusing wtutils.sh's wt--setup-worktree. Safety: the rebase is gated hard. If the tree is dirty or HEAD carries any unique commits, the hook refuses to touch history and logs a skip reason — it can never clobber work. It also no-ops cleanly when default_base is absent (setup still runs), when already on default_base, and on re-run. All paths exit 0; the hook never blocks Claude. Logs to ~/.claude/hooks/enterworktree-reconcile.log. install.sh now symlinks the hook into ~/.claude/hooks/ and prints the settings.json PostToolUse registration snippet (the repo does not edit the user's settings.json). The wt-add shell path is unchanged. Refs #1 Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Summary
Fixes #1. Claude Code's built-in
EnterWorktreetool (which~/.claude/CLAUDE.mdtells agents to prefer) creates worktrees from its ownworktree.baseRef(defaultfresh=origin/<default-branch>=main) and ignores.claude/chamber.config— so it skips the per-repodefault_base, post-createhooks, andsymlink_files. Inmanabot-alpha(default_base: origin/dev, PRs targetdev), everyEnterWorktreebranch was based onmain, polluting PRs with ~25dev→mainpromotion merges, and deps were never installed.Root cause confirmed empirically: an existing
EnterWorktreeworktree (worktree-worker-egress-step1-vpc) was based exactly onorigin/main's tip, 25 commits ahead oforigin/dev.Fix
New PostToolUse hook on
EnterWorktree:wtutils/enterworktree-reconcile.sh. After the tool creates the worktree it:chamber.configdefault_base(e.g.origin/dev) — viagit reset --hard— only for a freshly-created empty worktree.hooks+ appliessymlink_files/symlink_dirs/beads redirect, reusingwtutils.sh'swt--setup-worktree(no config-parsing duplication).EnterWorktree'sbaseRefcan't target an arbitrary branch, so this is a post-create reconciliation, exactly as the issue suggested.Safety (runs on every EnterWorktree create)
The rebase is gated hard — it proceeds only when all hold:
chamber.configdeclares adefault_baseorigin/<default-branch>)default_baseresolves to a real commit differing from HEADIf any gate fails: no history touched — setup hooks still run (idempotent), and a skip reason is logged to
~/.claude/hooks/enterworktree-reconcile.log. The hook never blocks Claude (all paths exit 0). Thewt-addshell path is untouched.How it was tested
/tmp/claude-safe/test-reconcile.shbuilds throwaway repos (main ahead of dev by promotion merges, mimicking manabot-alpha) and pipes a PostToolUse payload into the hook. 13 assertions across 6 scenarios, all pass:origin/dev, 0 commits ahead of dev (clean PR)symlink_filesapplieddefault_base→ no rebase, setup still runsdefault_base; stable on re-runshellcheckclean on the hook andinstall.sh.Deploy / sync
The repo does not edit the user's
settings.json. To deploy:cd ~/Code/chaimber-cliutils && ./install.sh— symlinks the hook into~/.claude/hooks/and prints the registration snippet.~/.claude/settings.jsonunder.hooks.PostToolUse. There is already anEnterWorktree|ExitWorktreematcher object runningworktree-cwd-notify.sh; the simplest path is to append to that object'shooksarray:{ "type": "command", "command": "bash ~/.claude/hooks/enterworktree-reconcile.sh" }(or add a standalone
{ "matcher": "EnterWorktree", "hooks": [...] }object — order doesn't matter).Open questions / notes
~/.claude/files — review then runinstall.sh+ the settings.json edit yourself.~/.claude/hooks/worktree-create.sh/worktree-remove.shreferencewt--is-excluded+~/.claude/chamber.user.config, which no longer exist inwtutils.sh. Those hooks are also not wired intosettings.jsonand only run outside a git repo anyway, so they're effectively dead for git repos. Out of scope here; flagging for cleanup.🤖 Generated with Claude Code