> Agent-ready spec from Diff of the Day (2026-12-02, idea 2). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: First-call context audit

## Problem Statement
Every call of a long agent run resends the same opening block: system prompt, tool definitions, agent instructions and memory files. Nobody checks how big it is. One engineer found that listing banned tools made an agent file start at about 70K tokens, against 15 to 17K when it listed allowed tools.

## Goals
- Show the token size of each part of the first request of a session.
- Rank the parts by size so the largest one is obvious.
- Show the before and after size of one rewritten agent file.
- Finish an audit of one session in under 2 minutes.

## Non-Goals
- Changing the agent or its config automatically: a person should read each change, because a smaller prompt can lose needed rules.
- Judging prompt quality: the audit counts size only, since quality needs a task benchmark.
- Exact billing: counts are estimates from one tokenizer.

## User Stories
- As an engineer, I want to see which part of my first call is largest so that I trim the right file.
- As a team lead, I want to compare two versions of an agent file so that I can approve a change with numbers.
- Edge case: as an engineer, I want the audit to say when a tool list is added by the desktop app and not by my config, so that I do not search my own files for it.

## Requirements
### P0
- A capture step that saves the first request of a session as a local JSON file.
  - [ ] Only the first request is saved.
  - [ ] The file stays on the local disk.
- A splitter and counter that reports tokens for system prompt, tool definitions, agent instructions and memory files.
  - [ ] Parts add up to the total within 2%.
  - [ ] The report names the tokenizer it used.

### P1
- A compare command for two captures.
  - [ ] The output shows the change per part and in total.
- A hint that flags instruction text which lists forbidden tools.
  - [ ] The hint cites the line numbers.

### P2
- A per-session history of first-call size.
  - [ ] A rise of more than 20% between sessions is flagged.

## Success Metrics
- Tokens in the first call before and after trimming.
- Share of the first call taken by tool definitions.
- Time to run one audit.

## Open Questions
- Where can you capture the first request without a proxy?
- Which tokenizer is closest to your provider?
- Do subagents start with the same block or a smaller one?

## Timeline
One evening: capture and counting first, compare second, hints if time remains.

## Agent Instructions
- Suggested stack: Python or TypeScript, one tokenizer library, a local HTTP logging proxy or the agent debug log.
- Build order: Capture, splitter, counter, report, compare, hints.
- Safety: Keep captures on the local disk, because they contain your prompts and file contents; add the capture folder to the ignore file of your repository; never upload a capture to a model or a service.
- Done when: One real session is audited, one agent file is rewritten, and the compare report shows the before and after size.

## Sources
- https://lnkd.in/p/dvy5Z2Db
- https://www.requesty.ai/blog/claude-5-minute-prompt-cache
