C.W.K.
Stream
Lesson 05 of 05 · published

The Measurement Loop

~23 min · logging, telemetry, budget

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Budget without logs is theater

If you do not log token usage, cache hits, truncation, compaction events, and output length, you are guessing. Good context operations are boringly measurable. The first time you actually graph token spend per session you will find at least one workflow that is 5x more expensive than you thought.

Minimum telemetry contract

Every long run should record: input tokens, output tokens, cached tokens, model id, request latency, and whether a checkpoint or compaction happened. That data tells you when to trim, cache, split, or hand off — without re-running the entire session.

Telemetry belongs beside the work

For agents, context metrics are not infrastructure trivia. They explain why quality changed halfway through a task. The first place to look when a long session goes wrong is the token graph, not the chat history.

Code

Telemetry contract·typescript
type ContextTelemetry = {
  model: string;
  inputTokens: number;
  outputTokens: number;
  cachedTokens: number;
  reasoningTokens?: number;
  latencyMs: number;
  compacted: boolean;
  checkpointId?: string;
  prefixVersion?: string;
};
Per-turn log line·json
{
  "turn": 47,
  "model": "claude-sonnet-4-7",
  "inputTokens": 38420,
  "cachedTokens": 32100,
  "outputTokens": 1820,
  "latencyMs": 4321,
  "cacheHitRatio": 0.835,
  "prefixVersion": "rules-v3"
}

External links

Exercise

Design a context telemetry row for your AI app or coding-agent workflow. Include at least six fields, and one field that helps the human decide when to checkpoint.
Hint
A 'context_used_pct' field is a great human-facing signal. So is 'turns_since_last_checkpoint.'

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.