[FEATURE] WorktreeCreate hook should support separate worktree_path and cwd outputs
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
The WorktreeCreate hook currently uses a single stdout print to communicate both the worktree root path (used by CC for internal tracking and cleanup) and the session CWD. In multirepo/monorepo layouts where the session should open inside a subfolder of the worktree, these two values are different — and there is no way to express that distinction today
Proposed Solution
Allow WorktreeCreate hooks to return a JSON object on stdout with two distinct fields:
{
"worktree_path": "/absolute/path/to/worktree/root",
"cwd": "/absolute/path/to/worktree/root/subfolder"
}
worktree_path would be used for CC-internal tracking and WorktreeRemove.
cwd would be used as the session working directory.
For backwards compatibility, a plain string on stdout continues to mean both values are the same (current behaviour).
Alternative Solutions
Currently none that satisfies both constraints simultaneously. The best available option is to print the subfolder path and accept that WorktreeRemove does not fire and worktree cleanup must be done manually.
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
A project with multiple subprojects under a single git root:
project-root/
project-root/.claude/
project-root/project-a/ ← has its own CLAUDE.md, configs, etc.
project-root/project-b/
project-root/workers/project-c/
When invoking claude -w project-a/feat/my-branch, the desired behaviour is:
- Git worktree created at project-root/.claude/worktrees/feat/my-branch (the worktree root)
- Session CWD opens at project-root/.claude/worktrees/feat/my-branch/project-a/ (the subfolder)
The subfolder CWD is essential because:
- CC auto-loads CLAUDE.md based on CWD — each subproject has its own
- Project-specific settings, tool configs, and context all live in the subfolder
Current behaviour:
The hook prints a single path on stdout. CC uses that path for both the session CWD and internal worktree tracking (matching against registered git worktrees for cleanup and WorktreeRemove firing).
If the hook prints the subfolder path:
- ✅ Session CWD is correct, CLAUDE.md loads correctly
- ❌ CC cannot match the path to a registered git worktree → WorktreeRemove never fires, automatic cleanup on session exit does not work
If the hook prints the worktree root:
- ✅ CC cleanup and WorktreeRemove work correctly
- ❌ Session CWD is wrong, wrong (or no) CLAUDE.md is loaded
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