wt-switch-create

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Arguments:
$ARGUMENTS
. 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
第一个以空格分隔的标记是新工作区的分支名称;标记之后的所有内容(如果有的话)是进入工作区后需要执行的任务。

What to do

操作步骤

  1. First action — before reading any files or running any commands — call
    EnterWorktree({name: "<branch-name>"})
    with the first token of the arguments as the name. This re-roots the session into the new worktree.
    • It works because this plugin maps
      WorktreeCreate
      wt switch --create <name> --no-cd --format=json
      , so the new worktree lands in worktrunk's normal sibling layout (
      <repo>.<branch>/
      ), not under
      .claude/worktrees/
      .
    • wt switch --create
      is idempotent: if the branch already exists, this just re-enters its worktree.
    • If you are already inside an
      EnterWorktree
      -created worktree (e.g. the background harness already isolated this session), skip this step
      EnterWorktree
      refuses to nest. Note that you're reusing the existing worktree and continue.
    • If
      EnterWorktree
      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.
  2. 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.
  1. 首要操作——在读取任何文件或运行任何命令之前——调用
    EnterWorktree({name: "<branch-name>"})
    ,将参数的第一个标记作为名称传入。这会将会话的根目录切换到新的工作区。
    • 此功能的实现原理是该插件将
      WorktreeCreate
      映射为
      wt switch --create <name> --no-cd --format=json
      ,因此新工作区会位于worktrunk的标准同级目录结构中(
      <repo>.<branch>/
      ),而非
      .claude/worktrees/
      目录下。
    • wt switch --create
      具有幂等性:如果分支已存在,此操作仅会重新进入其对应的工作区。
    • 如果已经处于
      EnterWorktree
      创建的工作区中(例如后台管理程序已隔离当前会话),请跳过此步骤——
      EnterWorktree
      不允许嵌套。此时只需复用现有工作区并继续操作即可。
    • 如果
      EnterWorktree
      执行失败(非git仓库、分支名称无效等),请报告错误并停止操作——不要退回到原工作目录继续工作,否则会违背该命令的设计初衷。
  2. 成功切换工作目录后,在新工作区中执行参数中的任务部分(分支名称之后的文本)。如果没有任务文本,只需确认工作区已准备就绪并等待下一条指令。

Cleanup

清理工作

Don't remove the worktree yourself.
ExitWorktree({action: "remove"})
(if the user asks to leave) or the session-exit prompt routes through this plugin's
WorktreeRemove
hook →
wt remove -D --foreground
. A worktree with uncommitted changes won't be auto-removed without confirmation — that's intended.
请勿自行删除工作区。当用户要求退出时,
ExitWorktree({action: "remove"})
或会话退出提示会通过该插件的
WorktreeRemove
钩子调用
wt remove -D --foreground
。存在未提交更改的工作区不会被自动删除,除非获得用户确认——这是有意设计的行为。

Scope

权限范围

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)操作仍需分别获得用户的明确许可。