Index of every page on this site: llms.txt
All skills
heffrey avatar

/isolating-horde-workspaces

@555219e
by Jeffheffrey/hordev4 stars
Run it yourself

Use before dispatching-hordes launches its first wave, before racing-prototypes creates candidates, and when tearing down worktrees after horde-qa passes

  • 1 file
  • 8.3 KB
  • Updated 2 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/heffrey/hordev/isolating-horde-workspaces

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈45 tokens for metadata: the name and description. ≈2.1k when used: this file.

Description uses 2.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈182 characters, or 2.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Isolating Horde Workspaces

Why Worktrees Carry More Weight Here Than You Think

Worktrees are not just collision avoidance. They are what keeps spec-driven development honest under parallelism, and hordev keeps the SDD tenets even though it drops the interview.

A worktree gives a line of work its own branch, its own history, and its own verifiable end state. That is what lets a spec stay attached to something real: this branch implements .hordev/specs/<feature-name>.md, these commits are its history, this diff is what horde-qa verified, and it can be thrown away whole if the spec was wrong. Without that, a horde's output is an undifferen- tiated pile of edits in one tree, and there is nothing to review, revert, or compare — the spec becomes a document nobody can check the code against.

The unit of isolation is a track of work, not an agent. One worktree per spec being implemented. Agents inside a track share it and stay out of each other's way through file ownership. This is the rule that decides everything below.

Never run a horde in the user's checkout, and never on the default branch.

Default: One Shared Worktree with File Ownership

Use this for most hordes. Create one worktree for the entire horde. Agents coordinate via file ownership assigned in decomposing-for-hordes: each file belongs to exactly one agent. Why: Process isolation per agent wastes merging overhead when agents do not actually collide. Ownership suffices when files are disjoint.

# Resolve the default branch instead of assuming origin/main. Repos use
# master, have no remote, or name their default something else entirely.
BASE=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null) ||
  BASE=$(git symbolic-ref --quiet --short HEAD)

# Create shared horde worktree
HORDE_ROOT=".claude/worktrees/horde-$(date +%s)"
git worktree add "$HORDE_ROOT" "$BASE" -b "horde/run-$(date +%s)"
cd "$HORDE_ROOT"

# Verify you are in the new worktree
git rev-parse --git-dir  # Should show worktree path, not .git

All agents in this run work in $HORDE_ROOT. Their ownership is enforced by their task assignment in dispatching-hordes.

Per-Agent Isolation: When and How

Create separate worktrees only when agents will:

  • Race competing prototypes (racing-prototypes). Mandatory, not optional: each candidate is a separate track of work with its own branch, so the user can open any of them and compare. Keep the losing branches until the user has seen the report — deleting them first leaves nothing to compare.
  • Run conflicting servers or builds (e.g., two agents binding port 3000, or simultaneous cargo builds)
  • Perform destructive or rollback-heavy experiments (migrations, large deletions, repo rewriting)
  • Do speculative work you expect to discard (prove feasibility, then decide)

For each agent needing isolation:

AGENT_WORKTREE=".claude/worktrees/agent-$AGENT_NAME"
git worktree add "$AGENT_WORKTREE" "$BASE" -b "horde/agent-$AGENT_NAME"

Each agent owns its worktree directory and branch. Keep it isolated: do NOT access files across worktrees.

Agents never call EnterWorktree

A session has one isolation pin, and dispatched agents share it. Three race candidates each called EnterWorktree on their own path; every call moved the pin, refused the siblings' writes, and moved the orchestrator's cwd with it. The orchestrator creates every worktree before dispatch and hands each agent an absolute path to work at. If the harness can isolate an agent itself (for Claude Code, isolation: "worktree" on the Agent call), use that instead of a pre-made path. Either way, the prompt forbids EnterWorktree in its prohibitions.

Sibling Repositories

