# Switch Worktree

> Switch the current session to work in an existing git worktree

- Skill: `majiayu000/switch-worktree` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/switch-worktree`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/switch-worktree/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/switch-worktree

---


# Switch to worktree

Switch the current session to an existing worktree.

## Steps

### 1. Resolve the worktree

If `$ARGUMENTS` is empty, list available worktrees and ask the user to pick one:

```
git worktree list
```

Otherwise, let `NAME` = `$ARGUMENTS`. The worktree path is `<repo-root>/.worktrees/<NAME>`.

Verify the worktree exists in `git worktree list` output. If not, stop with an error.

Let `WORKTREE` = the absolute path to the worktree.

### 2. Switch cwd

```
cd WORKTREE
```

Then verify the switch took effect:

```
pwd
```

If `pwd` does not show `WORKTREE`, stop with an error — the cwd did not persist.

### 3. Report

```
Switched to worktree: WORKTREE
Branch: <current branch from git branch --show-current>
```

