Skip to content

feat(statusline): cost, daily spend, memory and configuration counts - #539

Open
Mearman wants to merge 5 commits into
mainfrom
feat/statusline-cost
Open

Mearman wants to merge 5 commits into
mainfrom
feat/statusline-cost

Conversation

@Mearman

@Mearman Mearman commented Oct 19, 2026

Copy link
Copy Markdown
Member

Adds the cost and machine group of the claude-hud parity work to the built-in statusline: a cost and a dailyCost header segment and a memory and an environment row. All four are named in the schema's lists and the registry but left out of the default layout, so the default output is unchanged.

The cost segment draws the client's own cost.total_cost_usd as Cost. When the client reports none, it falls back to an estimate priced from the door's usage log with the per-model prices agent-shim model price already stores (keyed <provider>/<model>, cache tokens at Anthropic's published ratios of the input price). There is no shipped price table, and a request whose model has no price makes the whole estimate absent rather than understated. A launch that selected a provider, or a Bedrock or Vertex model id, counts as routed: it draws nothing unless cost.routed is set, and then the door's own record of each request is preferred over the client's figure, which is a lookup for a name it may not know. The log is read only when the layout lists a cost segment, from the UTC day the session began on.

Today's spend is a ledger in a new statusline directory under the agent-shim home, written through a new port with an atomic rename. It stores each session's absolute total, so two statuslines overwriting each other cost nothing, counts a session from its first sighting, restarts at local midnight and drops sessions unseen for a day.

The memory row reads vm_stat on macOS and /proc/meminfo on Linux through a port, because os.freemem leaves reclaimable cache out of what is free. The environment row counts CLAUDE.md files, rules, MCP servers and hook events from the pinned configuration directory (or the home directory's .claude) and the session's project, through list, stat and realpath ports with a link-cycle guard on the rules walk; environment.threshold is claude-hud's environmentThreshold.

cost.routed is the first boolean setting, so the key listing and --statusline <setting>=<value> gain a boolean kind. The parity map and document account for every key in the group, and the document records how the routed cost relates to the usage log.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-10-19T21:40:38.590695Z 2d548f1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

Elements can now list and resolve paths, write a file atomically into a state directory under the
agent-shim home, and read the memory in use, all through the ports, so an element that needs the
machine stays a function of its context and a test hands it an in-memory filesystem.

Memory comes from vm_stat on macOS and /proc/meminfo on Linux, because os.freemem leaves
reclaimable cache out of what is free and overstates the use.
…configuration counts

Four elements, none in the default layout. The cost segment draws the client's own figure, or an
estimate priced from the door's usage log with the prices `model price` stores when the client
reports none. A routed session (a launch that selected a provider, or a Bedrock or Vertex model id)
draws a cost only when cost.routed is set, and then prefers the door's record of each request over
the client's figure, which is not what was billed. The daily cost segment keeps a per-day ledger in
the statusline's state directory, counting a session from its first sighting and restarting at
local midnight. The memory row is a bar of the memory in use, and the environment row counts
CLAUDE.md files, rules, MCP servers and hook events, subject to environment.threshold.

Boolean settings become a kind the key listing and `--statusline <setting>=<value>` understand.
Claude Code stamps every request with its own session id, which changes when a conversation is
cleared inside one launch, unlike the launch's session id the record already carries. The door reads
it from the request header into an optional clientSessionId on the usage record, so a consumer can
tie requests to the client's per-conversation figures. A request without the header, or with it
repeated, records none.
Compressed pages hold real memory, so leaving them out of the sum read lower than the operating
system's own account of what cannot be handed on.
The day's ledger is one file for each conversation for each local day, summed on read, so
statuslines drawing at the same moment can no longer overwrite one another's entries. A
conversation that spans midnight starts the new day from the total it had on its last render, a
conversation is bound to the source of its first figure (the client's or the door's estimate),
and days older than the one before are removed through a new remove port.

The door's estimate is now read for the conversation named by the client's session id, matched to
the clientSessionId on each usage record, so clearing a conversation inside one launch no longer
carries the earlier conversation's requests into the estimate or the daily total. A failing read
of the model prices or the log now surfaces instead of being swallowed, and the routed-session
predicate is no longer exported.
@Mearman
Mearman force-pushed the feat/statusline-cost branch from 2d548f1 to 0602ba6 Compare October 20, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant