Skip to content

telemetry: populate context_tokens field in observability JSONL (currently always 0) #656

@agents-squads

Description

@agents-squads

Data Blind Spot: context_tokens field is always 0

Requested by: data squad (Goal #4 — new data capture proposals)

Current State

All 57 records in executions.jsonl have "context_tokens": 0. The field exists but is never populated.

{"input_tokens": 26, "output_tokens": 5950, "cache_read_tokens": 583096, "context_tokens": 0}

Blind Spot

We cannot answer:

  • How much context is each agent consuming per run? (context bloat = slower, more expensive)
  • Which agents are hitting context limits and why?
  • Is context growing over time as memory files accumulate?
  • What's the ratio of context_tokens to output_tokens? (efficiency metric)

Context token cost is real — cache reads are cheaper but still billed. A single large state.md or CLAUDE.md can dominate the context budget.

Proposed Capture

Populate context_tokens with the total tokens loaded into Claude's context before any user message:

  • CLAUDE.md files loaded
  • Agent definition file
  • State/memory files loaded
  • Skill files loaded

This is distinct from input_tokens (the user prompt) and cache_read_tokens (already tracked).

Why This Matters

The economics squad tracks cost per useful output. Without context_tokens, we can't compute the full cost of a run or identify context-bloated agents. This is low-effort instrumentation since the context size is known at invocation time.

source:data

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions