deployment
Production Claude Code: Scale & Reliability
Running Claude Code in production. Rate limits, retries, observability, cost tracking. The pieces that take you from demo to scale.
From Demo to Scale
Claude Code in Production
Running Claude Code locally is easy. Running it reliably, with rate-limit handling, retries, cost controls, and a full observability stack, is a different discipline. This breakdown covers every layer you need to go from weekend demo to always-on production system.
CI/CD
Ready
Team
Scale
24/7
Monitored
100%
Recoverable
Production Maturity
The 4 Levels
Most people stay at Level 1. Each level unlocks reliability, auditability, and team capability. Know which level you are at before adding more automation.
Level 1: Local Only
Works on your machine. Dies when you close the terminal. No logs, no recovery, no audit trail. This is where most people stop.
Level 2: Persistent
Survives reboots via launchd or systemd. Logs to file. Scheduled tasks run automatically. You can walk away and it keeps working.
Level 3: Monitored
Health checks, alerts on failure, cost tracking, full audit trail of every action. You know what happened, when, and how much it cost.
Level 4: Team Scale
Shared context, parallel agents, governance rules. Multiple developers with their own Claude Code instances, all working from shared skills and memory.
Reliability
Rate Limits & Retry Strategies
The Anthropic API has per-minute and per-day rate limits per model tier. Without defensive patterns, a single runaway loop can block your entire pipeline.
Exponential Backoff
- ›Retry after 1s, 2s, 4s, 8s, 16s
- ›Cap at 60s max wait
- ›Jitter ±10% to avoid thundering herd
- ›Max 5 retries before hard fail
Model Fallback
- ›Rate-limited on Sonnet? Fall to Haiku
- ›Track which model was used in logs
- ›Alert if Opus fallback triggered
- ›Never silently degrade quality
Quota Management
- ›Set hard limits in Anthropic console
- ›Alert at 80% of daily quota
- ›Batch non-urgent tasks overnight
- ›Use prompt caching to cut token use
#!/bin/bash
# Retry wrapper with exponential backoff
run_with_retry() {
local max=5
local delay=1
local attempt=1
while [ $attempt -le $max ]; do
"$@" && return 0
echo "[retry $attempt/$max] failed - waiting ${delay}s"
sleep $delay
delay=$((delay * 2))
attempt=$((attempt + 1))
done
echo "ERROR: command failed after $max attempts"
return 1
}
# Usage
run_with_retry claude -p "Process inbox" --output-format jsonObservability Stack
Logs · Metrics · Traces
You cannot manage what you do not measure. Claude Code hooks give you all three pillars of observability without third-party agents or SDKs.
Cost tracking via PostToolUse hook
Every tool invocation is logged with timestamp and token counts to a CSV. Build a simple dashboard on top of this data.
#!/bin/bash
# ~/.claude/hooks/cost-tracker.sh
LOGFILE="$HOME/.claude/cost-log.csv"
if [ ! -f "$LOGFILE" ]; then
echo "timestamp,tool,project,model,input_tokens,output_tokens" > "$LOGFILE"
fi
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ),${TOOL_NAME},${PROJECT:-unknown},${MODEL:-unknown},${INPUT_TOKENS:-0},${OUTPUT_TOKENS:-0}" >> "$LOGFILE"Operations
Cost Tracking
API costs compound fast. These four strategies keep spending predictable and efficient from day one.
Set spending limits
Configure hard limits in the Anthropic console. Set per-project budgets. Get alerts at 80% threshold. Never get surprised by a runaway agent.
Use the right model
Haiku for simple tasks (10x cheaper than Sonnet). Sonnet for standard work. Opus for complex reasoning only. Do not use Opus for file renaming.
Cache repeated context
CLAUDE.md and skills get cached automatically. Persistent memory means you do not re-explain context. Prompt caching cuts token usage 30-60% on repeated patterns.
Monitor with a dashboard
Cost hooks write to CSV. Aggregate by project, model, and day. Know exactly where your budget goes before it surprises you.
| Model | Relative cost | Best for | Avoid for |
|---|---|---|---|
| Claude Haiku | 1× | Bulk tasks, formatting, classification | Complex reasoning, novel code |
| Claude Sonnet | ~10× | Standard dev work, analysis, writing | Simple yes/no decisions |
| Claude Opus | ~50× | Hard reasoning, architecture decisions | File renaming, trivial edits |
Recovery
Failure Modes & Incident Playbook
When things break, follow the playbook. Do not guess. Every failure mode has a deterministic first response.
Ctrl+C to interrupt. Check ~/.claude/logs/ for the session log. Look for the last tool call; that is where it stuck. Restart with claude --resume or start fresh.
Check cost-log.csv immediately. Sort by project and timestamp. Identify the heavy session. Common cause: large file reads in a loop, or Opus used for bulk tasks. Switch to Haiku for batch operations.
First check: is CLAUDE.md current and complete? Second check: has MEMORY.md grown past 200 lines? Third: review recent skill changes. Context drift is usually the root cause.
Run claude mcp list to see status. Restart the failed server manually. Test with a simple query. If persistent, check for port conflicts or dependency updates.
File backup hook saves last 10 versions to ~/.claude/backups/. Restore with cp ~/.claude/backups/filename.bak.1 original-path. Or use Esc Esc then /rewind to undo.
Add exponential backoff to any wrapper scripts (see retry wrapper above). Use Haiku for non-critical tasks to reduce pressure on Sonnet/Opus quota.
Capacity Planning
Scaling from Solo to Team
Each growth stage introduces new bottlenecks. Plan for the next level before you hit the wall.
| Stage | Bottleneck | Solution | Precedence |
|---|---|---|---|
| Solo dev | Context re-entry each session | CLAUDE.md + persistent memory system | Day 1 |
| Automated tasks | Rate limits on burst tasks | Retry wrapper + queue with backoff | Week 1 |
| Multiple projects | Cost visibility across contexts | Per-project cost-log.csv + weekly review | Month 1 |
| Small team | Skill drift between devs | Skills + hooks in git, shared CLAUDE.md | Month 2 |
| CI/CD | Review quality inconsistency | claude-code-action on all PRs | Month 3 |
Reliability Checklist
Production Readiness
Work through this checklist before calling any Claude Code system "production". Every unchecked box is a silent risk.
Persistence
- ✓launchd / systemd unit deployed
- ✓Logs routed to dated log files
- ✓Job restarts on failure (RestartPolicy)
Observability
- ✓PostToolUse cost hook active
- ✓File change audit trail logging
- ✓Stop hook fires on session end
Cost Controls
- ✓Spending limit set in Anthropic console
- ✓Model routing: Haiku for bulk, Opus for reasoning
- ✓Weekly cost-log.csv review scheduled
Reliability
- ✓Health check script on a cron
- ✓Backups hook saving last 10 versions
- ✓Incident playbook documented and accessible
Team / CI
- ✓Skills and hooks committed to git
- ✓CLAUDE.md layers: team → personal → project
- ✓Claude Code action in GitHub Actions PR workflow
Ready to move from local setup to team scale? Claude Code training for teams covers shared conventions, enterprise rollout, and non-developer onboarding. For help architecting a production agent system, book a consultation.
Want this running in your stack?
AY Automate builds AI automation systems for production teams.