Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
- Commands: `today`, `week`, `month`, `models`, `sessions`, `projects`, `hours`, `watch`, `export`
- `watch` takes a sub-view (`limits|today|week|models|sessions|hours`, default `limits`) and refreshes it on an interval
- `watch` (default `--view limits`) continuously refreshes "current session" (5h) / "this week" usage with reset times (`--interval`, `--session-reset <HH:mm>`, `--week-reset <Ddd HH:mm>`; both persist to `%LOCALAPPDATA%\aimon\limits-settings.json`, and `r` re-prompts for both reset times while watching; the session reset is auto-computed at startup and never prompted for there, only the week reset is)
- The usage-progress bar of `watch --view limits` is measured in `Commands/QuotaCost` (the estimated cost with the cache-read part scaled by `--cache-read-weight`, default 0.1, persisted as `CacheReadWeight` only when passed; `--reset-cache-read-weight` forgets it), not in plain API cost: the subscription quota does not weigh cache reads at their list price. `UsageWindowSummary.CostBreakdown` carries the cost per token kind (`EstimatedCost` is its total) and the limits view prints the resulting split. What is persisted for the limits is the reading, not the limit: `UsageCalibration` (the percentage read off Claude plus the cost breakdown at that moment) in `SessionCalibration`/`WeekCalibration`, and the limit is derived from it under the weight in effect, so the weight can be tuned without reading `/usage` again. The default weight is a heuristic - tune it against Claude's own percentage. The startup decisions (weight, readings, what to save, notices) live in `Commands/LimitsStartup` so they can be tested without a terminal; the console is cleared right after startup and after each `r` recalibration, so a message for the user must be added to the notices list that `SpectreRenderer.WithNotices` draws in the view, not printed with `AnsiConsole` (only a message that is followed by a prompt, like the ignored saved weekly reset in `LimitsAnchors.TryResolve`, may be printed).
- `export` supports `--format json|csv` and `--output <path>` (defaults to stdout, JSON)
- Report commands (`today|week|month|models|hours|sessions`) take `--json` (machine-readable stdout, no progress bar, update check skipped). `today` takes `--date yyyy-MM-dd`; `week`/`month` take `--from [--to]` or `--last <days>` (`month` also `--month yyyy-MM`); `models` takes `--model <text>`. `projects` and `sessions --list` (default last 30 days, same range options) take `--top`, `--sort`, `--project`, `--model` (`Commands/ListOptions`, ordering in `Commands/UsageSorting`, JSON in `Rendering/UsageReports`; the range / load / sort / JSON-or-hint-or-table flow both commands share is `Commands/UsageList.Run`, so a new list command should reuse it); `sessions` without `--list` is the unchanged aggregate view and rejects those options. Date arguments are validated by `Commands/DateRangeResolver` (max 3650 days, years 2000-2999) and a bad one prints to stderr and exits 1; `Commands/DateRangeOptions` only defines/reads the options, and `Commands/JsonOutput` holds the shared `--json` plumbing (JSON shapes are in `Rendering/CliJsonContext`, durations as seconds).
- Run WPF app (Windows-only): `dotnet run --project src/AIUsageMonitor.WPF`
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ The real reset times and token limits live on your Anthropic account, not locall

- `--session-reset "HH:mm"` — the session reset time Claude shows (e.g. `"18:30"`)
- `--week-reset "Ddd HH:mm"` — the weekly reset (e.g. `"Mon 09:00"`); fixed per account, so it only needs entering once, unlike the session reset
- `--session-token-progress <percent>` / `--week-token-progress <percent>` — the usage % Claude shows (e.g. `32`), used to back out a token budget
- `--session-token-progress <percent>` / `--week-token-progress <percent>` — the usage % Claude shows (e.g. `32`), used to back out a usage budget. Each percentage is saved together with the cost counted at that moment, and the budget is derived from it; a percentage given while nothing is counted for the window yet is ignored (the saved one is kept)
- `--cache-read-weight <0-1>` — what share of the list price of cache-read tokens counts toward the usage bar (default `0.1`, a heuristic: the subscription quota is not metered at API prices, and cache reads dominate long sessions). Lower it if the bar runs ahead of Claude's own percentage, raise it if it runs behind; the saved percentages are kept and the budgets re-derived, so there is no need to read `/usage` again. It is saved when given; `--reset-cache-read-weight` forgets it. A line below the table shows what the bar is made of (cache read / output / cache write / input)

Without these, values are estimated from local transcript timestamps, and a row shows as **unknown** rather than a guessed countdown when there isn't enough local evidence (no activity in the last 5 hours, or no weekly anchor at all).

Expand Down Expand Up @@ -206,7 +207,8 @@ aimon <命令>

- `--session-reset "HH:mm"` — Claude 显示的会话重置时间(如 `"18:30"`)
- `--week-reset "Ddd HH:mm"` — 每周重置时刻(如 `"Mon 09:00"`);账号固定不变,只需录入一次,不会像会话那样过期
- `--session-token-progress <百分比>` / `--week-token-progress <百分比>` — Claude 显示的用量百分比(如 `32`),用来反推出 token 预算
- `--session-token-progress <百分比>` / `--week-token-progress <百分比>` — Claude 显示的用量百分比(如 `32`),用来反推出用量预算。百分比会连同当时统计到的成本一起保存,预算由它推算;窗口内还没有统计到用量时给出的百分比会被忽略(保留已保存的)
- `--cache-read-weight <0-1>` — cache read token 按标价的多大比例计入用量进度条(默认 `0.1`,是经验值:订阅额度不按 API 标价计量,而 cache read 在长会话里占绝大多数)。进度条比 Claude 显示的快就调小,慢就调大;已保存的百分比会保留并按新权重重新推算预算,无需再看 `/usage`。传入后会被保存,`--reset-cache-read-weight` 可忘记它。表格下方有一行说明进度条由哪几类 token 构成(cache read / output / cache write / input)

不配置这些参数时,会根据本地会话记录估算;当本地证据不足时(近 5 小时无活动,或压根没有周期锚点),对应行会显示为**未知**,而不是编造一个倒计时。

Expand Down
10 changes: 10 additions & 0 deletions src/AIUsageMonitor.Cli/Commands/CostShares.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AIUsageMonitor.Cli.Commands;

/// <summary>
/// How much of a quota-weighted cost each kind of token accounts for. The figures are fractions of 1, not dollars.
/// </summary>
/// <param name="Input">The share of the uncached input tokens.</param>
/// <param name="Output">The share of the output tokens, including thinking.</param>
/// <param name="CacheRead">The share of the tokens read from the prompt cache, after weighting.</param>
/// <param name="CacheWrite">The share of the tokens written to the prompt cache.</param>
internal readonly record struct CostShares(decimal Input, decimal Output, decimal CacheRead, decimal CacheWrite);
Loading
Loading