kandev-session-cost
August 3, 2026 · View on GitHub
A kandev plugin that adds a cost icon to the chat bar showing the spend of the current session — total cost, cost-per-turn, and a per-model breakdown — parsed from your local agent CLI transcript by the tokscale CLI.
The amount is colour-coded by how much you've spent (green → amber → red). Hover or focus previews the details, while click or tap pins them open and exposes an explicit Refresh action. Once loaded, the cost stays next to the icon so the bar always "says the cost".
Screenshots
The current session's spend on hover — colour-coded total, cost-per-turn, token totals, and a per-model breakdown:

The cost pill lives in the chat composer toolbar, beside the model picker:

Operator settings (Settings → Plugins → Session Cost), generated from the
manifest's config_schema:

What it does
- A coins button in the chat composer toolbar (
chat-input-actionsslot, desktop + mobile). Hover or focus previews details; click or tap pins the same detail surface open without recalculating. - Pinnable details: the headline amount (colour-coded by spend tier), cost / turn, token totals (input / output / cache read), and a per-model breakdown showing each model's cost plus its input / output / cache-read counts. Tap the trigger again, tap outside, or press Escape to close.
- Explicit refresh: only pinned details show Refresh. It recalculates the active session once, remains open while loading, and ignores repeated input until the request finishes.
- Inline amount: once loaded, the total is shown next to the icon in the tier colour.
- Reads spend from tokscale, keyed on the agent transcript id. The backend
resolves the composer's kandev session id to its ACP transcript id via the
Host data API (
api_read: ["sessions"]) — the UI only ever sends kandev ids. - Cost per turn is computed server-side: tokscale reports the session's
message (turn) count, and the backend returns
cost / turns. - When tokscale is unavailable the popover explains how to fix it instead of erroring.
Settings
Settings → Plugins → Session Cost (generated from the manifest config_schema):
command— explicit tokscale invocation (path or full command); empty auto-detects (tokscaleon PATH, else pinnednpx -y tokscale@4.9.0).warn_threshold(USD, default 1) — amount turns amber at or above this.high_threshold(USD, default 10) — amount turns red at or above this.
Layout
manifest.yaml— one GET webhook (session-cost), the UI bundle, theapi_read: ["sessions"]capability, and theconfig_schema.server/— Go backend half (pluginsdk.Plugin), spawned by kandev over the gRPC plugin contract. Maps kandev session id → ACP transcript id, runs tokscale grouped by session, and computes cost-per-turn. A failed tokscale run degrades to an install-status payload rather than a 500.ui/bundle.js— hand-written, no-build ES module using the shared host React instance andhost.uicomponents. It only renders the backend payload.
Build & install
Requires a kandev monorepo checkout at ../kandev (see the replace directive
in go.mod).
make test # unit tests (no tokscale needed — the runner is injected)
make package-host # tarball for this machine only (fast iteration)
make package # tarball for all 5 supported platforms
Install the tarball via Settings → Plugins → Install plugin (upload), or:
curl -F package=@kandev-session-cost-0.2.3.tar.gz http://localhost:8080/api/plugins/install
CI and releases
Pull requests run CI for module tidiness, formatting, vetting, and tests, plus
a separate host-build and five-platform package check. Pushing a v* tag that
matches manifest.yaml's version repeats verification, packages the plugin,
extracts its internal checksums.txt, and publishes both the tarball and that
checksum file in a GitHub Release.