using-git-worktrees

Manages git worktree lifecycle for parallel agents with port offsets and hygiene gates.

Updated Mar 22, 2026
One-click install
npx skills add https://github.com/diazMelgarejo/orama-system --skill using-git-worktrees-diazmelgarejo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-git-worktrees
Source: https://github.com/diazMelgarejo/orama-system/tree/main/bin/orama-system/skills/using-git-worktrees
Command: npx skills add https://github.com/diazMelgarejo/orama-system --skill using-git-worktrees-diazmelgarejo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? When multiple AI agents write to the same repository simultaneously, they collide on files, ports, and sequential document numbering. This Skill provides a complete git worktree lifecycle so parallel agents can work in isolated checkouts without corrupting each other's state. ## Core Features & Use Cases - Worktree Bootstrap: Creates isolated worktrees under ~/code/oramasys/worktrees/<slug>/ with automatic stale lock cleanup, .gbrain-source pinning, and per-worktree ENV_OFFSET port assignment (index × 100). - Mandatory Hygiene Gate: Enforces repo_hygiene.py checks before every commit to catch hardcoded machine paths, Unicode bidi controls, banned terms, and docs/v2/ ordinal collisions. - Coordination Protocols: Handles board-job source-ref verification, sequential numbering reservation via README "Next free slot", nested-branch merge protocol for concurrent edits, and safe cleanup via git worktree remove. - Use Case: Two agents both need to add documents to docs/v2/ on the orama-system repo. Each bootstraps its own worktree, reserves its ordinal by committing the README slot update first, works on offset ports (3100 vs 3200), and merges without silent collisions. ## Quick Start Ask the agent to bootstrap a new git worktree for your feature branch using the worktree-bootstrap script and then follow the hygiene gate before committing.

Frequently Asked Questions about using-git-worktrees

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run parallel AI agents on the same git repository?

Create a separate git worktree per agent using the worktree-bootstrap script, which assigns each worktree a unique ENV_OFFSET so services bind to different ports. Each agent then works in its own checkout under ~/code/oramasys/worktrees/ without file collisions.

How do I avoid port collisions between git worktrees?

The bootstrap script writes a .worktree-env file with ENV_OFFSET equal to the worktree index times 100. Source that file so services like AlphaClaw and PT bind to offset ports such as 3100 or 3200 instead of the canonical 3000 and 8000.

When should I use a git worktree instead of the canonical checkout?

Use a worktree when the agent will write files and another agent is concurrently writing to the same repo. Board-assigned jobs also require a fresh worktree created from the row's source_ref, verified against expected_base_sha before editing.

Why does git stash pop fail or cause hook problems in a worktree?

Local git hooks can interfere with stash pop or apply operations. Disable hooks first with git -c core.hooksPath=/dev/null stash pop, then reinstall them with scripts/git/install-local-hooks.sh afterward.

How do I safely remove a git worktree after finishing a branch?

Run git worktree remove <path> from the canonical checkout, then verify with git worktree list and delete the branch with git branch -d. Never use rm -rf on the worktree directory because it leaves a dangling entry in the worktree list.

What causes docs/v2 ordinal collisions with parallel agents?

Two agents can independently compute the same next number and both write files like 18-slug.md, which git accepts silently. Reserve your number first by committing the README "Next free slot" update before writing the document.