Claude Drain GuardA zero-dependency VS Code extension that watches Claude Code locally, aggregates five-minute slices, and tells you to stop after the first anomalous prompt—before the next few prompts drain the session. Install or updateInstall Claude Drain Guard 0.9.1 from the Visual Studio Marketplace, or open Extensions: Install from VSIX... in VS Code and select the Marketplace releases are immutable: an uploaded package cannot be replaced. Version 0.9.1 adds immediate, monotonic 5h/7d synchronization on top of the official cache telemetry introduced in 0.9.0. Status barFive-hour usage and cache hit stay visible in a small item on the right. A separate state indicator sits beside it:
Click the item and select Refresh every Ns to set a 1–60 second background refresh interval. The default is 15 seconds; file changes still trigger an immediate incremental read. Quota display adapts to the available data: Claude.ai 5h/7d, 5h-only, stale quota, or local API/Bedrock usage. Cache hit remains visible in every active mode. The colored indicator is independent of the quota percentage: only cache, fresh-token, change-point, and sudden-drain anomaly signals change it. Signals
DashboardClick the status item or run Claude Drain Guard: Open Dashboard. The first card is the current Claude Code session, detected from the most recently active JSONL session file. It shows session totals and one bar per completed API response. Hover a bar for its exact fresh input, cache hit, output, time, and cost. Records created by older releases are associated with the latest contiguous project run without rescanning or duplicating historical data. The 24-hour chart switches between 5-minute, 30-minute, and 1-hour buckets and uses a log scale so ordinary activity remains visible beside a large spike. It includes numeric scale labels, total/peak values, and detailed hover data. The initial 5-minute bars are rendered before Webview JavaScript runs, and current-session turns backfill a bucket if its aggregate slice is not available yet. Consecutive anomalous turns are grouped into one incident with aggregate fresh tokens and cost instead of filling the table with repeated rows. Prompt and response content is never shown. The cached 5-hour usage snapshot has its own reset timer. When its published reset time arrives, the status bar moves the expired window from 100% to a new local 0% window immediately and performs a read-only background refresh; it no longer waits for the next prompt. Five-hour quota rollover does not imply prompt-cache expiry and does not affect anomaly classification. The first response in a new session or after at least five idle minutes is treated as a possible cache rebuild. When official telemetry is connected, Claude Code's own unexpected-miss classification takes priority and expected rebuilds never alert. Cost follows the mature ccusage auto strategy: use Claude Code's reported per-entry estimate when available, otherwise multiply input, output, cache-read, 5-minute cache-write, and 1-hour cache-write tokens by the matching official model rates. It is an API-equivalent impact estimate, not a Claude Max invoice and not a conversion to the 5-hour quota. If old records omit the TTL breakdown, the default fallback is the standard 5-minute cache-write rate and can be changed with If Official cache telemetryClaude Code 2.1.251+ exposes authoritative main-conversation cache statistics through its status-line JSON. Run Claude Drain Guard: Connect Official Cache Telemetry once to receive:
The connection is explicit and fail-safe. It adds a small local status-line helper to Claude settings, stores only the listed counters, and never stores prompt or response text. If Claude already has a custom status line, Drain Guard refuses to overwrite or wrap it. Use Disconnect Official Cache Telemetry to remove only a status-line entry owned by Drain Guard. The dashboard uses three layers: official status-line data for the active main conversation and immediate 5h/7d updates, incremental JSONL reads for response history and subagents, and the OAuth usage endpoint as a five-minute quota reconciliation fallback. If the optional official layer is absent or stale, monitoring falls back without blocking Claude. Performance
No prompts, source code, credentials, or tool arguments are collected. Local anomaly monitoring remains independent of the network. Live 5h/7d usage is enabled by default: when a readable Claude OAuth token is available, the adapter makes its own read-only DevelopmentOpen this folder in VS Code and press To create a Marketplace package, increment Commands
Privacy and securitySee PRIVACY.md and SECURITY.md. This is a community project and is not affiliated with or endorsed by Anthropic. |