Agent traces contain everything you need to debug a weird run, but they're stored as walls of nested JSON. Stop reading them as documents, watch them as timelines.
---
title: How I debug Claude agents by replaying their trace
published: true
canonical_url: https://ferhatatagun.com/blog/debug-claude-agents-by-replaying-traces
description: Agent traces contain everything you need to debug a weird run, but they're stored as walls of nested JSON. Stop reading them as documents, watch them as timelines.
tags: claude, anthropic, agents, debugging
cover_image:
---
Your agent did something weird in production. A user reported it, you found the failed run in your logs, and you're now staring at a JSON file that's 400 messages long, half of them are `tool_result` blocks the size of small databases, and somewhere in there is the moment the agent decided to do the wrong thing.
You can't re-run the agent: the API state has moved on, the tool would behave differently now, the prompt has been updated three times since. You have only the trace.
The way most of us read agent traces is: open the JSON in an editor, ctrl+F for the tool name we suspect, scroll through walls of escaped strings, try to mentally reconstruct the sequence. It takes thirty minutes, by the end of which you have one of three answers — "yeah I see what went wrong," "I'm pretty sure I see what went wrong," or "I have no idea what went wrong." About a third of the time it's the third one, and you go ship a band-aid that may or may not fix the actual problem.
The thing nobody talks about is that this isn't a hard problem. The JSON contains all the information. The issue is purely *presentational* — it's nearly impossible to read.
**TL;DR**
When you save a Claude agent run, you usually persist the `messages` array — the full conversation including the model's responses and the tool results you fed back. A six-step agent run looks roughly like:
[
{ "role": "user", "content": "Find me the cheapest flight from IST to LAX next Tuesday" },
{ "role": "assistant", "content": [
{ "type": "text", "text": "I'll search for flights and check prices." },
{ "type": "tool_use", "id": "tu_01", "name": "search_flights", "input": {...} }
]},
{ "role": "user", "content": [
{ "type": "tool_result", "tool_use_id": "tu_01", "content": "[<2KB of JSON>]" }
]},
{ "role": "assistant", "content": [
{ "type": "text", "text": "Looking at three of those..." },
{ "type": "tool_us// related articles
Twitter/X: 🚀 While you’re sleeping, the market is printing. I’m a futures trader, sharing my personal high…
Twitter/X: anthropic is literally crushing the new model benchmark https://t.co/Mhyy2SZtUQ
Twitter/X: EU regulator evaluating implications of Anthropic Mythos curbs after US directive https://t.co/FE…