Skip to content
CI/CD & Automation Intermediate

Cost-Capped PR Review

Review a PR with a strict budget limit and machine-parseable output

Command

$ "color:#7C5CFC">claude -p "Review the changes in this PR" \
    "color:#d97757">--from-pr "$PR_URL" \
    "color:#d97757">--output-format json \
    "color:#d97757">--max-budget-usd 0.50 \
    "color:#d97757">--no-session-persistence \
    "color:#d97757">--permission-mode bypassPermissions

Response

{
  "subtype": "success",
  "result": "## PR Review\n...",
  "total_cost_usd": 0.34,
  "session_id": "abc-123"
}

Parsing Code

059669">">const data = JSON.parse(output);
059669">">const review = data.result;
059669">">const cost = data.total_cost_usd;
059669">">console.log(059669">`Review cost: $${cost}`);
059669">">// Post review as PR comment
await octokit.issues.createComment({ body: review });

Gotchas

! Budget is checked between turns — first turn can exceed the cap
! --from-pr accepts a PR number (123) or full URL

Related Recipes