# Jcode 0.99.1 usage and context receipt (#801)

Date: 2026-10-28. Refs #801. Installed release build, read through `--quiet version --json`: `semver` 0.99.1, `version` `v0.99.1 (7206efd0c)`. Host macOS arm64, Bun 1. The receipt records event shapes and counters only: no prompt, no model output beyond the fixed word the fake replied with, no credential, no account identifier.

## What was run

An isolated `HOME` and `JCODE_HOME` (fresh directories under the scratch area, an empty `mcp.json`, no credentials, no account), `JCODE_NO_TELEMETRY=1` and `JCODE_DISABLE_CLAUDE_MCP=1` as the adapter sets them. One `openai-compatible` profile `fakegw` (added with `jcode provider add ... --no-api-key`, written only into the isolated `config.toml`) pointed at a local server on `127.0.0.1` that streamed a fixed reply and a final `usage` chunk whose numbers the probe chose, so each number Jcode reported could be compared with the number sent. No real provider, key or model was involved.

`jcode serve` and `jcode acp` were started with the argv `jcodeCommand` builds (`--socket`, `--cwd`, `--no-update`, `--no-selfdev`, `--model`, `--provider-profile`, `--temporary-server`, `--mcp-tools eager`), a session was created, and three prompts were sent. Before the run the SHA-256 of the four real config files directly in `~/.jcode` (`auth.json`, `auth-refresh-state.json`, `config.toml`, `mcp.json`) was taken and compared after the last leg: unchanged. No process whose command line named the sandbox was left running.

## Shapes observed on the ACP stream

Per prompt, in this order: `available_commands_update` (first prompt only), `agent_message_chunk`, one `usage_update` per provider call, then the `session/prompt` result.

- **`usage_update`**: `{ sessionUpdate: "usage_update", used: <integer>, size: <integer> }` inside `session/update` params that carry the ACP `sessionId`. Nothing else. In Jcode's own source (`src/cli/acp.rs`) it is written on each `TokenUsage` server event: `used` is `effective_context_tokens_from_usage` of that provider call (`crates/jcode-compaction-core/src/lib.rs`): the input count alone for OpenAI-named providers and when the cache is a subset of it, and the input plus the cache read and cache creation counts for Anthropic or Claude named providers and when the numbers show split accounting (a cache creation, or a cache read above the input). `size` is the model's context limit (200000 for the fake model, which falls to Jcode's default). The source was read on GitHub at the default branch; the installed 0.99.1 binary's behaviour was observed only for the input-only case the fake gateway produced. The sequence of one two-call turn (a tool call, then the answer) was `used` 1000 then 1100 for provider inputs 1000 and 1100: occupancy of the last call, not an accumulated sum.
- **Prompt result**: `{ stopReason: "end_turn", usage: { inputTokens, outputTokens, cachedReadTokens, totalTokens } }`. `cachedWriteTokens` is in the source and absent when the provider reports no cache write. For the same two-call turn the result said `inputTokens` 2100 and `outputTokens` 40: the sum of the two calls (1000 + 1100, 10 + 30), so it is per turn, not a session total. A turn whose provider call reported no usage chunk had no `usage` member at all.
- **`totalTokens` adds the cached read on top of the input**: sent input 1234, output 56, cached 100; Jcode reported `inputTokens` 1234, `outputTokens` 56, `cachedReadTokens` 100, `totalTokens` 1390 (input + output + cached). For OpenAI-style providers the input already contains the cached part, so that total counts it twice. The hub never reads `totalTokens` from Jcode.
- **No other usage or context message** appeared: no ACP method other than `session/update`, and no `usage_update` carrying `totalTokens` or any ratio, window or reset.
- **`jcode usage --json`** (the account usage command) under the same isolated home printed `{ "providers": [] }`: no provider connected, so no sample of a limit. From Jcode's source its schema is `providers: [{ provider_name, limits: [{ name, usage_percent, resets_at, reset_in }], extra_info: [[key, value]], banked_reset?, error }]`. `name` is free text and no window length is given.

## What the hub does with it

| Jcode record | Host projection | Why |
| --- | --- | --- |
| `usage_update` `{used, size}` | `ContextReading` source `jcode_usage_update`, bound to the adapter's own ACP session id, with the measurement time | live-session occupancy, the same kind as Kimi's and Codex's readings |
| prompt result `usage` | one `usage` event per prompt, source `jcode_acp`: `inputTokens`, `outputTokens`, `cacheReadTokens`, `cacheWriteTokens` when present, task attribution, no `totalTokens` | per-turn consumption in the provider's own buckets |
| `usage_update` | never a `tokens` event, a hub token window or a quota window | occupancy is not consumption |
| prompt result `usage` | never a context reading, never a quota window | consumption is not occupancy and says nothing of a limit |

A reading with a malformed field (`used` or `size` not a non-negative safe integer, `size` not positive), for another session than the daemon's current one, older than `context.stale_min`, or from a peer that is not attached, is unknown in `ahub status`, the console and the dashboard: never zero and never healthy. A result without both `inputTokens` and `outputTokens` as non-negative safe integers writes no usage record; a present but malformed cache bucket is dropped alone.

## Not supported, and why

- **Native quota windows.** Jcode declares no quota reader. `jcode usage --json` gives a free-text `name`, a percentage and a reset time but no window length, so mapping it to the hub's window ids would parse vendor prose, which #801 rules out. With no account it returned no provider at all, so there is no sample of a real limit either. `ahub budget` keeps `no reading` for Jcode, and the manual `ahub budget set` path is unchanged. Revisit when Jcode names the window length (and an account is available to record a real sample).
- **Served-model evidence.** The ACP stream carries no served model in either record, so the usage event has none; the hub does not infer one from the requested model.
- **Real account and provider.** Every number above came from a local fake gateway. A real provider's cache semantics (Anthropic reports cache apart from input, OpenAI includes it) are taken from Jcode's own documentation and source, not observed here, which is why the hub records the buckets and never a derived total.
- **The TUI form.** `jcode --resume` runs the same ACP-owned session; the TUI's own context display was not read.

## Decision

The two measurements with structured evidence (occupancy, and per-turn token buckets) are supported on 0.99.1. Everything else stays unknown. `docs/verification/2026-10-26-jcode-0.99.1.md` remains the contract receipt a later version repeats; a later version repeats this receipt's probe too before its usage readings are claimed.
