Skip to content

Studio: Run cost — what a background run takes from your plan, before and after #1056

In review
0 of 7 issues completed

Description

@danielrispler

Code references are at 98e1ea8a5. Decisions are from #935's grilling of 2026-12-02 (resolution comment on #935; Q16–Q26).

Problem Statement

plotkeeper starts background runs on Daniel's claude login (First map, Map text review, Back a law, micro-worlds) and says nothing about what they cost. The runner already reads each run's total_cost_usd (server/src/runner.rs:1124) and appends it to background-runs.jsonl (runner.rs:1787-1805), but no view shows it. Draft the map shows only a time hint (ui/map-model.ts:316-320).

For a subscriber, total_cost_usd is an API list-price estimate, not money paid: for subscribers "the session cost figure isn't relevant for billing purposes" (https://code.claude.com/docs/en/costs). What a subscriber spends is a share of the plan's 5-hour and weekly limits, which Anthropic publishes only as ratios: Max is "5x Pro usage" per 5 hours and per week, and Ultra is "10 times the Pro plan's usage every week" with no 5-hour limit once verified (https://claude.com/pricing; https://support.claude.com/en/articles/17728952).

Without a figure, Daniel cannot tell whether plotkeeper is "very cheap" (Q18), and a new user has no reason to trust that a click won't eat their window.

Solution

Every click that starts a background run shows a cost estimate before it, as a range in the plan's terms: "about 1–3% of your 5-hour window". Every run's actual cost shows where its result shows, and the Background runs list's head shows the last 7 days' total, whether or not any run is listed. A subscriber sees shares of the 5-hour window and the week. An API-key user sees dollars. Anyone whose plan is not known sees dollars labelled "API price".

plotkeeper detects the plan itself and asks Daniel only to confirm it in Settings. A first ticket measures, on Daniel's account, how many API-price dollars one percent of each window is. Everything else rests on that factor.

User Stories

The cost estimate

  1. As Daniel, before I press Draft the map, I see beside its time hint about how much of my plan it will take, reviewer and automatic redrafts included, so I can decide whether now is a good time.
  2. As Daniel, every other button that starts a run shows the same kind of estimate: Back a law and Guard with a law's Back this law and Start the run, Explore this and a micro-world's Rebuild and Try again, Review map text and Run again, and the Map draft's Retry.
  3. As Daniel, the estimate is a range ("about 1–3%"), never one exact number, so it does not promise what it can't know.
  4. As Daniel, an estimate for First map grows with the number of parts it will draft, so a 30-part repository shows more than a 10-part one.
  5. As Daniel, before enough runs of a kind have been recorded, the estimate still shows, from the trial's figures, so the first click is never blind.
  6. As Daniel, when a share rounds below 1%, the estimate says "under 1%" rather than "0%".

The actual cost

  1. As Daniel, a run's actual cost shows where its result shows: the Map draft panel's status line once the draft is ready ("took about 2% of your 5-hour window"), the Map text review's line in Ratify, Back a law's patch review, and a micro-world's row.
  2. As Daniel, each ended run still in the Background runs list shows its actual cost on its row.
  3. As Daniel, a run that recorded no cost (cancelled before it answered, died) shows none, not zero.
  4. As Daniel, the Background runs list's head shows the last 7 days' total across every kind and project ("last 7 days, all projects: about 4% of your week"), so I can see whether plotkeeper as a whole is cheap. It shows even when no run is listed, as long as the total is not zero.
  5. As Daniel, the total counts runs that were dismissed, by me or by plotkeeper, since they still spent.

The plan

  1. As Daniel, plotkeeper works out on its own whether I am on a subscription or an API key, and on which plan, and Settings shows what it found with Confirm and Change.
  2. As Daniel, until I confirm, every share says "about" and Settings marks the plan as detected, not confirmed.
  3. As Daniel, I can pick my plan by hand (Pro, Max, Ultra, API key, Don't know), and my pick wins over detection until I change it.
  4. As Daniel, when nothing could be detected and I picked nothing, or I picked Don't know, every figure is dollars labelled "API price", never a share.
  5. As an Ultra subscriber, I see only weekly shares, since my plan has no 5-hour window.
  6. As an API-key user, I see dollars, since that is what I pay.
  7. As Daniel, opening the page still spends nothing: detection never starts a claude call on a timer.

Honesty

  1. As Daniel, hovering a figure says where it comes from: "API price of the run, turned into your plan's share by a factor measured on ; Anthropic does not publish plan sizes."
  2. As Daniel, a share always carries "about".

Implementation Decisions

The calibration trial comes first (Q24)

  • The first ticket measures, on Daniel's account in a quiet hour, the API-price dollars per percent of the 5-hour window and of the week: about 5 First map drafts on chery and observability-sdk with every other session idle. It reads the plan's percentages before and after with /usage sent through claude -p (its usage_report.rate_limits.limits[], https://code.claude.com/docs/en/agent-sdk/typescript.md, SDKUsageReport, marked experimental), and divides the runs' summed total_cost_usd by each window's change.
  • The factors go in one place in the server's code, with the date, the plan measured on and the runs' ids. The trial's numbers are written to docs/studio/research/run-cost.md, so the spec's sources are in the repository. The other plans follow from the published ratios: one percent of Pro is a fifth of Max's dollars, and one weekly percent of Ultra is twice Max's dollars.
  • The trial also settles three facts not yet verified: whether claude -p "/usage" spends model tokens, whether /usage or /status names the plan, and how often the plan-limit request may be made before it falls back to bars cached within 60 minutes (https://code.claude.com/docs/en/costs, "When the usage request fails").
  • If /usage spends tokens or gives nothing on a -p run, detection uses only the status line, and the trial says so on the spec.

The run record

  • background-runs.jsonl's line gains two optional fields: units, the parts a First map writer or reviewer group covered, and model, from the result's modelUsage. Old lines lack them and still read. A First map line with no units is not used for a per-part figure.
  • This is the one stored-shape change of the spec.

The cost estimate (Q16)

  • An estimate comes from recorded costs. For First map the unit is a part: the dollars per part of the last 20 recorded First map lines that have units, writers, reviewers and redrafts together. For every other kind the unit is a run: the last 20 recorded runs of that kind with a cost. With fewer than 3 such records it comes from the trial's figures.
  • The range is the 25th to 75th percentile of those per-unit costs times the units, turned into the plan's share.
  • Estimates are computed on the server, which owns background-runs.jsonl, and reach the page with the views that hold the buttons. The page only formats them.
  • Records come from every project, since cost depends on the kind and the model far more than on the repository; First map's per-part unit carries the repository's size.

The actual cost and the total (Q26)

  • A run's actual figure is its recorded total_cost_usd, turned into the plan's share with the same factor. A missing cost shows nothing. For First map, the figure on the Map draft panel is the sum over the draft's runs.
  • Map text review and First map runs are dismissed as soon as their answers are kept (server/src/map_review.rs:1028-1033, server/src/map_draft.rs:630-637), so their actual cost shows on the view that keeps their answer, not in the list. That dismissal stays.
  • The total is the sum over background-runs.jsonl of the last 7 days, all projects, dismissed runs included. runsNodes returns nothing when no run is listed and the queues are not paused (ui/map-runs.ts:117-121); it also draws the head when the total is not zero.

The plan (Q23, Q25)

  • Detection, in order of trust:
    1. Daniel's own pick in Settings.
    2. A status-line reading. plotkeeper statusline (server/src/statusline.rs) already receives Claude Code's status-line JSON when Daniel has pasted the snippet (docs/studio/settings.md:67); for subscribers it carries rate_limits.five_hour and rate_limits.seven_day with used_percentage and resets_at (https://code.claude.com/docs/en/statusline). It saves only those four numbers, in one file in the data folder, replaced on each call; no session id, no cost, no context size.
    3. /usage through claude -p, sent only alongside a run Daniel started: right before and right after it, at most once per run and at most once in 10 minutes. Never on a timer and never on page open, so the rule "opening the page spends nothing" (docs/studio/settings.md:26) holds. Settings also has Detect again, which sends one.
  • No rate_limits at all reads as an API key; weekly rows with no session row read as Ultra.
  • Pro or Max: no field names it unless the trial finds one. plotkeeper compares the before/after change in the 5-hour percentage around its first three runs with their API price, against the measured factor: closer to Max's factor guesses Max, else Pro. Another session spending at the same time skews the reading, so the guess is shown as detected, never as confirmed.
  • The plan is stored in settings.json as plan: { "kind": "pro" | "max" | "ultra" | "api" | "unknown", "confirmed": bool }. Detection writes confirmed: false; Confirm sets it true; Change writes Daniel's pick with confirmed: true. Detection never overwrites a confirmed plan.

Where the figures show (Q17)

  • Every button that starts a background run: Draft the map (ui/map-scan.ts:260), Back a law (ui/patch-review.ts:81-82), Guard with a law's Back this law and Start the run (ui/patch-review.ts:268, 320), Explore this (ui/map-brief.ts:494, ui/map-stale.ts:57), a micro-world's Rebuild and Try again (ui/micro-world.ts:36, 41, 88), Review map text and Run again (ui/map-ratify.ts:207-229), and the Map draft's Retry (ui/map-draft.ts:290). Redrafts start on their own (server/src/map_draft.rs:832-856), so they have no button; Draft the map's estimate includes them.
  • The estimate is a short line beside or under the button, in the time hint's style where one exists.
  • Actual costs: the views in story 7, and the Background runs list (ui/map-runs.ts), one figure per ended row and the head's total.
  • Settings: a Plan row in the writer section, which ui/writers.ts renders.

Glossary and docs

  • docs/studio/CONTEXT.md gains Run cost: "what a background run takes: its API price, and for a subscriber the share of the plan's 5-hour and weekly limits it is estimated to use." Its Avoid line names Estimate, which is a session's remaining-time range, and its body says it brings back one reading of the retired Plan usage (the subscription's two windows) for runs only. It also gains the grilling's Run-time link.
  • docs/studio/behaviour/background-runs.md gains a "Cost" section and the record's new fields; docs/studio/settings.md gains the plan setting and Detect again; docs/studio/behaviour/storage.md says what the status line saves now, beside its note on the retired snapshots (storage.md:41-43).
  • system-map.json: the new research doc, and the status line's new responsibility on its part.

Testing Decisions

  • The cost estimate is a pure function of records, a kind, a unit count, the plan and the factors: one table test in Rust, with rows for each kind, too few records, the trial fallback, old First map lines with no units, Ultra (no 5-hour share), API key (dollars), unknown plan (API price) and a share under 1%.
  • The run record: extends the runner's record test with units and model, and a row reading an old line without them.
  • The status-line reading: extends server/tests/statusline.rs with rows for input with and without rate_limits, checking only the four numbers are saved.
  • The /usage parser: a table test over captured usage_report JSON from the trial (subscriber, Ultra, no rate_limits, null report), stored as fixtures.
  • The 7-day total: a test over a background-runs.jsonl fixture with dismissed runs, other projects, missing costs and lines older than 7 days.
  • The page: snap fixtures for the Background runs list with figures and the total (and with only the total), Draft the map's card with its estimate, the Map draft panel's spent line, and the Settings Plan row detected and confirmed.
  • Not tested by code: whether the factor is right. Only the trial measures that, and the hover says so.

Out of Scope

  • Law draft (the second spec from the grilling), which uses this spec's figure.
  • What summaries and PR briefs spend: Studio: what share of a Claude plan a week of full plotkeeper use takes #1053.
  • Capping a run's cost (claude --max-budget-usd exists, claude --help). A figure first.
  • Making any run cheaper. This spec only shows the cost.
  • Any harness other than claude; background runs have only that one (docs/studio/behaviour/background-runs.md:7).

Further Notes

  • plotkeeper's recorded First map runs so far cost a median $0.17 and at most $0.30 API price each (20 runs; reproduce with a median over cost of kind: "first-map" lines in background-runs.jsonl). Repo-to-wiki tools such as DeepWiki are free for public repositories and metered for private ones (https://docs.devin.ai/work-with-devin/deepwiki).
  • The factor drifts when Anthropic changes limits. Re-running the trial is a manual step; the hover shows the factor's date.

Made without Daniel

  • Estimates use the last 20 records per kind across all projects, with First map per part (set aside: per project, which leaves most projects with no records).
  • The range is the interquartile range (set aside: min–max, which one $2.17 Opus run would blow up).
  • The run record gains units and model (set aside: grouping First map runs by draft after the fact, which the record can't do).
  • Auto-dismissed runs show their cost on the view that keeps their answer (set aside: keeping them listed, which undoes the dismissal's reason).
  • Detection prefers the status line over /usage, and /usage rides only on runs Daniel started (set aside: /usage on a timer, which breaks "opening the page spends nothing").
  • The status line starts saving four numbers (set aside: saving nothing, which leaves only /usage). This reverses part of Studio: the context-window snapshots stopped when the terminal went #416, which stopped the old status line's snapshots; it saves far less than those did.
  • The total counts all projects (set aside: per project, since the plan is shared across them).
  • The plan lives in settings.json (set aside: a separate state file).

Sub-issues

Sub-issues

0 of 7 Issues completed
Loading 7 sub-issues

Activity

  1. added
    ready-for-agent
    on Dec 2, 2026
  2. danielrispler commented on Dec 2, 2026

    @danielrispler
    OwnerAuthor

    Generated by AI while breaking this spec into tickets.

    Amendment: the run record gains a third optional field, subject, beside units and model, in the same stored change. It is the key of the view that keeps the run's answer (a First map draft, a review's PR and head, a law, a micro-world). The views clear their run ids when a run ends, so without it no view could find its run's actual cost.

  3. danielrispler commented on Dec 2, 2026

    @danielrispler
    OwnerAuthor

    Route draft: #1058 strong·medium → medium·medium — breakdown critic: a hand-checked trial raises the tier to medium, never strong
    Route draft: #1059 (new) → medium·medium — breakdown critic: the pure engine split out of the core ticket
    Route draft: #1060 strong·high → strong·high — unchanged; absorbed the run-record ticket, whose cut routed nothing lower
    Route draft: #1061 strong·high → strong·high — unchanged; its Settings row split out
    Route draft: #1063 medium·medium → medium·medium — unchanged; the estimate and actual-cost UI tickets merged (shared snap registry)
    Route draft: #1064 (new) → medium·medium — breakdown critic: the Settings row split out of plan detection
    Route draft: #1065 cheap·medium → medium·medium — breakdown critic: it changes parts of the system map (cheap rule 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions