🇺🇸 English | 🇮🇹 Italiano
A local budget guardian for Claude Code — tracks tokens, blocks overspend.
If you share a Claude Max subscription across multiple machines, one session can silently drain the weekly quota before you switch to the other machine. spooky-proxy sits between Claude Code and the API, reads token usage directly from local files, and cuts the connection the moment you hit your self-imposed limit.
No API calls. No account credentials. Everything is already on disk.
- Zero-overhead token tracking — reads
~/.claude/projects/**/*.jsonl, no upstream requests - 3 rolling budget windows — session (24h), weekly all-models (7d), weekly Sonnet (7d) — mirrors
/usagein Claude Code - Automatic blocking — returns HTTP 429 when any window exceeds your threshold
- Calibration — infers absolute subscription limits from
/usagepercentages in one command - Joint two-machine calibration — correctly accounts for tokens used on a second machine
- Web dashboard — live usage bars, budget slider, calibration form at
http://localhost:8990 - Fail-open — any scan or config error lets requests through; never permanently blocks you
- Transparent proxy — full API compatibility: streaming, thinking, images, all models
# 1. Clone and build
git clone https://github.com/ccavo001/claude-spooky-proxy
cd claude-spooky-proxy && make build
# 2. Point Claude Code at the proxy (add to ~/.zshrc)
export ANTHROPIC_BASE_URL=http://localhost:8990
export MACHINE_NAME=laptop
# 3. Start
source ~/.zshrc && MACHINE_NAME=laptop make run
# 4. Calibrate — run /usage in Claude Code, then:
curl -X POST "http://localhost:8990/calibrate?session_pct=22&weekly_pct=55&weekly_sonnet_pct=6"Open http://localhost:8990 for the dashboard. That's it — budget enforcement is now active.
- How it works
- Installation
- Dashboard
- Calibration
- Budget threshold
- Running as a daemon
- When to recalibrate
- Troubleshooting
- API reference
- Contributing
- License
Claude Code ──► proxy :8990 ──────────────► api.anthropic.com
│
▼
~/.claude/projects/**/*.jsonl
│
(parsed on every request)
│
▼
┌───────────────────────┐
│ session rolling 24h │
│ weekly rolling 7d │
│ sonnet rolling 7d │
└───────────────────────┘
│
if any window ≥ budget%
│
▼
HTTP 429
The proxy reads JSONL records written by Claude Code after every response — the same data source that powers /usage. No subscription API involved.
Budget windows correspond to Claude Code's /usage output:
| Proxy window | /usage label |
|---|---|
current_session |
Current session (rolling 24h) |
this_week |
Current week — all models (rolling 7d) |
this_week_sonnet |
Current week — Sonnet only (rolling 7d) |
Prerequisites: Go 1.21+, Claude Code installed.
git clone https://github.com/ccavo001/claude-spooky-proxy
cd claude-spooky-proxy
make build # native binary → builds/
make build-all # macOS arm64 + amd64, Linux amd64Add to ~/.zshrc or ~/.bashrc:
export ANTHROPIC_BASE_URL=http://localhost:8990
export MACHINE_NAME=laptop # any descriptive labelsource ~/.zshrcMACHINE_NAME=laptop make runspooky-proxy ready on :8990 machine=laptop
curl http://localhost:8990/health
# {"status":"ok"}Claude Code will work exactly as before — the proxy is fully transparent until a budget limit is hit.
Open http://localhost:8990 in your browser.
┌──────────────────────────────────────────┐
│ 🕸 spooky-proxy [laptop] ● online │
├──────────────────────────────────────────┤
│ USAGE │
│ Session (24h) ████░░░░ 42.1% │
│ Week — all models ██░░░░░░ 18.3% │
│ Week — Sonnet █░░░░░░░ 6.2% │
├──────────────────────────────────────────┤
│ TOTALS Today: 12M All time: 340M │
├──────────────────────────────────────────┤
│ LOCAL TOKENS (for joint calibration) │
│ Session 6.1M · Weekly 91M · Sonnet 18M │
│ [Copy params] [Copy curl] │
├──────────────────────────────────────────┤
│ BUDGET THRESHOLD ────●──── 50% [Save] │
├──────────────────────────────────────────┤
│ CALIBRATE [form] [Calibrate] │
└──────────────────────────────────────────┘
Bars turn orange at 80% of the threshold, red when blocked. Auto-refreshes every 10 seconds.
The Local tokens card is the key tool for two-machine calibration:
- Copy params — copies
remote_session=X&remote_weekly=Y&remote_sonnet=Zready to append to a curl command on the other machine - Copy curl — copies a complete calibrate command with this machine's token values pre-filled; replace the
__placeholders with percentages from/usage
Calibration tells the proxy what 100% of your subscription looks like in absolute tokens. It only needs to run once per subscription window, or whenever /stats drifts significantly from /usage.
Important
Calibrate immediately after reading /usage. Token counts shift with every request — the two readings must be nearly simultaneous.
Use this when only one machine has consumed tokens in the current period.
Via dashboard (recommended): open http://localhost:8990, read /usage in Claude Code, enter the three percentages in the Calibrate card.
Via curl:
# 1. In Claude Code:
# /usage → note the three percentages
# 2. Immediately run:
curl -X POST "http://localhost:8990/calibrate?session_pct=22&weekly_pct=55&weekly_sonnet_pct=6"{
"weekly_all": 513000000,
"weekly_sonnet": 794000000,
"session": 29000000,
"budget_pct": 50,
"calibrated_at": "2026-04-14T09:00:00Z"
}Limits are saved to ~/.claude/spooky-proxy-limits.json.
# Verify
curl http://localhost:8990/stats | jq .usage_pct/usage shows the combined subscription usage across all machines, but each machine's JSONL files are local. Calibrating from one machine alone underestimates the limit.
Prerequisites: both proxies running; the other machine reachable via local network or SSH.
Warning
Run the steps below without interruption. Token counts change with every API request.
- On the desktop: open
http://desktop:8990, click Copy curl in the Local tokens card - On the laptop: paste the command, replace
__with the percentages from/usage, run it - Copy limits to the desktop:
scp ~/.claude/spooky-proxy-limits.json user@desktop:~/.claude/spooky-proxy-limits.json
- Verify on both machines at
http://localhost:8990
# Step 1 — read the desktop's token counts
ssh user@desktop "curl -s http://localhost:8990/stats" | jq '{
remote_session: .stats.current_session.total_tokens,
remote_weekly: .stats.this_week.total_tokens,
remote_sonnet: .stats.this_week_sonnet.total_tokens
}'
# → {"remote_session":5200000,"remote_weekly":98000000,"remote_sonnet":18000000}
# Step 2 — in Claude Code on either machine: /usage → note the percentages
# Step 3 — calibrate on the laptop (sums both machines)
curl -X POST "http://localhost:8990/calibrate?\
session_pct=22&weekly_pct=55&weekly_sonnet_pct=6&\
remote_session=5200000&remote_weekly=98000000&remote_sonnet=18000000"
# Step 4 — push limits to the desktop
scp ~/.claude/spooky-proxy-limits.json user@desktop:~/.claude/spooky-proxy-limits.json
# Step 5 — verify on both
curl http://localhost:8990/stats | jq .usage_pctThe proxy computes: absolute_limit = (local_tokens + remote_tokens) / percentage
The default threshold is 50% — the proxy blocks at half your subscription limit, leaving the other half for other machines or safety margin.
Dashboard: drag the slider in the Budget threshold card → Save.
curl:
curl -X POST "http://localhost:8990/budget?pct=70"The value is persisted in ~/.claude/spooky-proxy-limits.json and survives restarts.
make build-darwin && make install-darwinSet your MACHINE_NAME in the installed plist:
nano ~/Library/LaunchAgents/com.claudeproxy.spooky.plistlaunchctl load ~/Library/LaunchAgents/com.claudeproxy.spooky.plist
# Logs
tail -f ~/Library/Logs/claude-spooky-proxy/proxy.log
tail -f ~/Library/Logs/claude-spooky-proxy/error.log
# Restart
launchctl unload ~/Library/LaunchAgents/com.claudeproxy.spooky.plist
launchctl load ~/Library/LaunchAgents/com.claudeproxy.spooky.plistmake build-linux && sudo make install-linuxEdit the service file to set your username (the proxy must read your ~/.claude/):
sudo nano /etc/systemd/system/claude-spooky-proxy.service
# → set User=yourusername
sudo nano /etc/claude-spooky-proxy/config.env
# → set MACHINE_NAME and CLAUDE_CONFIG_DIR=/home/yourusername/.claudesudo systemctl start claude-spooky-proxy
sudo journalctl -u claude-spooky-proxy -f| Situation | Action |
|---|---|
| First run | Single or joint calibration |
| Proxy updated (new build) | Restart → recalibrate |
/stats drifts far from /usage |
Recalibrate |
| Weekly window resets (new period), one machine only | Single calibration |
| Weekly window resets, both machines used tokens | Joint calibration |
| Anthropic changes plan limits | Recalibrate |
Note
Expect a 1–3 percentage point discrepancy between /stats and /usage. This is normal: spooky-proxy uses strict rolling windows while Claude Code uses subscription-anchored windows. It does not affect budget enforcement.
Claude Code returns 429
The budget was hit on at least one window. Check which:
curl http://localhost:8990/stats | jq '{
session: .usage_pct.session,
weekly: .usage_pct.weekly_all,
sonnet: .usage_pct.weekly_sonnet
}'Options:
- Wait — windows reset automatically (session: ~24h, weekly: ~7d)
- Recalibrate if the inferred limits seem wrong
- Bypass temporarily — stop the proxy and
unset ANTHROPIC_BASE_URL
Proxy blocking with apparently low usage
Calibration may have produced an underestimated limit (e.g., calibrated when only one machine had tokens, but the other had used a large share). Recalibrate using joint two-machine calibration.
curl http://localhost:8990/stats | jq '{tokens: .stats.this_week.total_tokens, limit: .limits.weekly_all}'Proxy not responding
curl http://localhost:8990/health
lsof -i :8990macOS: launchctl unload/load ~/Library/LaunchAgents/com.claudeproxy.spooky.plist
Linux: sudo systemctl restart claude-spooky-proxy
Corrupted calibration — full reset
rm ~/.claude/spooky-proxy-limits.json
# proxy is now fail-open; recalibrate from scratchUse Claude Code without the proxy
unset ANTHROPIC_BASE_URL
claude # connects directly to api.anthropic.comThe proxy keeps running. Tokens are still written to JSONL and counted on the next /stats.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Web dashboard |
/health |
GET | Liveness check → {"status":"ok"} |
/stats |
GET | Token usage + percentages + calibrated limits |
/calibrate |
POST | Infer absolute limits from /usage percentages |
/budget |
POST | Update budget threshold |
/v1/* |
ANY | Transparent proxy to api.anthropic.com |
| Parameter | Type | Description |
|---|---|---|
session_pct |
float | "Current session" % from /usage |
weekly_pct |
float | "Current week all models" % from /usage |
weekly_sonnet_pct |
float | "Current week Sonnet only" % from /usage |
remote_session |
int | Session tokens from the other machine |
remote_weekly |
int | Weekly tokens from the other machine |
remote_sonnet |
int | Sonnet weekly tokens from the other machine |
All parameters optional. remote_* are only used for joint calibration.
| Parameter | Type | Description |
|---|---|---|
pct |
int (1–100) | New budget threshold percentage |
| Variable | Default | Description |
|---|---|---|
MACHINE_NAME |
hostname | Label for this machine in stats output |
PROXY_PORT |
8990 |
Listening port |
UPSTREAM_URL |
https://api.anthropic.com |
Anthropic API endpoint |
ANTHROPIC_API_KEY |
(empty) | Overrides the auth header — not needed for Claude Max |
CLAUDE_CONFIG_DIR |
~/.claude |
Path to Claude Code's data directory |
Bug reports and pull requests are welcome. For major changes, open an issue first to discuss what you'd like to change.
make ci # fmt + vet + test + LOC validation
make validate-loc # verify all Go files are ≤100 lines