Skip to content

Token counter #111

@oscardcstudio-cell

Description

@oscardcstudio-cell

Feature proposal: expose token usage data via postMessage

Hi! I've been using Pixel Agents and love the concept. I'm working on a fork that adds token consumption visualization, and I'd like to contribute the data layer back upstream if you're interested.

What I'm proposing

Extract token usage (input_tokens, output_tokens, cache tokens) and the model string from JSONL transcript entries in transcriptParser.ts, and broadcast them as a new tokenUpdate postMessage event to the webview.

Data only — no UI changes. The webview would receive:

{
  type: 'tokenUpdate',
  agentId: string,
  outputTokens: number,
  inputTokens: number,
  cacheReadTokens: number,
  model: string,        // e.g. "claude-sonnet-4-6"
  timestamp: string,
}

Filtered correctly: skips isSidechain entries and isApiErrorMessage entries.

Why it's useful

Anyone building on top of Pixel Agents could use this to display token counters, session cost estimates, or consumption visualizations — without having to re-implement the JSONL parsing themselves.

Scope

Small changeset: transcriptParser.ts, types.ts, constants.ts, and the corresponding handler in useExtensionMessages.ts. Probably ~80 lines total.

Question

Would you be open to a PR along these lines? Happy to adjust the approach based on your feedback before I start coding.

Thanks for building this — great project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: webviewWebview UI: React, Canvas rendering, sprites, editortype: featureNew feature or capability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions