forked-subagent

Dispatch Claude sub-agents as OS subprocesses scoped to dedicated git worktrees.

1|Updated Jul 15, 2026
One-click install
npx skills add https://github.com/stefanrusek/dark-harness --skill forked-subagent-stefanrusek
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: forked-subagent
Source: https://github.com/stefanrusek/dark-harness/tree/main/.claude/skills/forked-subagent
Command: npx skills add https://github.com/stefanrusek/dark-harness --skill forked-subagent-stefanrusek

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? In-process sub-agents share one checkout, so a confused agent can write files outside its assigned scope, sweep other agents' staged files into commits, and break the main branch. This Skill launches Claude Code as a real OS subprocess with its working directory hard-scoped to a target directory or a dedicated git worktree, giving filesystem-enforced isolation instead of prompt-based convention. ## Core Features & Use Cases - Subprocess dispatch: Run claude -p non-interactively in any directory and receive a JSON result with success status, exit code, final text output, session ID, cost, and duration. - Git worktree lifecycle: Create or reuse worktrees on sibling paths, and clean them up only when they have no uncommitted changes and their branch is fully merged, leaving failed runs inspectable. - Combined flow: One command creates the worktree, dispatches the sub-agent, and applies merge-aware cleanup, with exit codes that compose with shell scripting. - Use Case: A coordinator agent dispatching an implementation task gets a sub-agent whose writes are physically confined to its own worktree, then merges the branch and cleans up automatically once the work is verified. ## Quick Start Dispatch a sub-agent to implement a task in an isolated git worktree by running the run-in-worktree script with the repo path, a branch name, and the task prompt.

Frequently Asked Questions about forked-subagent

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

FAQPage Schema
How do I run a Claude sub-agent in an isolated directory?▼

Run the dispatch script with Bun, passing --dir for the target working directory and --prompt or --prompt-file for the task. It spawns claude -p with --output-format json and prints a JSON result containing success status, exit code, final text output, session ID, and cost.

When should I use a forked subprocess instead of the in-process Agent tool?▼

Use a forked subprocess for implementation work that creates, edits, or deletes files, where filesystem-enforced isolation matters. Use the in-process Agent tool for read-only research, lookups, or analysis, since it avoids subprocess spin-up and worktree bookkeeping overhead.

How do I isolate a sub-agent's file writes with git worktree?▼

Use the run-in-worktree script with --repo, --branch, and --prompt flags. It creates or reuses a worktree at a sibling path, dispatches claude into it, and the sub-agent's writes stay confined to that worktree rather than the shared checkout.

What happens to the worktree if the sub-agent fails or leaves uncommitted changes?▼

Cleanup only removes a worktree when it has no uncommitted changes and its branch is fully merged into the base ref. Otherwise it is left in place with a printed reason so the run can be inspected, and --force removes unconditionally.

Does dispatching a sub-agent require a git repository?▼

No. The dispatch script has no git awareness and runs claude in any plain directory. Git worktree creation and cleanup are separate scripts that can be composed with dispatch or used independently.