wt-switch-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArguments: . The first whitespace-delimited token is the branch
name for the new worktree; everything after it (if any) is the task to perform
once inside the worktree.
$ARGUMENTS参数:。第一个以空格分隔的标记是新工作区的分支名称;标记之后的所有内容(如果有的话)是进入工作区后需要执行的任务。
$ARGUMENTSWhat to do
操作步骤
-
First action — before reading any files or running any commands — callwith the first token of the arguments as the name. This re-roots the session into the new worktree.
EnterWorktree({name: "<branch-name>"})- It works because this plugin maps →
WorktreeCreate, so the new worktree lands in worktrunk's normal sibling layout (wt switch --create <name> --no-cd --format=json), not under<repo>.<branch>/..claude/worktrees/ - is idempotent: if the branch already exists, this just re-enters its worktree.
wt switch --create - If you are already inside an -created worktree (e.g. the background harness already isolated this session), skip this step —
EnterWorktreerefuses to nest. Note that you're reusing the existing worktree and continue.EnterWorktree - If fails (not a git repo, invalid branch name, etc.), report the error and stop — do not fall back to working in the original directory, since that defeats the purpose.
EnterWorktree
- It works because this plugin maps
-
After the cwd switch succeeds, proceed with the task portion of the arguments (the text after the branch name) in the new worktree. If there was no task text, just confirm the worktree is ready and wait for the next instruction.
-
首要操作——在读取任何文件或运行任何命令之前——调用,将参数的第一个标记作为名称传入。这会将会话的根目录切换到新的工作区。
EnterWorktree({name: "<branch-name>"})- 此功能的实现原理是该插件将映射为
WorktreeCreate,因此新工作区会位于worktrunk的标准同级目录结构中(wt switch --create <name> --no-cd --format=json),而非<repo>.<branch>/目录下。.claude/worktrees/ - 具有幂等性:如果分支已存在,此操作仅会重新进入其对应的工作区。
wt switch --create - 如果已经处于由创建的工作区中(例如后台管理程序已隔离当前会话),请跳过此步骤——
EnterWorktree不允许嵌套。此时只需复用现有工作区并继续操作即可。EnterWorktree - 如果执行失败(非git仓库、分支名称无效等),请报告错误并停止操作——不要退回到原工作目录继续工作,否则会违背该命令的设计初衷。
EnterWorktree
- 此功能的实现原理是该插件将
-
成功切换工作目录后,在新工作区中执行参数中的任务部分(分支名称之后的文本)。如果没有任务文本,只需确认工作区已准备就绪并等待下一条指令。
Cleanup
清理工作
Don't remove the worktree yourself. (if the
user asks to leave) or the session-exit prompt routes through this plugin's
hook → . A worktree with uncommitted
changes won't be auto-removed without confirmation — that's intended.
ExitWorktree({action: "remove"})WorktreeRemovewt remove -D --foreground请勿自行删除工作区。当用户要求退出时,或会话退出提示会通过该插件的钩子调用。存在未提交更改的工作区不会被自动删除,除非获得用户确认——这是有意设计的行为。
ExitWorktree({action: "remove"})WorktreeRemovewt remove -D --foregroundScope
权限范围
This command authorizes creating/entering ONE worktree and doing the requested
task. Commits, pushes, and merges still each require explicit user permission.
此命令授权创建/进入一个工作区并执行请求的任务。提交(commits)、推送(pushes)和合并(merges)操作仍需分别获得用户的明确许可。