Skip to content
Getting Started Simple

Set a Budget Cap

Limit spending per invocation with --max-budget-usd

Command

$ "color:#7C5CFC">claude -p "Analyze this file" "color:#d97757">--output-format json "color:#d97757">--max-budget-usd 1.00

Response

{
  "subtype": "error_max_budget_usd",
  "is_error": false,
  "total_cost_usd": 0.152,
  "result": ""
}

Parsing Code

059669">">const data = JSON.parse(output);
059669">">if (data.subtype === 059669059669">">'error_max_budget_usd') {
  059669">">console.warn(059669">`Budget exceeded: $${data.total_cost_usd}`);
} 059669">">else {
  console.log(data.result);
}

Gotchas

! Budget is checked BETWEEN turns, not mid-generation — a single turn can blow past the limit
! Minimum Opus call costs ~$0.016 due to system prompt overhead

Related Recipes