Inspecting what the agent sends
Customizing agents · topic customizing-agents/inspecting-the-agent
What an agent sends to the model is hidden by default. This topic covers watching how full the context is while working, reading the record a harness keeps of each session, and logging the exact requests the agent sends to the model provider, along with why each of these records holds sensitive data.
Concepts
- Context meter
- A live view of how much of the context window a session uses. A status line can show the share in use and the tokens so far as the session runs, and a context command breaks the use down by category, such as instructions, tools, memory and messages. Watching it shows when a session is getting full and which tools or files are expensive, so the learner can compact or start fresh before the agent starts dropping instructions. glossary
- Session record
- The file in which a harness saves a session, with every message, tool call and tool result, so the session can be resumed later. It is the most complete account of what the agent saw and did, and the place to find where a run went wrong. It is also plain text on disk, kept for a set number of days, and it holds whatever passed through a tool, including file contents and any secret the agent printed. glossary
- Request logging
- Recording the exact requests an agent sends to the model provider and the responses it gets back. The agent can be pointed at a gateway between it and the provider that logs every request, or a monitoring export can be set to include full request bodies, which it leaves out by default. The log shows what each tool description, file and instruction costs. It holds everything the agent read, so it stays on systems the team controls. glossary
Links
- Builds on: What an agent is, Running a coding agent
- Leads to: nothing yet
- Related: Connecting tools with MCP, Context engineering for code
- Competencies drawing on it: Connects an agent to tools and data safely
Lessons
- Seeing what the agent sends (tutorial)
Your reference
Each lesson above adds its takeaways and its example here once you finish it. Your reference lists every lesson you have finished.
Seeing what the agent sends
Unlocks when you finish Seeing what the agent sends.
Takeaways
/contextbreaks down what fills the window by category, and a status line can show the share in use, the input tokens and the record's path after every reply.- The session record under
~/.claude/projects/holds every message, tool call and tool result in plain text, secrets included, untilcleanupPeriodDaysorclaude purgeremoves it. OTEL_LOG_RAW_API_BODIES=file:<dir>writes each request, with the system prompt, the tool definitions and the messages, to a local directory. The log shows what each part costs in every request.- Turn the log on for one session, keep it in a directory outside every repository that only you can read, and delete it when you have your numbers. A gateway on
ANTHROPIC_BASE_URLthat you don't run holds a copy of the same data. Anthropic doesn't vouch for gateway products made by others.
Example
Two status lines · open in the lesson
Run statusline_demo.py in the fixture directory, and compare with the output below. The first sample input is from before the first request, when the share is still null. The second is from after a request.
used_text = "-" if used is None else f"{round(used)}%"total_text = "-" if total is None else f"{total:,} tokens"record = "-" if not transcript else os.path.basename(transcript)return f"context {used_text} | {total_text} | record {record}"Prints the lines below (verified in CI from site/examples/customizing-agents/seeing-what-the-agent-sends/statusline_demo.py)
context - | 0 tokens | record 2f6c0d1e-5a7b-4c9d-8e3f-1a2b3c4d5e6f.jsonl context 12% | 23,480 tokens | record 2f6c0d1e-5a7b-4c9d-8e3f-1a2b3c4d5e6f.jsonl
Sources
Claude Code context windowExplore the context window, Claude Code documentation (reference)Claude Code statuslineCustomize your status line, Claude Code documentation (reference)Claude Code claude directoryExplore the .claude directory, Claude Code documentation (reference)Claude Code monitoringMonitoring, Claude Code documentation (reference)Claude Code llm gatewayOther LLM gateways, Claude Code documentation (reference)