using-git-worktrees
БесплатноБез исполняемых скриптовНе проверенUse when starting feature work that needs isolation from current workspace or before executing implementation plans - creates an isolated git worktree (via…
от osmontero★ 18 звёзд на GitHubОб этом скилле
Using Git Worktrees
Overview
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: In opencode v2, worktrees are created with the native worktree_* tools, and the session moves into the worktree — not just the shell. This keeps opencode's tracking (list/remove), project config, and AGENTS.md discovery pointing at the right place.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Default Path: Native Worktree Tools
Use this when running inside opencode v2 (the normal case). The tools are worktree_create, worktree_list, worktree_remove (Code Mode namespace opencode), plus session_move.
1. Create the worktree
Call worktree_create with a name — use the feature/branch name (e.g. auth, fix-login-timeout). It returns { directory }.
Where the worktree lands is decided by the worktree.directory setting in the project's opencode config, not by the skill:
- Not set (default): opencode's data directory,
worktree/<project-id prefix>/<name>— outside the repo, so nothing to gitignore. - Set (e.g.
"worktree": { "directory": ".worktrees" }): relative paths resolve against the project's canonical checkout. If the directory is inside the repo, it must be gitignored (see below).
Do not hand-roll the location with git worktree add — opencode only records and manages worktrees it created itself, so manual ones are invisible to worktree_list / worktree_remove.
If the user wants a non-default location, the v2-idiomatic move is to set worktree.directory in the config (and note it in AGENTS.md or memory) — not to pick a path per session.
2. Create the branch
worktree_create does not take a branch name: the new worktree is at a detached HEAD on the repo's current commit. Create the branch from inside the worktree:
git checkout -b "<branch-name>"
(git checkout main would fail — main is already checked out in the primary worktree; that is expected and not an error.)
3. Move the session into the worktree
Call session_move with the worktree directory as directory. The move takes effect at a safe boundary, so destination-dependent work (reads, edits, setup commands) belongs in the next call.
Why this instead of cd: a shell cd only changes one command's working directory; session_move re-roots the session's Location, so tool calls, config discovery, and instruction files all resolve against the worktree checkout.
4. Project-local location safety (only if inside the repo)
When worktree.directory places worktrees inside the checkout (.worktrees/, worktrees/, …), verify the directory is ignored before creating the worktree:
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
If not ignored: add it to .gitignore, commit, then create. This prevents worktree contents from polluting git status or being accidentally committed.
5. Run project setup
The worktree is a fresh checkout — dependencies are not shared with the main worktree. Auto-detect and run setup:
# Node.js
[ -f package.json ] && npm install
# Rust
[ -f Cargo.toml ] && cargo build
# Python
[ -f requirements.txt ] && pip install -r requirements.txt
[ -f pyproject.toml ] && poetry install
# Go
[ -f go.mod ] && go mod download
6. Verify clean baseline and report
Run the project's tests to confirm the worktree starts green:
# project-appropriate: npm test / cargo test / pytest / go test ./...
If tests fail: report the failures and ask whether to proceed or investigate. If they pass: report ready.
Worktree ready at <full-path> (branch <name>)
Session moved. Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
Cleanup
Pairs with finishing-a-development-branch after the work is done:
worktree_removewith the worktreedirectoryremoves a worktree opencode recorded for the project. It uses theeditpermission on that directory; setforce: trueonly to discard uncommitted changes.- Never remove a worktree with unpushed, unmerged commits without explicit confirmation — that deletes the work.
- A worktree created manually with raw git (fallback below) is not recorded by opencode; remove it with
git worktree remove <path>instead.
Fallback: Raw Git
Use git worktree add directly only when:
- Running in a harness without the native tools (Claude Code, Codex, plain terminal).
- The worktree needs a base other than the current HEAD (
git worktree add <path> -b <branch> <base-commit>). - The user explicitly asks for a manual worktree.
The same safety rules apply: gitignore check for project-local paths, setup, baseline tests, and announce the location.
Quick Reference
| Situation | Action |
|---|---|
| In opencode v2 | worktree_create → |
Установить using-git-worktrees в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл using-git-worktrees?
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates an isolated git worktree (via the native opencode v2 worktree tools) and moves the session into it
Как установить скилл using-git-worktrees?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл using-git-worktrees запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic