How to monitor Claude Code التكلفةs without surprises (2026 دليل)
- The Anthropic console has a monthly spend ceiling but no real-time alerting — by the time you see the damage, a long وكيل session has already run its course.
- Seven مجاني tools can give you visibility into Claude Code spend; each has an honest trade-off worth knowing before you wire it in.
- Three DIY cron patterns handle most منفرد-developer budgets. If you're running وكيلs on a schedule or a team is sharing an مفتاح API, the manual approach has a ceiling.
1. The problem with Claude Code التكلفة surprises
Claude Code bills by رمز, not by session or by time. That's fine when you're editing a single file or asking a contained question. It becomes a problem the moment you introduce an وكيلic loop — a task that spawns وكيل فرعيs, reads multiple files, calls tools repeatedly, and runs while you step away from the keyboard.
The core issue is the feedback loop. The Anthropic console (console.anthropic.com) shows your monthly spend in near-real-time, and you can set a monthly usage limit that hard-stops the API once your account crosses a dollar threshold. But the console doesn't push alerts mid-session. You have to check it. And by the time a monthly limit fires, you've already spent everything up to that ceiling.
What's missing is the gap between those two things: a signal that fires during a running session, before the damage compounds. The tools and patterns below are the commوحدةy's current answers to that gap. None of them are perfect. The honest version of this دليل says so.
2. Seven مجاني tools, reviewed
These are the tools that show up consistently in r/ClaudeAI threads, GitHub issues, and the Anthropic commوحدةy forum when developers ask "how do I see what I'm spending?" أوdered roughly by how much الإعداد they require.
1. ccusage
ccusage reads the JSONL session files Claude Code writes locally to ~/.claude/ and aggregates رمز counts by day, session, or project. Run ccusage daily to see اليوم's spend. Run ccusage session --last 5 to inspect the last five sessions line by line. It's the closest thing to a first-party CLI dashboard that exists right now.
2. claudeرمزs
claudetokens (and the underlying Anthropic رمزizer library) lets you count رمزs in a string before you send it. Useful for estimating prompt التكلفة before committing a large context load, or for مبنى a pre-flight check into your own scripts that blocks requests above a رمز threshold.
3. Anthropic console (native)
The console shows your rolling monthly spend, per-model رمز breakdown, and lets you set a hard monthly limit. It's the authoritative source — everything else in this list is an approximation of what the console knows. Set your monthly limit the moment you add a payment method. Anthropic's API docs describe the limit mechanics in the billing section.
4. claude-code-usage-monitor (commوحدةy)
A Python script that reads the same local JSONL files as ccusage but surfaces them as a live terminal dashboard — a refreshing pane you can leave مفتوح in a tmux split while Claude Code runs in another. Shows رمز counts and a التكلفة estimate per session. The project was active as of early 2026 with several commوحدةy contributors.
ccusage. Requires Python and a terminal pane you can keep visible. Not useful if you're running وكيلs headless or on a remote machine.5. claude-رمز-counter (bash wrapper)
Several developers have shared minimal bash wrappers that call the Anthropic API's /messages/count_tokens endpoint (docs) before sending a prompt. The endpoint returns input_tokens without actually executing the request — useful as a pre-send gate in shell scripts. Wire it to a threshold and abort if the count is over your limit.
claudetokens. Adds one extra API round-trip per gated request, which التكلفةs a small number of رمزs itself.6. ccusage-web (dashboard fork)
A browser-based variant of ccusage that serves a local web dashboard on localhost:3000. Better for developers who prefer a GUI over a terminal output, or who want to share a read-only spend view with a teammate. Runs entirely local — no data leaves your machine.
ccusage's underlying data source constraints. The web layer adds convenience, not accuracy. Still a local-file estimate, not a live API pull.7. Anthropic Usage API (direct)
Anthropic exposes a /v1/usage endpoint on the API that returns your actual billed رمز counts per model per day — the same numbers the console shows. Querying it directly lets you build your own monitoring loop without parsing local session files. This is the authoritative source; use it if you want numbers that match your invoice.
Running Claude Code وكيلs on a schedule?
Septim Courier is a hands-off التكلفة monitoring اشتراك. It polls the Anthropic Usage API on your behalf, sends a weekly digest, and alerts you when daily spend crosses a threshold you set. $19/mo, no الإعداد مطلوب beyond your مفتاح API. Early access list is مفتوح now.
3. Three DIY monitoring patterns
If you'd rather build than subscribe, these three patterns cover most منفرد-developer monitoring needs. الكل of them use tools that are either already on your machine or installable with a single command.
Daily spend diff via cron
Run ccusage daily on a cron schedule and write the output to a log file. A second cron job compares اليوم's الإجمالي against the previous day's. If the diff exceeds a threshold, it writes an alert to a file you can pick up on login.
# In crontab -e:
# Every hour, append today's token total to a log
0 * * * * /usr/local/bin/ccusage daily --date today >> ~/.claude-cost/daily.log 2>&1
# Every morning at 8am, diff yesterday vs two days ago and flag if >20% jump
0 8 * * * /usr/local/bin/node /home/you/scripts/cost-diff.js >> ~/.claude-cost/alerts.log
# cost-diff.js reads the last two lines of daily.log,
# parses the token counts, and writes "ALERT: spend up 32% vs yesterday"
# if the ratio exceeds 1.2
Good for: catching sessions that ran overnight or over a weekend and compounded without you noticing. Not good for: catching a single runaway session mid-flight — the hourly poll is too slow.
Real-time spend alert to Slack
Poll the Anthropic Usage API every خمس دقائق via a cron job. When cumulative daily spend crosses a threshold, POST to a Slack webhook. This is the closest you can get to real-time without مبنى a full monitoring service.
# cost-alert.sh
#!/bin/bash
THRESHOLD_USD=10 # alert when daily spend exceeds $10
SLACK_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK/HERE"
# Pull today's usage from Anthropic API
TODAY=$(date +%Y-%m-%d)
RESPONSE=$(curl -s https://api.anthropic.com/v1/usage?date=$TODAY \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01")
# Parse total cost (requires jq)
COST=$(echo $RESPONSE | jq -r '.total_cost // 0')
# Alert if over threshold
if (( $(echo "$COST > $THRESHOLD_USD" | bc -l) )); then
curl -s -X POST $SLACK_WEBHOOK \
-H 'Content-type: application/json' \
--data "{\"text\":\"Claude Code spend alert: \$$COST today (threshold: \$$THRESHOLD_USD)\"}"
fi
# In crontab:
# */5 * * * * /home/you/scripts/cost-alert.sh
Good for: getting a ping before a session goes too far. Requires a Slack workspace and a few minutes to create the incoming webhook. Swap the Slack POST for an email via sendmail or a Pushover notification if you prefer.
Weekly spend digest to email
A Friday-afternoon cron job that pulls the week's رمز الإجماليs from ccusage, formats them into a plain-text summary, and sends it to your inbox. Lower-frequency, lower-noise — good for developers who run Claude Code sporadically and want a monthly mental model without checking the console daily.
# weekly-digest.sh
#!/bin/bash
RECIPIENT="you@example.com"
WEEK_DATA=$(ccusage daily --last 7)
echo "Subject: Claude Code weekly spend $(date +%Y-%m-%d)
From: alerts@localhost
To: $RECIPIENT
Weekly Claude Code usage summary:
$WEEK_DATA
-- Septim Labs cost-monitor script
" | sendmail $RECIPIENT
# In crontab (Friday at 4pm):
# 0 16 * * 5 /home/you/scripts/weekly-digest.sh
Good for: a zero-interruption summary you can scan in 30 seconds. Not good for: catching anything in real time. Treat it as a review tool, not an alert system.
4. When DIY stops scaling
The patterns above work. A senior developer can wire any of them in an afternoon. The trade-off is maintenance: cron jobs drift, Slack webخطّافات break when someone rotates the رمز, and ccusage version bumps occasionally change output formatting in ways that break shell parsers.
Three signals that the DIY approach is التكلفةing you more time than it's saving:
- You have more than one person sharing an مفتاح API or working across multiple projects, and you need per-person or per-project breakdowns rather than a single daily الإجمالي.
- You're running وكيلs on a schedule — overnight builds, background research loops, anything that runs while you're not watching — and a missed alert means waking up to a surprise bill.
- You've already been surprised once and want something that fires before the session completes, not after.
Those are the cases our tools are built for. They're not the only option, and the مجاني tools above are genuinely good. But if you're past the point where cron and shell scripts feel like the right layer of infrastructure, here's what we offer:
Septim Courier ($19/mo) handles the polling and alerting layer for you. It connects to the Anthropic Usage API with your key, sends you a weekly digest, and pushes an email alert when your daily spend crosses a threshold you configure. No scripts to maintain, no cron jobs to debug. Early access list is مفتوح at septimlabs.com/septim-courier.
Septim وكيل فرعي التكلفة Guard ($29) operates at the وكيل layer rather than the reporting layer. It installs as a PreToolUse hook in your Claude Code configuration and hard-halts a running وكيل mid-session when cumulative spend crosses your threshold. The difference from a usage alert is the timing: التكلفة Guard fires before the next tool call goes out, not after the session completes. Useful for anyone running long وكيلic sessions who wants a circuit breaker, not just a notification. Details at septimlabs.com/وكيل فرعي-التكلفة-guard.
Septim Rescue ($299) is the in-crisis option: a one-session ارتباط where we audit your Claude Code billing logs, identify where the spend compounded, and give you a written plan for preventing recurrence. If you've already had a surprise bill and want a human to walk through your specific session files, this is the path. Details at septimlabs.com/septim-rescue.
To be direct: Courier and التكلفة Guard are not the only path to solving this. The seven مجاني tools and three DIY patterns in this post will cover a منفرد developer running Claude Code in a normal workday سير العمل. The Septim tools are the paid, hands-off version of the same job. Use whichever fits where you are right now.
Already surprised by a bill this month?
Septim Rescue is a single focused session: we audit your billing logs, find where the spend compounded, and write a concrete plan to prevent it happening again. $299, completed within one business day.
الأسئلة الشائعة
ccusage can parse, and the Anthropic console shows your monthly الإجمالي. But there is no built-in alert that fires mid-session. The /context command shows your current رمز window usage, not cumulative التكلفة — those are different numbers. Real-time alerting requires either a third-party tool or the DIY patterns described above.ccusage reads your local JSONL session files and estimates التكلفة based on the رمز counts recorded there. The Anthropic console's numbers are authoritative — they include server-side overhead such as injected system prompts, tool definitions, and any caching that affects billing. In practice, ccusage tends to undercount relative to the dashboard, sometimes by 10–30% on sessions with heavy tool use. Use it to understand relative spend trends, and cross-check against the console for exact dollar amounts.Further reading
- Claude Code invisible رمز burn (April 2026) — what's causing التكلفة spikes beyond normal usage patterns, and four detection methods.
- Septim وكيل فرعي التكلفة Guard — the PreToolUse hook that hard-halts وكيلs mid-session on budget breach. $29 سعر التأسيس.
- Septim Courier — hands-off usage monitoring with weekly digests and threshold alerts. $19/mo.
- ccusage on GitHub — the most widely used مفتوح-source Claude Code usage tool.
- Anthropic Usage API docs — the authoritative reference for querying your own billing data programmatically.