Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d

## `/wt-switch-create` command (Claude Code only)

`/wt-switch-create [<branch>] [<repo>] [-- <task>]` starts work in a fresh worktree without leaving the session. It creates (or re-enters) a worktrunk worktree with `wt switch`, switches the session's working directory into it, then runs the task there. Every argument is optional: a missing branch name is picked from the task, a path-shaped token names a different repository, and the task is whatever follows `--` (or the trailing words, when there is no `--`). The worktree is a normal worktrunk worktree — it persists after the session and is merged or removed with `wt merge` / `wt remove` like any other.
`/wt-switch-create [<branch>] [<repo>] [-- <task>]` starts a task in a fresh worktree without leaving the session: it creates the worktree, switches into it, and runs the task (all arguments optional). The worktree persists like any other; merge or remove it with `wt merge` / `wt remove`.

## Statusline (Claude Code only)

Expand Down
2 changes: 1 addition & 1 deletion skills/worktrunk/reference/claude-code.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 34 additions & 36 deletions skills/wt-switch-create/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,46 @@ branch-shaped lead — all task).

Steps 1–3 come before any other work.

<!-- Maintainers: the design choices here are backed by tested evidence in
rationale.md (same directory) — read it before re-adding guards or routes. -->
<!-- Maintainers: rationale.md (same directory) covers the harness rules and
design choices behind this — read it before re-adding guards or routes. -->

1. **Pick the branch name** if none was given: short, from the task ("fix the
parser bug" → `fix-parser-bug`) and consistent with existing worktree
names, or, mid-session, from the work being moved; with nothing to derive
from, ask.
1. **Pick the branch name** if none was given: short, from the task and
consistent with existing worktree names, or, mid-session, from the work
being moved; with nothing to derive from, ask.

2. **Create the worktree** with a `Bash` call (omit `-C <repo>` when no repo
was given):
2. **Create the worktree** with a `Bash` call (omit `-C <repo>` for this repo):

```
wt -C <repo> switch --create <branch> --no-cd --format=json
```

Stdout is JSON whose `path` field is the worktree's absolute path (status
lines go to stderr). On `Branch <branch> already exists`:

- the user named the branch → rerun the same command without `--create`;
it enters the existing branch, creating its worktree if missing.
- the name was picked in step 1 → the user never chose that branch; pick
another name and rerun.

Any other failure (not a git repo, invalid name): report it and stop — do
not do the task in the original directory.

Mid-session, when the work to move is uncommitted in the current worktree,
carry it across: `git stash push -u` before creating the worktree, then
`git -C <path> stash pop` after (the stash is shared across worktrees).

3. **Re-root the session** with `EnterWorktree({path: "<path from the JSON>"})`.

If it is rejected (worktree in a different repo, session already in a
worktree, pinned cwd — the rejections are graceful and create nothing),
leave the session rooted where it is and work in the worktree through
absolute paths instead; name the worktree path when reporting back. Don't
try to `cd` there: the harness resets `cd` that leaves the session's
working directories, and `EnterWorktree` is the supported way to move a
session.

4. **Do the task** in the worktree. If there was no task text, confirm the
worktree is ready and wait for the next instruction.
lines go to stderr). On `Branch <branch> already exists`: if the user named
the branch, rerun without `--create` (it enters the branch, creating its
worktree if missing); if step 1 picked the name, pick another and rerun. Any
other failure (not a git repo, invalid name): report it and stop.

Mid-session, carry uncommitted work across: `git stash push -u` before
creating the worktree, then `git -C <path> stash pop` after (the stash is
shared across worktrees).

3. **Enter the worktree, then do the task.** Call
`EnterWorktree({path: "<path from the JSON>"})`.

- **Accepted** → the session is re-rooted in the worktree. Do the task (or,
with no task text, confirm it's ready and wait).
- **Rejected** → the worktree is in another repo (`EnterWorktree` re-roots
only within the repo your cwd is in; the rejection is graceful and creates
nothing). You can still `cd` into the worktree and work there if it's
inside an allowed directory — an entry in `permissions.additionalDirectories`,
such as `~/workspace`. So `cd <path>` and read the result:
- no `Shell cwd was reset` notice → it stuck; the worktree is reachable.
Work there and do the task.
- `Shell cwd was reset` → not reachable. Stop and ask the user to make it
reachable: add the repo, or a parent like `~/workspace`, to
`permissions.additionalDirectories` (durable, every session), or run
`/add-dir <path>` (this session). Then continue. Don't grind through
absolute paths with `cd` resetting on every command.

## Cleanup

Expand All @@ -89,6 +87,6 @@ entered by `path`, so removal is always `wt remove <branch>`.

## Scope

This command authorizes creating/entering ONE worktree — in the named repo, if
one was given — and doing the requested task. Commits, pushes, and merges still
This command authorizes creating/entering ONE worktree (in the named repo, if
one was given) and doing the requested task. Commits, pushes, and merges still
each require explicit user permission.
Loading
Loading