Skip to content

feat: add --format=json to wt switch and CC worktree hooks#1959

Merged
max-sixty merged 5 commits intomainfrom
cc-hooks
Apr 7, 2026
Merged

feat: add --format=json to wt switch and CC worktree hooks#1959
max-sixty merged 5 commits intomainfrom
cc-hooks

Conversation

@max-sixty
Copy link
Copy Markdown
Owner

Adds --format=json to wt switch and WorktreeCreate/WorktreeRemove hooks to the Claude Code plugin, so agent-created worktrees go through wt instead of raw git.

wt switch --format=json prints structured JSON to stdout (action, branch, path, etc.) without changing any behavior — hooks, --execute, shell integration, and cd all run normally regardless of format. A SwitchFormat enum (text/json) keeps the help text clean (only valid values shown).

Plugin hooks are inline one-liners in hooks.json:

  • WorktreeCreate — pipes CC's JSON through jq to extract the branch, calls wt switch --create --format=json, extracts the path
  • WorktreeRemove — extracts the worktree path from CC's JSON, passes it directly to wt remove -D --foreground

Approval prompts still run — the hooks don't pass --yes, so wt's non-interactive detection applies normally.

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

max-sixty and others added 4 commits April 6, 2026 15:54
Add `--format=json` flag to `wt switch` for structured output, and
WorktreeCreate/WorktreeRemove hooks to the Claude Code plugin so
agent-created worktrees go through wt instead of raw git.

The format flag only affects output — hooks, --execute, shell
integration, and cd all run normally regardless of format. Hook scripts
intentionally omit --yes so wt's approval prompts still run.

Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts:
#	src/cli/mod.rs
#	src/main.rs
#	tests/snapshots/integration__integration_tests__help__help_switch_short.snap
Remove separate shell scripts; inline hooks into hooks.json. Remove
hook passes worktree path directly to `wt remove` instead of deriving
the branch name via git rev-parse. Remove timeout overrides, redundant
docs paragraph, and || true.

Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts:
#	src/cli/mod.rs
#	src/main.rs
Remove SwitchAction enum — action strings map 1:1 from SwitchResult
variants and are a serialization detail. Consolidate from_result match
arms. Use serde_json::to_string + println! to match list's JSON output
pattern.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit d6e84ed into main Apr 7, 2026
25 checks passed
@max-sixty max-sixty deleted the cc-hooks branch April 7, 2026 02:17
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