The Claude Code provider enables CLI Agent Orchestrator (CAO) to work with Claude Code (Anthropic's CLI) through your Anthropic API key or Claude subscription, allowing you to orchestrate multiple Claude-based agents.
- Anthropic API Key or Claude Subscription: Authentication for Claude Code
- Claude Code CLI: Install the CLI tool
- tmux: Required for terminal management
# Install Claude Code CLI
npm install -g @anthropic-ai/claude-code
# Authenticate
claude setup-token# Start the CAO server
cao-server
# Launch a Claude Code-backed session
cao launch --agents developer --provider claude_codeVia HTTP API:
curl -X POST "http://localhost:9889/sessions?provider=claude_code&agent_profile=developer"The Claude Code provider detects terminal states by analyzing output patterns:
- IDLE: Terminal shows
>or❯prompt, ready for input - PROCESSING: Spinner characters visible (
✶,✢,✽,✻,·,✳) with ellipsis and status text - WAITING_USER_ANSWER: Claude showing numbered selection options with
❯cursor - COMPLETED: Response marker
⏺present + idle prompt visible - ERROR: No recognizable output state
Status detection checks patterns in priority order: PROCESSING → WAITING_USER_ANSWER → COMPLETED → IDLE → ERROR.
The provider extracts the last assistant response by finding the ⏺ response marker:
- Find all
⏺markers in the output - Take the last one (final response)
- Extract text until the next
>prompt or separator line (────────) - Strip ANSI codes from the result
CAO launches Claude Code with --dangerously-skip-permissions to bypass:
- Workspace trust dialog: The "Yes, I trust this folder" prompt that appears for new directories
- Tool permission prompts: Approval dialogs for file edits, command execution, etc.
This is safe because CAO already confirms workspace trust during cao launch ("Do you trust all the actions in this folder?") or via --yolo flag. Without this flag, worker agents spawned via handoff/assign would block on the trust dialog with no way to accept it interactively.
A fallback _handle_trust_prompt() method also monitors for the trust dialog and sends Enter to accept it, in case the flag doesn't cover all scenarios.
When launched with an agent profile (e.g., --agents code_supervisor), CAO:
- Loads the profile from the agent store
- Extracts the system prompt from the Markdown content
- Passes it via
--append-system-prompt(newlines escaped to\nfor tmux compatibility) - Injects MCP servers via
--mcp-configJSON if the profile definesmcpServers
The provider builds the command via _build_claude_command():
claude --dangerously-skip-permissions [--append-system-prompt "..."] [--mcp-config "..."]
- Prompt patterns:
IDLE_PROMPT_PATTERNmatches both old>and new❯prompt styles, including non-breaking space (\xa0) - ANSI handling: All pattern matching strips ANSI codes first via
ANSI_CODE_PATTERN - Processing detection:
PROCESSING_PATTERNmatches both old format (✽ Cooking… (esc to interrupt)) and new Claude Code 2.x format (✽ Cooking… (6s · ↓ 174 tokens · thinking)) - Trust prompt exclusion:
TRUST_PROMPT_PATTERN("Yes, I trust this folder") is excluded fromWAITING_USER_ANSWERdetection to avoid false positives during initialization - Shell escaping: Uses
shlex.join()for safe command construction with multiline prompts - Exit command:
/exitviaPOST /terminals/{terminal_id}/exit
TerminalStatus.IDLE: Ready for inputTerminalStatus.PROCESSING: Working on taskTerminalStatus.WAITING_USER_ANSWER: Waiting for user inputTerminalStatus.COMPLETED: Task finishedTerminalStatus.ERROR: Error occurred
The E2E test suite validates handoff, assign, and send_message flows for Claude Code.
# Start CAO server
uv run cao-server
# Run all Claude Code E2E tests
uv run pytest -m e2e test/e2e/ -v -k claude_code
# Run specific test types
uv run pytest -m e2e test/e2e/test_handoff.py -v -k claude_code
uv run pytest -m e2e test/e2e/test_assign.py -v -k claude_code
uv run pytest -m e2e test/e2e/test_send_message.py -v -k claude_code
uv run pytest -m e2e test/e2e/test_supervisor_orchestration.py -v -k ClaudeCode -o "addopts="-
Trust Dialog Blocking:
- Claude Code should launch with
--dangerously-skip-permissionsautomatically - If the trust dialog still appears, check that the provider code includes the flag
- Claude Code should launch with
-
Processing Detection Failure:
- Verify Claude Code CLI version (
claude --version) - Newer versions may use different spinner formats — check
PROCESSING_PATTERN
- Verify Claude Code CLI version (
-
Authentication Issues:
claude setup-token # Or set ANTHROPIC_API_KEY environment variable -
Status Stuck on ERROR:
- Attach to tmux session and check terminal output
- Verify Claude Code starts correctly in a regular terminal first