Skip to main content

Overview

Composable scripts let you build complex AI workflows from simple, reusable pieces. Chain scripts together like Unix commands, use dispatchers to orchestrate tool access, and leverage process isolation for clean multi-step pipelines.

The --cc Flag

--cc is shorthand for --tool cc, which explicitly selects Claude Code as the backend runtime. Use --codex for Codex CLI. When composing scripts, the runtime selection in the shebang applies to each script independently.
--codex shebangs work the same way as --cc shebangs for composable scripts — each script in a pipeline can target a different runtime. Key point: --cc alone does NOT grant tool access. You need --skip or --bypass for that.

The Dispatcher Pattern

Use --cc --skip to give the AI full access to Claude Code’s tools (shell commands, file operations, browser automation) during script execution. This creates a dispatcher — a script that can take real actions:

Why --cc --skip?

  • --cc: Selects Claude Code as the tool (explicit, for future compatibility)
  • --skip: Shorthand for --dangerously-skip-permissions (grants full tool access)
  • --live: Streams progress narration in real-time
The AI can now:
  • Run shell commands (npm test, git status, etc.)
  • Read and write files
  • Browse the web with --chrome
  • Use all Claude Code tools without permission prompts

Example: Test Runner Dispatcher

Tradeoff: Tool Output Visibility

When Claude Code runs shell commands, subprocess output is captured internally (not streamed to your terminal). You won’t see live npm test output scrolling by. Solution: Use --live and prompt the AI to narrate progress:
This gives you visibility into what’s happening through the AI’s narration.

Chaining Scripts Together

Connect scripts in Unix pipelines. Each script runs independently with clean process isolation:

Process Isolation

AI Runner clears inherited environment variables between nested calls so each script starts fresh:
Each .md script runs in isolation:
  • No inherited ANTHROPIC_MODEL or ANTHROPIC_SMALL_FAST_MODEL
  • No carried-over provider configuration (CLAUDE_CODE_USE_BEDROCK, etc.)
  • No leaked session IDs or internal state
This prevents state leakage and ensures each script behaves identically whether run standalone or as part of a pipeline.

Child Scripts Should Be Simple

Best practice: Only the top-level dispatcher should use --cc. Child scripts in pipelines should be simple prompt mode:
Why? Nested tool access creates complexity:
  • Multiple agentic loops
  • Unpredictable execution order
  • Debugging nightmares
Keep child scripts pure: input → processing → output.

Example: Multi-Stage Pipeline

dispatcher.md (top-level orchestrator):
extract-errors.md (simple filter):
analyze-patterns.md (simple analysis):
generate-report.md (simple formatter):
Run the pipeline:

Long-Running Scripts

Scripts that take more than 30 seconds (browser automation, multi-step analysis, CI/CD pipelines) should always use --live:

Why --live Matters

Without --live:
  • No output until the entire script completes
  • No indication of progress
  • Looks frozen for minutes
With --live:
  • Heartbeat while waiting for first response
  • Real-time narration of progress
  • Immediate feedback on what’s happening

Streaming at Turn Granularity

--live streams between tool calls, not during them. The AI’s text responses appear immediately, but tool execution (shell commands, file writes) completes before streaming continues. Prompt for narration:
Phrases like “print as you go”, “after each step”, or “tell me when done” prompt the AI to write text between tool calls, giving --live something to stream.

Output Redirection with --live

When stdout is redirected, --live separates narration from content:
Console (stderr):
File (stdout):
How it works:
  1. Intermediate turns (narration) stream to stderr
  2. The final turn is split at the first content marker (--- frontmatter or # heading)
  3. Preamble text goes to stderr
  4. Content from the marker onward goes to stdout (the file)
  5. A summary line appears on stderr when complete

Quiet Mode for CI/CD

Suppress all narration for clean stdout-only output:
With --quiet:
  • No status messages
  • No narration
  • No “Done” summary
  • Only the final content goes to stdout
Perfect for CI/CD pipelines where you need clean, parseable output.

Composable Patterns Reference

Simple Chain

Each script: pure input/output transformation.

Dispatcher + Workers

Top-level has tool access, workers are pure functions.

Parallel Execution

Run independent analyses concurrently.

Conditional Execution

Use exit codes to control flow.

Loop Over Inputs

Process multiple files with the same script.

Provider Selection in Pipelines

Each script in a pipeline can use a different provider:
Flags apply only to the script they precede:

Security Considerations

Dispatcher scripts with --skip or --bypass have full system access. Follow these guidelines:
  1. Audit before running: Review dispatcher scripts that run commands or write files
  2. Restrict child scripts: Keep children read-only (no --skip)
  3. Use --allowedTools for granular control:
  4. Never pipe untrusted sources with --skip: