Create Worktree
Codex Compatibility
When running this skill in Codex, translate Claude Code-only primitives before acting: AskUserQuestion -> chat/request_user_input, TodoWrite -> update_plan, Task/TaskCreate/TeamCreate/SendMessage -> spawn_agent/send_input/wait_agent when available and allowed, and EnterPlanMode/ExitPlanMode -> a concise chat plan plus explicit approval.
Resolve Read/Write/Edit/Bash/WebSearch/WebFetch to Codex file/shell/web tools, and map ~/.claude/... paths to ~/.agents/... or ~/.codex/... unless the task explicitly targets Claude Code. EnterWorktree is Claude Code–only — on Codex, switch into the worktree with cd /absolute/path/to/new-worktree instead (the script already ran git worktree add).
Cursor Compatibility
When running this skill in Cursor Agent, translate Claude Code-only primitives before acting: AskUserQuestion -> AskQuestion; TodoWrite -> Cursor TodoWrite or an equivalent checklist; Task/TaskCreate/TeamCreate/SendMessage/multi-agent flows -> Cursor Task (subagents), parallel Tasks, or run_in_background when allowed (TeamCreate/SendMessage may have no exact match); EnterPlanMode/ExitPlanMode -> Plan mode (SwitchMode / CreatePlan) plus explicit user approval.
Resolve Read/Write/Edit/StrReplace/Bash/web/search/MCP via Cursor Composer or Agent equivalents. MCP names written as mcp__server__tool typically map to call_mcp_tool with configured server identifiers. Map ~/.claude/... to ~/.cursor/skills/, .cursor/skills/, and .cursor/rules/ unless the task explicitly targets Claude Code. EnterWorktree is Claude Code–only — on Cursor, switch into the worktree with cd /absolute/path/to/new-worktree instead (the script already ran git worktree add).
Creates a git worktree at <parent>/<project>-<branch>, copies .gitignored configuration files (excluding heavy build/dependency dirs), and navigates into it.
Steps
Get the branch name. Ask the user via
AskUserQuestionif not provided. Suggested format:feat/...,fix/..., or any topic name.Run the script from the current project root:
bash ~/.claude/skills/create-worktree/scripts/create-worktree.sh <branch-name>Read the printed
Path:line from the script output. The script ends with:Path: /absolute/path/to/new-worktreeSwitch the session into the new worktree using the
EnterWorktreetool with the printed path. The script already registered the worktree viagit worktree add, so it appears ingit worktree listandEnterWorktreecan enter it directly:EnterWorktree({ path: "/absolute/path/to/new-worktree" })This actually moves the agent's working directory into the worktree (unlike a bare
cd, whose shell state does not propagate out of aBashcall). On non–Claude Code agents that lackEnterWorktree, fall back tocd /absolute/path/to/new-worktree(see compat notes).Confirm to the user in Japanese (per global preference):
- 新しいworktreeのパス
- 現在の作業ディレクトリがその worktree に切り替わったこと
.env等の ignored ファイルがコピー済みであることnode_modules等の重いディレクトリはスキップしたのでpnpm installが必要な旨
What gets copied
All entries listed by git ls-files --others --ignored --exclude-standard --directory — typically .env, .env.local, .vercel/ config, .tsbuildinfo, etc.
What gets excluded (always skipped)
node_modules, .next, dist, build, .cache, coverage, .turbo, .vercel/output, .serena, test-results, playwright-report, storybook-static, out, html, .yarn
Branch handling
- Existing local branch → checks it out in the new worktree
- New branch name → creates it from current
HEAD - Branch names with
/(e.g.,feat/foo) → directory uses-(e.g.,corelive-feat-foo)
Failure modes
- Not in a git repo → error
- Target directory already exists → error (will not overwrite)
- Branch already checked out in another worktree → git's own error surfaces
Notes
- Sibling-of-current-worktree placement: works whether invoked from the main checkout or another worktree.
- The directory switch must be issued by the agent after the script returns; shell state does not propagate out of the script. Prefer
EnterWorktree({ path })so the switch persists for the rest of the session; a barecdin aBashcall does not.