Cost & Performance Intermediate
Batch for Cache Hits
Run similar prompts back-to-back with identical system prompts to maximize cache savings
Command
"color:#9CA3AF;font-style:italic"># Same system prompt across all calls = cache hits $ "color:#7C5CFC">for item in "$@"; "color:#7C5CFC">do "color:#7C5CFC">claude -p "Analyze: $item" \ "color:#d97757">--system-prompt "You are a code review assistant." \ "color:#d97757">--output-format json \ "color:#d97757">--no-session-persistence \ "color:#d97757">--permission-mode bypassPermissions "color:#7C5CFC">done
Response
// Call 1: cache_creation_input_tokens: 14253 (pays write cost) // Call 2: cache_read_input_tokens: 14253 (90% savings!) // Call 3: cache_read_input_tokens: 14253 (90% savings!) // ... // Must run within 5-minute window before cache expires
Parsing Code
059669">">// Keep system prompts identical across calls: 059669">">// ✅ Same --system-prompt string = cache hit 059669">">// ❌ Different prompts = cache miss (pays write cost again) 059669">">// 059669">">// Stateless with stable prompt (simplest SaaS pattern): 059669">">for (059669">">const item 059669">">of items) { execFileSync(059669059669">">'claude', [059669059669">">'-p', 059669">`Analyze: ${item}`, 059669059669">">'--system-prompt', STABLE_PROMPT, 059669059669">">'--no-session-persistence', 059669059669">">'--output-format', 059669">'json' ], opts); }
Gotchas
! Ephemeral cache expires after 5 minutes of idle — run calls back-to-back
! Keep system prompts byte-identical across calls for maximum cache hits