Skip to content

工具描述:EnterWorktree 进入工作树

Tool Description: EnterWorktree

v2.1.51

Tool description for the EnterWorktree tool.

仅当用户明确要求在工作树中工作时才使用此工具。此工具创建一个隔离的 git worktree 并将当前会话切换到其中。

使用时机

  • 用户明确提到 "worktree"(例如,"start a worktree"、"work in a worktree"、"create a worktree"、"use a worktree")

禁止使用时机

  • 用户要求创建分支、切换分支或在不同分支上工作 —— 请改用 git 命令
  • 用户要求修复 bug 或开发功能 —— 除非他们特别提到 worktree,否则请使用正常的 git 工作流
  • 除非用户明确提到 "worktree",否则切勿使用此工具

前提条件

  • 必须在 git 仓库中,或者在 settings.json 中配置了 WorktreeCreate/WorktreeRemove hooks
  • 当前不能已处于 worktree 中

行为

  • 在 git 仓库中:在 .claude/worktrees/ 目录内创建一个新的 git worktree,并基于 HEAD 创建一个新分支
  • 在 git 仓库外:委托给 WorktreeCreate/WorktreeRemove hooks 以实现与 VCS 无关的隔离
  • 将会话的工作目录切换到新的 worktree
  • 会话退出时,将提示用户保留或删除 worktree

参数

  • name(可选):worktree 的名称。如果未提供,则生成一个随机名称。

英文原文 / English Original

Use this tool ONLY when the user explicitly asks to work in a worktree. This tool creates an isolated git worktree and switches the current session into it.

When to Use

  • The user explicitly says "worktree" (e.g., "start a worktree", "work in a worktree", "create a worktree", "use a worktree")

When NOT to Use

  • The user asks to create a branch, switch branches, or work on a different branch — use git commands instead
  • The user asks to fix a bug or work on a feature — use normal git workflow unless they specifically mention worktrees
  • Never use this tool unless the user explicitly mentions "worktree"

Requirements

  • Must be in a git repository, OR have WorktreeCreate/WorktreeRemove hooks configured in settings.json
  • Must not already be in a worktree

Behavior

  • In a git repository: creates a new git worktree inside .claude/worktrees/ with a new branch based on HEAD
  • Outside a git repository: delegates to WorktreeCreate/WorktreeRemove hooks for VCS-agnostic isolation
  • Switches the session's working directory to the new worktree
  • On session exit, the user will be prompted to keep or remove the worktree

Parameters

  • name (optional): A name for the worktree. If not provided, a random name is generated.