Claude Code cost control: how do I limit daily spend?
Run /usage to see where your tokens went. For API automation, divide your daily budget across tasks and set a spending threshold on each run.
This question is part of the free Claude Certified Developer - Foundations practice test.
Short answer
The correct answer is A. Run claude -p --max-budget-usd 1 "Review the staged diff"..
In print mode (-p), --max-budget-usd tells Claude Code to stop when its estimated API spend reaches the amount you set. The final request can take spend past the threshold. Leave room below your budget. If the job retries, the new run gets its own allowance.
The Question
A scheduled job uses an API key to review a diff. Which command gives that run a dollar threshold?
Why A is correct
In print mode (-p), --max-budget-usd tells Claude Code to stop when its estimated API spend reaches the amount you set. The final request can take spend past the threshold. Leave room below your budget. If the job retries, the new run gets its own allowance.
Why the other options are wrong
/usage shows what the session consumed. Reading the estimate after a job finishes cannot stop the job.
Turns vary in cost. One turn can read a large diff and produce a long answer.
A fresh session drops old context. The new review can still use more tokens than you planned.
Budget a day of code reviews
Suppose your API budget is $5 today. If you schedule four reviews with a $1 threshold each, you leave $1 for overages. Count retries before starting another review. Give each run the staged diff and the question you need answered. For example, ask which changed line could cause a duplicate charge. A request to explain the entire billing system gives the agent much more code to read. At the end of the day, compare the estimates with spend in your API billing console.
Ready to see how you'd score?
Take the free practice quiz and find out which Claude Certified Developer - Foundations domains you need to focus on. No signup required.
Practice 5 similar questions
Same cert, same or adjacent domain. Use these after reviewing the explanation.
Related Claude Certified Developer - Foundations Practice Questions
Quick FAQ
Does the session estimate show what I owe on a Claude subscription?
Pro and Max include usage in the plan. Open /usage to check your plan limits. If you enabled usage credits, check the separate credits row for additional spend.
Can I set one daily limit with --max-budget-usd?
The flag applies to one print-mode run. Set a threshold for each job, count retries, and leave room for a request that crosses the threshold.
Official sources used
Verify program and exam details at the source before scheduling.