Work that spans two git repositories (an app and its marketing site, a service and its infrastructure repo) is two tracks, because a worktree belongs to one repository. decomposing-for-hordes gives the sibling's tasks a wave of their own; this is how that wave is isolated.

  • Its own branch, in its own repository, off that repository's default branch, named for the same run in both (horde/run-<id>) so the two are found together.
  • Its own worktree inside the sibling repository, created the same way as above, before dispatch. Agents in that wave get that path and nothing from the primary worktree.
  • The orchestrator commits there too. If the session cannot run git in the sibling repository (a session isolated to one worktree may be refused), create the sibling worktree and branch before isolating, or put the exact commands in the report for the user to run. Sibling work written and never committed is not done: a single checkout in that repository discards it, and nothing in the primary branch shows it existed.
  • The report names every branch, one per repository.

Shared-State Hazards and Mitigations

Ownership does not prevent these:

Hazard Agents Affected Mitigation
Git index (.git/index) All in one worktree Agents do not run git at all. The orchestrator commits, once the tree is coherent — see dispatching-hordes. A worktree has one index, and file ownership does not protect it.
Lockfiles (package-lock.json, Cargo.lock, poetry.lock) All decomposing-for-hordes must assign lockfile ownership to ONE agent. Others use --locked or equivalent to freeze.
Generated artifacts (dist/, build/, pycache) All Assign to worktree owner. Add to .gitignore if not tracked.
Dependency caches (node_modules/, target/) All One agent installs; others skip or use read-only cached versions.
Ports and fixture databases All Document in task that port X is reserved for agent Y. Cross-check in dispatching-hordes before dispatch.
npm/cargo registries offline All One agent's network hiccup stalls everyone. Mitigate: fetch dependencies before dispatch, cache locally if possible.

Cleanup Policy

Before the horde is removed, every worktree must be safe to delete:

  • All work is committed to its branch.
  • No uncommitted changes.
  • No local state (running servers, open files).
# Check all worktrees
git worktree list

# For each worktree, verify
cd "$WORKTREE_PATH"
git status  # Must be clean
git log --oneline -5  # Verify commits exist

# Tear down after horde-qa passes
git worktree remove "$HORDE_ROOT"           # Shared worktree
git worktree remove "$AGENT_WORKTREE_1"     # Per-agent worktrees if used
git worktree remove "$AGENT_WORKTREE_2"
# ... etc

If a worktree has uncommitted work and you cannot lose it, the orchestrator — never an agent — checkpoints it:

cd "$WORKTREE_PATH"
git add .
git commit -m "Horde checkpoint: $TASK_ID"
git log --oneline -1  # Note the SHA
# Then safe to remove

Critical Rules

Never:

  • Let agents write to the user's original checkout while the horde runs. (Separate worktree enforces this.)
  • Commit horde work to the default branch. Each worktree has its own branch; use one per horde run.
  • Share a worktree across multiple horde runs. Use unique branch and worktree names per run.

Always:

  • Run git worktree list at the start to confirm the horde's isolation.
  • Pass $HORDE_ROOT or $AGENT_WORKTREE_N to all dispatched agents as an absolute path. They work there and never call EnterWorktree.
  • Commit and verify each agent's work before removing its worktree.

Run Lifecycle

  1. Before dispatching-hordes: Set up isolation (this skill). Capture $HORDE_ROOT and any per-agent worktree paths. Export them.
  2. During dispatch: Each agent receives its worktree path. Agents work only in that tree; cross-tree reads/writes are errors.
  3. After horde-qa passes: Tear down worktrees. Verify all branches pushed (if a remote exists) or at least committed.
  4. Finish: Return to the user's original checkout. It is untouched.

Battle cry

"Zug zug." — when the worktree is up and the horde is off the user's checkout. Teardown gets nothing; it is bookkeeping.

Once, at that moment — not every message, and never two messages running. Full rules in using-hordev § Voice: conversational output only, never in artifacts, never on bad news.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 555219e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 2 months ago

README badge

README badge for heffrey/hordev/isolating-horde-workspaces