spawning-agents-on-the-command-line

Spawn fresh Claude subagents via CLI backgrounding with JSON output.

1|2|Updated Aug 7, 2025
One-click install
npx skills add https://github.com/snits/claude-files --skill spawning-agents-on-the-command-line
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spawning-agents-on-the-command-line
Source: https://github.com/snits/claude-files/tree/main/skills/spawning-agents-on-command-line
Command: npx skills add https://github.com/snits/claude-files --skill spawning-agents-on-the-command-line

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When subagents need to work independently and the Task tool isn't available, you can spawn Claude instances from the command line to delegate analysis with clean context and structured JSON responses.

Core Features & Use Cases

  • CLI background spawning: Write a focused prompt, then background a Claude instance.
  • Fresh context, parallel analysis: Each agent runs with isolated context to avoid cross-talk.
  • Structured outputs: JSON responses simplify downstream processing and aggregation.

Quick Start

  1. Write a focused prompt to a file (prompt.txt).
  2. Background the agent: cat prompt.txt | claude -p --output-format json
  3. Poll for completion using BashOutput with a bash_id
  4. Parse the JSON response to continue the parent task

Frequently Asked Questions about spawning-agents-on-the-command-line

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

FAQPage Schema
How do I spawn Claude agents from the command line to delegate work?

Spawn Claude agents via CLI by writing a focused prompt to a file, then backgrounding a Claude instance with `cat prompt.txt | claude -p --output-format json`. Each agent runs with isolated context, returning structured JSON responses you can parse and poll for completion.

When should I use CLI-spawned agents instead of the Task tool?

Use CLI-spawned agents when the Task tool is unavailable, you need parallel analysis with clean context, context budgets are tight, or shared conversation history should not be serialized. Each agent operates independently without cross-talk.

How do I handle JSON responses from backgrounded Claude instances?

Parse JSON responses using BashOutput with polling and error handling to track completion status. The structured output format simplifies downstream processing and aggregation of results from multiple agents.

Can I give spawned agents access to files on my system?

Yes, use the optional `--add-dir` flag when backgrounding the agent to grant file access. Combine this with your focused prompt file to enable agents to analyze or process specific directories.

What's the difference between spawning agents and running Claude interactively?

Spawned agents run in isolated contexts with fresh state, enabling parallel execution and avoiding serialized conversation history bloat. Interactive sessions maintain shared context; backgrounded agents are suited for delegation, testing, and scenarios requiring clean separation.