/onex:using_git_worktreesfrom onex
Creates isolated Git worktrees for parallel feature development with smart directory selection and safety verification. Automatically checks .gitignore and CLAUDE.md preferences.
Ships in onex. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Follow this priority order:
# Check in priority order
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative
If found: Use that directory. If both exist, .worktrees wins.
grep -i "worktree.*director" CLAUDE.md 2>/dev/null
If preference specified: Use it without asking.
If no directory exists and no CLAUDE.md preference:
No worktree directory found. Where should I create worktrees?
1. .worktrees/ (project-local, hidden)
2. ~/.config/worktrees/<project-name>/ (global location)
Which would you prefer?
When agents (subagents, general-purpose agents, automated workflows) create worktrees, they MUST use the canonical location:
$ONEX_STATE_DIR/worktrees/{repo}/{branch}
This location:
Do NOT use project-local directories for agent worktrees. Project-local .worktrees/ is for human-driven workflows only.
MUST verify .gitignore before creating worktree:
# Check if directory pattern in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore
If NOT in .gitignore:
Per best practices "Fix broken things immediately":
Why critical: Prevents accidentally committing worktree contents to repository.
No .gitignore verification needed - outside project entirely.
project=$(basename "$(git rev-parse --show-toplevel)")
# Determine full path
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.config/worktrees/*)
path="~/.config/worktrees/$project/$BRANCH_NAME"
;;
esac
# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
After every worktree creation, install pre-commit hooks before writing any code:
cd ${ONEX_WORKTREES_ROOT:-~/omni_worktrees}/$TICKET/$REPO
pre-commit install --install-hooks
This is mandatory — pre-commit hooks enforce hardcoded-topic lint, import ordering,
and other checks that run on every commit. Without this step, hooks never execute.
If pre-commit is not in the venv: uv add pre-commit --dev or pip install pre-commit.
Auto-detect and run appropriate setup:
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi
# Python
if [ -f pyproject.toml ]; then uv sync; fi
# Go
if [ -f go.mod ]; then go mod download; fi
Run tests to ensure worktree starts clean:
# Examples - use project-appropriate command
npm test
cargo test
pytest
go test ./...
If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
When creating a worktree at $ONEX_STATE_DIR/worktrees/, write a .claude-session.json marker file in the worktree root immediately after creation:
# After git worktree add
# NOTE: Run this from the parent repo directory, NOT from within the new worktree.
# git rev-parse --show-toplevel returns the worktree root if run inside one,
# which would set parent_repo_path incorrectly and break SessionEnd cleanup.
cat > "${worktree_path}/.claude-session.json" <<MARKER
{
"session_id": "${SESSION_ID}",
"created_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"repo": "${project}",
"branch": "${BRANCH_NAME}",
"worktree_path": "${worktree_path}",
"parent_repo_path": "$(git rev-parse --show-toplevel)",
"creator": "using-git-worktrees/1.0.0",
"cleanup_policy": "session-end"
}
MARKER
| Field | Required | Purpose |
|---|---|---|
session_id | Yes | Links worktree to creating session for cleanup scoping |
created_at | Yes | ISO-8601 timestamp of creation |
repo | Yes | Repository name (basename of repo root) |
branch | Yes | Branch name used for the worktree |
worktree_path | Yes | Absolute path to the worktree directory |
parent_repo_path | Yes | Absolute path to the main repository |
creator | Yes | Skill name and version that created this worktree |
cleanup_policy | Yes | Must be "session-end" -- signals automatic cleanup |
Without this marker, the worktree will NOT be cleaned up automatically.
When a Claude Code session ends, the SessionEnd hook scans $ONEX_STATE_DIR/worktrees/ for worktrees with .claude-session.json markers matching the current session ID.
A worktree is removed if ALL conditions are met:
.claude-session.json marker with cleanup_policy: "session-end"session_id matches the ending sessionparent_repo_path from marker exists and is a valid directorygit diff --quiet)git diff --cached --quiet)$ONEX_STATE_DIR/worktrees/ (traversal guard)If ANY condition fails, the worktree is logged as STALE but NOT deleted.
| Scenario | Action |
|---|---|
| Clean worktree, matching session | Removed via git worktree remove |
| Clean worktree, different session | Skipped (belongs to another session) |
| Dirty worktree, any session | Skipped + logged as STALE |
No .claude-session.json | Skipped entirely |
| Malformed marker | Skipped + logged as STALE |
For stale worktrees that weren't auto-cleaned:
# List all worktrees under $ONEX_STATE_DIR/worktrees
find $ONEX_STATE_DIR/worktrees -name '.claude-session.json' -exec jq -r '.repo + "/" + .branch + " (session: " + .session_id + ")"' {} \;
# Remove a specific stale worktree (from parent repo)
cd /path/to/parent/repo
git worktree remove $ONEX_STATE_DIR/worktrees/repo/branch
git worktree prune
| Situation | Action |
|---|---|
.worktrees/ exists | Use it (verify .gitignore) |
worktrees/ exists | Use it (verify .gitignore) |
| Both exist | Use .worktrees/ |
| Neither exists | Check CLAUDE.md -> Ask user |
| Directory not in .gitignore | Add it immediately + commit |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
| Agent creating worktree | Use $ONEX_STATE_DIR/worktrees/{repo}/{branch} |
Worktree created at $ONEX_STATE_DIR/worktrees/ | Write .claude-session.json marker |
| Session ending | Auto-cleanup matching clean worktrees |
| Stale worktree logged | Manual cleanup required |
Skipping .gitignore verification
Assuming directory location
Proceeding with failing tests
Hardcoding setup commands
You: I'm using the using-git-worktrees skill to set up an isolated workspace.
[Check .worktrees/ - exists]
[Verify .gitignore - contains .worktrees/]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]
Worktree ready at <home>/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth feature
Never:
rm -rf to clean up worktrees (use git worktree remove instead).claude-session.json markerAlways:
.claude-session.json when creating agent worktreesgit worktree remove + git worktree prune for cleanupCalled by:
Pairs with:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (omninode-ai/omniclaude) — no native marketplace selected
npx claudepluginhub p/omninode-ai-onex-plugins-onex128 skills in this plugin
/adversarial_pipelineAdversarial PipelineAutonomous 3-stage adversarial plan-to-ticket pipeline — design_to_plan → hostile_reviewer gate (≥3 issues required) → plan_to_tickets. All stages run as background agents. Zero foreground work./agent_healthcheck/onex:agent_healthcheck — dispatch-only shimDispatch-only shim for agent stall detection and recovery. All detection and recovery logic lives in node_worker_stall_recovery (omnimarket). The skill parses args, builds the input envelope, dispatches to the node, and renders the receipt./aislop_sweep