FOSS · MIT—Open-source agent-swarm, the operating system for all your AI agents→
How-To/Claude Code Out-of-Process Orchestration: Full Setup Guide | desplega.ai

Claude Code Out-of-Process Orchestration: Full Setup Guide | desplega.ai

Learn how to configure Claude Code for out-of-process orchestration, enabling automated multi-agent workflows and E2E test pipelines from external systems.

Out-of-process orchestration means running Claude Code as a managed subprocess that your own scripts, build tools, or test runners can invoke, feed prompts to, and harvest output from — without ever opening the interactive TUI. This pattern unlocks multi-agent pipelines, CI-driven test generation, and reproducible automation. If you're also evaluating IDE-native setups, see our companion guide on configuring MCP servers for Claude Code for the in-process counterpart.

Install Claude Code CLI

Install the Claude Code CLI globally via npm so it is available as a subprocess your orchestrator can invoke programmatically. A global install puts the claude binary on your PATH, which is essential for spawning it from arbitrary working directories inside CI runners and worker containers.

npm install -g @anthropic-ai/claude-code

Set Your Anthropic API Key

Export your Anthropic API key as an environment variable so non-interactive Claude Code processes can authenticate without a browser prompt. Store the secret in your CI provider's encrypted secret manager and inject it into the job environment at runtime — never commit it to source control.

export ANTHROPIC_API_KEY=sk-ant-...

Run Claude Code in Non-Interactive Mode

Pass the --print --bare flags combined with a prompt string to run Claude Code as a one-shot subprocess that writes its output to stdout and exits. This is the fundamental building block of every out-of-process workflow: predictable invocation, predictable termination, and a clean exit code your orchestrator can branch on.

claude --print --bare "Generate a Playwright test for the login flow" > test_output.ts

Pipe Input from Your Orchestrator Process

Spawn Claude Code as a child process from your orchestration script, pipe instructions to stdin, and capture stdout for downstream processing in your pipeline. Using spawnSync keeps the call deterministic and lets your higher-level agent framework treat each Claude invocation as a pure function from prompt to artifact.

import { spawnSync } from 'child_process';

const result = spawnSync(
  'claude',
  ['--print', '--bare', '--dangerously-skip-permissions'],
  {
    input: 'Write a Playwright test that checks the dashboard loads within 3 seconds.',
    encoding: 'utf-8',
    env: { ...process.env }
  }
);

console.log(result.stdout);

Enable Structured JSON Output

Add the --bare --output-format json flags so your orchestrator receives a machine-readable response envelope it can parse reliably rather than free-form text. Structured output is critical when you chain multiple agents together: each downstream step needs to extract specific fields without resorting to brittle regexes.

claude --print --bare --output-format json "List the test cases needed for a checkout flow" | jq '.result'

Skip Permission Prompts for Automation

Use the --dangerously-skip-permissions flag in sandboxed CI environments to prevent interactive permission dialogs from blocking your out-of-process workflow. Only enable this inside ephemeral, isolated containers — never on a developer workstation with persistent secrets or production credentials mounted.

claude --print --bare --dangerously-skip-permissions "Refactor the auth helper to use environment variables"

Wire Claude Code Output into Your E2E Test Pipeline

Consume the generated test files from Claude Code stdout and write them to your test directory, then immediately invoke your test runner so the full loop executes in one CI step. Pair this with desplega.ai to feed any failures back into a follow-up Claude invocation that proposes a patch — closing the generate, run, repair cycle without human intervention.

#!/bin/bash
set -e

claude_output=$(claude --print --bare --dangerously-skip-permissions \
  "Generate a Playwright spec for /checkout in TypeScript")

echo "$claude_output" > tests/e2e/checkout.spec.ts

npx playwright test tests/e2e/checkout.spec.ts

With these seven primitives in place — install, auth, non-interactive mode, stdin piping, bare JSON output, permission skipping, and runner integration — you have a complete foundation for treating Claude Code as a composable agent inside any larger orchestration system. From here you can layer queues, retries, parallel fan-out, and cost budgeting on top of the same subprocess contract.