-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Background
I use wtp daily for worktree management — the post-create hooks in .wtp.yml are great for automating environment setup.
Recently, Claude Code added a --worktree flag that creates an isolated worktree for each AI coding session. It supports a WorktreeCreate hook that completely replaces the default git worktree add behavior, so I was able to configure wtp as the hook. This means both humans running wtp add and Claude Code running claude --worktree get the exact same environment setup from a single .wtp.yml.
Problem
The WorktreeCreate hook must print only the absolute path of the created worktree to stdout. Claude Code reads this to set the session's working directory.
Since wtp's output is human-readable, the hook currently needs to extract the path with grep | sed:
{
"hooks": {
"WorktreeCreate": [
{
"hooks": [
{
"type": "command",
"command": "bash -c 'NAME=$(jq -r .name); OUT=$(wtp add -b \"$NAME\"); echo \"$OUT\" >&2; echo \"$OUT\" | grep \"Location:\" | sed \"s/.*Location: //\"'"
}
]
}
]
}
}This captures wtp's output, echoes it to stderr for logging, then extracts the path from the 📁 Location: line. It works, but it's fragile — any change to the output format would break it.
Proposal
Add --quiet to wtp add, consistent with the existing wtp list --quiet which outputs only paths.
wtp add -b feature-x --quiet would:
- On success: Print only the absolute worktree path to stdout, suppress progress messages
- On post-create hook failure: Still print the path (worktree itself is created), output warning to stderr — consistent with current behavior where hook failures are treated as warnings
- On worktree creation failure: Error message to stderr with non-zero exit code
The hook simplifies to:
bash -c 'NAME=$(jq -r .name); wtp add -b "$NAME" --quiet'No grep, sed, or output redirection needed.
Without the flag, behavior stays exactly the same. This is an opt-in change only.