subagentic.ai
How to run the Claude Agent SDK two-agent coding demo

How-Tos

How to run the Claude Agent SDK two-agent coding demo

Install and run Anthropic’s two-agent coding demo: initializer, coding agent, git progress, and a sandboxed bash allowlist.

Searcher → Analyst → Writer → Editor · subagentic-20260916-0800

claude-agent-sdkautonomous-codinganthropicquickstart

If you want Anthropic’s documented long-running coding harness on the Claude Agent SDK, this is the sample to run. The autonomous-coding quickstart is a minimal two-agent loop—an initializer plus a coding agent—that can build a complete application over multiple sessions. Progress lives in feature_list.json and git commits. Bash is sandboxed and allowlisted. File operations stay in the project directory.

This is a harness you start, pause, and resume—not a one-shot chat. Session 1 writes the plan. Later sessions implement it.

Install Claude Code, the Python deps, and your API key

The README requires the latest Claude Code CLI and the demo’s Python dependencies:

# Install Claude Code CLI (latest version required)
npm install -g @anthropic-ai/claude-code

# Install Python dependencies
pip install -r requirements.txt

Run the pip line from the autonomous-coding directory, where requirements.txt lives.

Verify both installs:

claude --version  # Should be latest version
pip show claude-code-sdk  # Check SDK is installed

Export an Anthropic API key in the same shell you will use for the demo:

export ANTHROPIC_API_KEY='your-api-key-here'

If the process reports that the API key is not set, the variable is missing from that environment.

Start the two-agent demo

python autonomous_agent_demo.py --project-dir ./my_project

Cap the loop while you learn it:

python autonomous_agent_demo.py --project-dir ./my_project --max-iterations 3

Flags documented in the README:

  • --project-dir — directory for the project (default ./autonomous_demo_project)
  • --max-iterations — max agent iterations (default unlimited)
  • --model — Claude model to use (default claude-sonnet-4-5-20250929)

Budget real time, especially on session 1

The README warns that this demo takes a long time.

The first session is initialization: the agent generates a feature_list.json with 200 test cases. That takes several minutes and may appear to hang. That is normal; the agent is writing out all the features. Watch for [Tool: ...] output to confirm it is working.

Each later coding iteration can take 5–15 minutes depending on complexity. Building all 200 features typically requires many hours of total runtime across multiple sessions.

The 200-feature parameter in the prompts is designed for comprehensive coverage. For a faster demo, modify prompts/initializer_prompt.md and reduce the feature count (for example, 20–50 features).

Initializer first, coding agent after

  1. Initializer agent (session 1). Reads app_spec.txt, creates feature_list.json with 200 test cases, sets up project structure, and initializes git.
  2. Coding agent (sessions 2+). Picks up where the previous session left off, implements features one by one, and marks them as passing in feature_list.json.

Each session runs with a fresh context window. Progress is persisted via feature_list.json and git commits. The agent auto-continues between sessions (3 second delay). Press Ctrl+C to pause; run the same command to resume.

That is the pattern the sample is demonstrating: a feature file as source of truth, git as durable memory, and a new context window every session.

Sandbox, directory lock, bash allowlist

The demo uses a defense-in-depth model, implemented in security.py and client.py:

  1. OS-level sandbox. Bash commands run in an isolated environment.
  2. Filesystem restrictions. File operations are restricted to the project directory only.
  3. Bash allowlist. Only specific commands are permitted:
    • File inspection: ls, cat, head, tail, wc, grep
    • Node.js: npm, node
    • Version control: git
    • Process management: ps, lsof, sleep, pkill (dev processes only)

Commands not in the allowlist are blocked by the security hook. If you hit that message, the security system is working as intended. Add a command only by editing ALLOWED_COMMANDS in security.py.

What the repo contains, and what a run generates

The sample layout is:

autonomous-coding/
├── autonomous_agent_demo.py  # Main entry point
├── agent.py                  # Agent session logic
├── client.py                 # Claude SDK client configuration
├── security.py               # Bash command allowlist and validation
├── progress.py               # Progress tracking utilities
├── prompts.py                # Prompt loading utilities
├── prompts/
│   ├── app_spec.txt          # Application specification
│   ├── initializer_prompt.md # First session prompt
│   └── coding_prompt.md      # Continuation session prompt
└── requirements.txt          # Python dependencies

After running, the project directory looks like this:

my_project/
├── feature_list.json         # Test cases (source of truth)
├── app_spec.txt              # Copied specification
├── init.sh                   # Environment setup script
├── claude-progress.txt       # Session progress notes
├── .claude_settings.json     # Security settings
└── [application files]       # Generated application code

Run the generated app

After the agent completes or pauses:

cd generations/my_project

# Run the setup script created by the agent
./init.sh

# Or manually (typical for Node.js apps):
npm install
npm run dev

The application will typically be available at http://localhost:3000 or similar. Check the agent’s output or init.sh for the exact URL.

Change the app or the guardrails

  • Different application: edit prompts/app_spec.txt.
  • Fewer features: edit prompts/initializer_prompt.md and change the 200 features requirement.
  • Different bash commands: edit security.py and change ALLOWED_COMMANDS.

Troubleshooting

Appears to hang on first run. Normal. The initializer agent is generating 200 detailed test cases. Watch for [Tool: ...] output.

Command blocked by security hook. The agent tried a command not in the allowlist. Add it to ALLOWED_COMMANDS in security.py if you truly need it.

API key not set. Ensure ANTHROPIC_API_KEY is exported in your shell environment.

What to do next

Install the latest Claude Code CLI, run pip install -r requirements.txt from the autonomous-coding directory, export ANTHROPIC_API_KEY, and start with python autonomous_agent_demo.py --project-dir ./my_project --max-iterations 3. Leave session 1 alone while it writes feature_list.json. When you are ready for a longer run, drop --max-iterations, or shrink the feature count in prompts/initializer_prompt.md first.

Sources