.agents/skills/git-worktree/SKILL.md
Create a dedicated git worktree for the current task, then keep working inside that new directory instead of the original checkout.
This skill is about execution, not just advice. When it triggers, actually create the worktree unless the repository state makes that impossible.
Do not introduce helper scripts for this skill. Use direct git and shell commands inline.
git worktree, independent branch directory, or isolated workspaceAfter creating the worktree, treat the new path as the active working directory for the rest of the task.
In any agent environment, "enter the directory" means:
Never claim you "switched" unless your subsequent actions actually target the new worktree_path.
If your environment supports a per-command working directory, use it for every later command. If it does not, prefix later commands with an explicit cd <worktree_path> && ....
login-timeout-fix or user-exportgit-worktree, new-worktree, or task unless the request is too vaguetask-$(date +%Y%m%d-%H%M%S)worktree/<repo-name>-<slug>Inspect the repository context from the current checkout:
git rev-parse --show-toplevelgit branch --show-currentgit status --shortgit worktree list --porcelainDecide a task slug yourself using the rules above
Build branch and path names inline, then create the worktree with direct shell commands like:
repo_root=$(git rev-parse --show-toplevel)
repo_name=$(basename "$repo_root")
parent_dir=$(dirname "$repo_root")
source_branch=$(git -C "$repo_root" branch --show-current)
if [ -n "$source_branch" ]; then
source_ref="$source_branch"
else
source_ref="HEAD@$(git -C "$repo_root" rev-parse --short HEAD)"
fi
slug="<task-slug>"
base_branch="worktree/$slug"
branch_name="$base_branch"
base_path="$parent_dir/$repo_name-$slug"
worktree_path="$base_path"
index=2
while git -C "$repo_root" show-ref --verify --quiet "refs/heads/$branch_name" || [ -e "$worktree_path" ]; do
branch_name="${base_branch}-$index"
worktree_path="${base_path}-$index"
index=$((index + 1))
done
git -C "$repo_root" worktree add -b "$branch_name" "$worktree_path" HEAD
Immediately verify the handoff inside the new worktree, for example:
pwd
git status --short --branch
These verification commands must run against worktree_path.
Announce the new active path briefly, then continue the main task there
For the remainder of the task, use worktree_path as the working directory for every relevant command or edit operation
HEAD from the current checkout so uncommitted local changes are not dragged into the new worktreeHEADThe safe default is isolation from uncommitted changes.
HEAD unless the user explicitly asks to carry local edits overWhen you use this skill:
User request:
Create a separate worktree for this task and then start implementing it.
Expected behavior:
worktree/... branch and sibling directory with direct git worktree commandsOnly remove a worktree when the user asks or when cleanup is clearly part of the task.
Before cleanup: