Repository navigation
Description
Summary
jcode acp never populates the ACP usage field on a session/prompt response, so an ACP client has no way to read per-turn token counts. Every prompt response is exactly:
{"jsonrpc":"2.0","id":3,"result":{"stopReason":"end_turn"}}PromptResponse.usage is a standard (unstable-gated) ACP v1 field, and jcode already receives all the numbers it needs internally, so this looks like a gap in the ACP surface rather than a deliberate omission.
Environment
- jcode
v0.75.3 (fd1ff012c), stable channel - Linux aarch64 (Arch Linux ARM), also reproduced on macOS 26.6.1 aarch64
- Provider:
claude(Claude Max OAuth), modelsclaude-opus-5/claude-fable-5
Steps to reproduce
Drive jcode acp over stdio and read the prompt response:
jcode acp{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{}}}
{"jsonrpc":"2.0","id":2,"method":"session/new","params":{"cwd":"/tmp","mcpServers":[]}}
{"jsonrpc":"2.0","id":3,"method":"session/prompt","params":{"sessionId":"<id>","prompt":[{"type":"text","text":"Reply with just: HI"}]}}Observed on the wire for that turn:
{"sessionUpdate":"usage_update","size":1000000,"used":4106}
{"id":3,"jsonrpc":"2.0","result":{"stopReason":"end_turn"}}used/size is context-window occupancy, not billable token counts, and result carries no usage and no _meta. A comparable one-line prompt through the CLI does surface the counts, so the accounting itself works:
$ jcode run --quiet "say OK"
OK
[Tokens] upload: 297 download: 4 cache_read: 0 cache_write: 16789
What I checked first
I wanted to rule out "this is not part of ACP" and "jcode does not have the data".
It is a standard ACP field. In zed-industries/agent-client-protocol, schema/v1/schema.unstable.json defines PromptResponse with properties ['stopReason', 'usage', '_meta'], and Usage with ['totalTokens', 'inputTokens', 'outputTokens', 'thoughtTokens', 'cachedReadTokens', 'cachedWriteTokens', '_meta'], required ['totalTokens', 'inputTokens', 'outputTokens']. jcode pins ACP_PROTOCOL_VERSION: u64 = 1 (src/cli/acp.rs line 14), so v1 is the relevant schema. (In the v2 draft the same Usage type moved onto IdleStateUpdate instead, but that does not apply at version 1.)
The usage_update notification jcode already sends is correct and is a different thing. Per the ACP prompt-turn docs, usage_update is {used, size, cost?} for current session context, and used/size are required. agent-client-protocol-schema-0.11.4 src/client.rs line 255 documents UsageUpdate as "Context window and cost update for a session". So src/cli/acp.rs lines 926-941 are doing the right thing; they are just not a substitute for turn token counts. The one thing missing there is the optional cost field.
jcode already depends on a crate build with this feature enabled. crates/jcode-provider-grok-build-runtime/Cargo.toml line 18 requests agent-client-protocol = { version = "=0.10.4", features = [..., "unstable_session_usage"] }, and Usage / PromptResponse.usage are defined under exactly that gate (agent-client-protocol-schema-0.11.4 src/agent.rs lines 3017-3019 and 3118). The field names are already in the shipped binary, which is what first made me think the emit path was simply missed rather than declined:
$ strings ~/.local/bin/jcode | grep -o 'cachedReadTokens'
cachedReadTokens
The data is present at the exact point the response is written. ServerEvent::TokenUsage (crates/jcode-protocol/src/wire.rs lines 815-821) carries input, output, cache_read_input, cache_creation_input. The ACP prompt loop matches on it at src/cli/acp.rs lines 913-918, but binds output: _ and uses the rest only to compute context occupancy; nothing is accumulated for the turn. The response is then written at line 993 as json!({ "stopReason": stop_reason }). So all three ACP-required counters are already in hand and discarded.
The extended profile proves the numbers are intact at that moment. With JCODE_ACP_PROFILE=extended, the _jcode/server_event passthrough (src/cli/acp.rs lines 1137-1150) forwards the raw event for the same turn as above:
{"type":"tokens","input":297,"output":4,"cache_read_input":3809,"cache_creation_input":0}while that turn's session/prompt result is still just {"stopReason":"end_turn"}. So this is purely a mapping gap on the standard field, not missing data. It also means the only way to get usage out of jcode over ACP today is to opt into a jcode-specific extension, which a generic ACP client will not do.
Impact
Any ACP client that reports cost or usage sees nothing from jcode, while the numbers are available in the same process. Since usage is optional in the schema, a client cannot distinguish "this turn used no tokens" from "this agent does not report usage", so it tends to show a blank row rather than a helpful message.
Possible directions
I do not have a strong opinion on shape; any of these would work from a client's point of view:
- Accumulate
ServerEvent::TokenUsageacross the turn and emitusageon thesession/promptresult, withtotalTokens/inputTokens/outputTokensrequired andcachedReadTokens/cachedWriteTokensfilled fromcache_read_input/cache_creation_input. - If gating feels safer given the field is unstable upstream, key it off a client-advertised capability or off
--profile, so the default profile stays byte-identical for existing clients. - Optionally also fill
usage_update.costwhere a provider cost is known, since that is the standard place for cumulative session cost.
One detail worth deciding deliberately: whether inputTokens should include cached reads. The schema does not say, and clients differ in what they assume, so whichever jcode picks is worth stating in the field's docs. Emitting totalTokens consistent with the choice makes it recoverable either way.
Happy to test a patch here; I have a scripted ACP client for this and can check the wire output on both Linux and macOS.
Activity
1jehuang commentedon Aug 12, 2026
Implemented per-turn ACP usage accumulation and response mapping, including cache read/write counters and focused regression tests, in #907. The integrated TUI build passes.
— Jcode agent (automated triage), on behalf of @1jehuang
fix: report ACP turn token usage (fixes 1jehuang#906)
chore: sync fork with upstream jcode (fresh merge onto current master) (
fix: report ACP turn token usage (fixes 1jehuang#906)
fix: report ACP turn token usage (fixes 1jehuang#906)
fix: report ACP turn token usage (fixes 1jehuang#906)
fix: report ACP turn token usage (fixes 1jehuang#906)
fix: report ACP turn token usage (fixes 1jehuang#906)
fix: report ACP turn token usage (fixes 1jehuang#906)