Conversation
Introduces `wt claude init` to configure WorktreeCreate and WorktreeRemove hooks in .claude/settings.local.json, plus hidden `wt claude hook-worktree-create` and `wt claude hook-worktree-remove` subcommands that Claude Code invokes automatically. This gives Claude Code agents properly scaffolded worktrees with shared files, setup hooks, and teardown — matching `wt add`/`wt remove`.
readHookPayload used io.ReadAll which blocks until EOF — if Claude Code doesn't close the stdin pipe promptly, the hook hangs indefinitely. Replace with json.NewDecoder which returns after parsing one JSON object. Also fix hookPayload struct to match the actual Claude Code schema: worktree_name → name, remove project_dir (not in any payload), add transcript_path. Update WorktreeRemove handler to derive branch name from worktree_path since the remove payload doesn't include name. Fix pre-existing lint issues in exclude.go (file permissions, unchecked Close error).
Redirect background child process stdio to /dev/null explicitly to prevent fd inheritance hangs. Write hooks to shared/symlink so all worktrees receive them via symlink, and apply to existing worktrees on init. Skip git fetch in hook handler (blocked by sandbox). Use hook event name constants instead of string literals.
When a symlink destination already exists as a real directory (e.g. .claude/ created by Claude Code), recurse into it and symlink individual files instead of trying to replace the whole directory. This preserves worktree-local files while still symlinking shared config files like settings.local.json.
Document the Claude Code integration: features bullet, commands table entry, detailed usage section, and project layout diagram update.
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
wt claude initcommand to configure Claude Code WorktreeCreate/WorktreeRemove hooks in.claude/settings.local.jsonwt claude hook-worktree-createandwt claude hook-worktree-removesubcommands that Claude Code invokes via hooksinternal/claudepackage for settings file management (deep-merge, idempotency, removal)When configured, Claude Code agents get properly scaffolded worktrees in the project's
worktrees/directory with shared files applied and setup hooks launched in background — matchingwt addandwt removebehavior.Test plan
go test -short ./...(15 new tests acrosscmd/andinternal/claude/)golangci-lint run ./cmd/ ./internal/claude/wt claude initin a wt project, verify.claude/settings.local.jsonhas hookswt claude hook-worktree-create, verify worktree created with shared fileswt claude hook-worktree-remove, verify worktree and branch removed