Running Claude Code Against the Aggregator With a Fixed Weekly Budget: Splitting One Key Across Days
Learn how to cap Claude Code's weekly spend by splitting one API key's balance into daily slices, monitoring usage, and gracefully stopping when each day's budget is exhausted.
Why Budget Daily Instead of Weekly
A single weekly budget can be exhausted in a few heavy sessions, leaving nothing for the rest of the week. Splitting the balance into daily slices forces a steady pace and avoids surprises. Claude Code, like any API client, will keep making requests as long as the key has credit—so you need a mechanism to stop it when the day's slice is used up.
Prerequisites
- An API key from the aggregator (topped up with USDC on Base, no KYC).
- Claude Code configured to use the aggregator's endpoint and your key.
- A way to track your spending (the aggregator's dashboard or API usage endpoint).
Step 1: Determine Your Daily Slice
Decide on a weekly budget in USDC, then divide by 7 (or by the number of days you plan to work). For example, if you top up with 70 USDC and want it to last a week, your daily slice is 10 USDC. Remember that you pay official price × 1.3, so your effective spend per token is higher than the official rate.
- Keep a buffer for days with heavier usage.
- Adjust the slice based on your typical daily token consumption.
Step 2: Set Up Usage Monitoring
You need to know when the day's slice is exhausted. Options:
- Manual checks: Query the aggregator's usage endpoint periodically (e.g., via a cron job) and compare against your slice.
- Dashboard alerts: If the aggregator provides spending alerts, set a threshold at your daily slice.
- Local logging: Instrument Claude Code to log token counts and compute cost using the aggregator's pricing.
Without monitoring, you cannot enforce the slice.
Step 3: Graceful Stopping
When the daily slice is reached, stop Claude Code from making further requests. Graceful stopping means:
- Finish the current request before halting.
- Save any in-progress work.
- Prevent new sessions until the next day.
Implement this by:
- Wrapping Claude Code calls in a script that checks remaining budget before each request.
- Using a watchdog that kills the process if spending exceeds the slice.
- Setting a hard limit via the aggregator if available (e.g., per-key spending caps).
Step 4: Reset and Repeat
At the start of each day (or your chosen reset time), reset the counter for the daily slice. The weekly total remains unchanged, so you can track cumulative spend.
- Automate the reset with a scheduled job.
- Keep a log of daily usage to refine future slices.
Example Workflow
- Top up 70 USDC on the aggregator.
- Set daily slice = 10 USDC.
- Before each Claude Code session, check today's spend via the usage API.
- If spend < slice, proceed; else, stop and wait until next day.
- At midnight UTC, reset the daily counter.
Tips
- Use environment variables to configure the slice and reset time.
- Consider a soft limit (warning) and a hard limit (stop).
- Remember that contributor credits (official price × 1.1 or × 1.2) can offset costs if you contribute keys, but budgeting still applies.
- Test the stopping mechanism with a low slice to ensure it works.
By splitting your weekly budget into daily slices and enforcing graceful stops, you gain predictable spending and avoid draining your balance prematurely.