CC-301l · Module 1
Scripted Multi-Step Workflows
3 min read
A scripted workflow chains multiple Claude Code invocations into an automated pipeline. Each invocation is a -p call with a specific prompt, and the output of one step feeds into the next. This is the scripted equivalent of a multi-turn conversation — except it runs unattended, can be scheduled, and produces repeatable results.
The pattern: a shell script that invokes Claude multiple times with different prompts, passing context between steps through files or environment variables. Step 1: analyze the codebase. Step 2: generate a plan based on the analysis. Step 3: execute the plan. Each step reads the previous step's output and builds on it. The script runs end-to-end without human intervention.
#!/bin/bash
set -euo pipefail
# Step 1: Analyze
claude -p "Analyze src/api/ for common patterns. \
Output a JSON list of patterns found." \
--output-format json > /tmp/analysis.json
# Step 2: Plan
claude -p "Based on this analysis, create a refactoring plan: \
$(cat /tmp/analysis.json)" \
--output-format json > /tmp/plan.json
# Step 3: Execute (with human review gate)
echo "Plan generated. Review /tmp/plan.json before proceeding."
read -p "Execute? (y/n) " confirm
[ "$confirm" = "y" ] && \
claude -p "Execute this refactoring plan: $(cat /tmp/plan.json)"