xctrace is the command line tool behind Xcode Instruments, and it’s what an AI agent reaches for when you give it a .trace file. Parsing Xcode Instruments traces with AI agents works, but it’s slower, more expensive, and less consistent than you might expect.

I gave a talk about this at Do iOS 2026 in Amsterdam. The video is embedded below, and this article follows the same path with the details I didn’t have time for. If you’re new to Instruments itself, start with my Xcode Instruments guide.

Watch the talk

My talk at Do iOS 2026: how to find, fix, and verify performance issues with an agent.

If you want to jump to a part of the talk:

Why agents struggle with Instruments traces

A .trace file isn’t one file. It’s a package with the recorded data of every instrument you used, and Instruments reads it through its own UI. Your agent doesn’t have that UI. The command line way in is xctrace export, which writes the tables of a trace to XML:

# List every table in the recording
xcrun xctrace export --input Recording.trace --toc

# Export one table, for example the potential hangs
xcrun xctrace export --input Recording.trace \
  --xpath '/trace-toc/run[@number="1"]/data/table[@schema="potential-hangs"]'

On a 334 MB recording from my benchmark app, the table of contents listed 82 tables. Even a query that returned only 1 KB of XML took 12 to 16 seconds on my Mac, because xctrace opens the whole trace for every call. An agent has to find out by itself which tables matter, what the columns mean, and how to read the XML. What it does is write scripts, and that’s where your tokens go.

I gave an agent the same trace three times

For the talk, I recorded my Video Compressor app after I had already optimized it. I first went through the trace manually in Instruments, so I knew the main suspect: a library thumbnail cell loading video thumbnails from iCloud while scrolling. That was valuable, because I could verify the agent’s answer against what I had found myself.

Then I started three fresh tasks with Claude Sonnet 5.5 and a 300k token context window:

RunPromptTimeResult
1The trace as an attachment30 min6 issues, including the thumbnail cell
2The trace as a file path20 minThe thumbnail cell again, but two issues disappeared and two new ones appeared
3An optimized prompt that asks for a deep analysis26 minRanked findings, a list of “checked and not worth fixing”, 12 scripts, one new issue, and two earlier issues missing

I expected a file path to be cheaper than an attachment, because the agent could peek into the file instead of loading all of it. The context usage did go down, but it was one run per prompt, and the outcome wasn’t better. An attachment is a file path under the hood, so I didn’t see a real difference.

The more important lesson is about consistency. All three runs found the thumbnail cell, which was great. However, the rest of the list changed every time, because every fresh task starts without the learnings of the previous one. Each agent had to figure out the trace format again and wrote its own parser. That also means you can’t conclude from a missing issue that it’s solved.

I also noticed that some of the scripts the agents wrote ended up in a temporary directory, so I didn’t even know they existed. If you want to reuse them, ask your agent to create reusable scripts and to store what it learned in a reference file that your AGENTS.md points to.

Why context decides the result

The context window is the limit you work with, and a trace file eats a big part of it. The visual below shows what that looks like for a 300k window. The numbers are illustrative, but they’re based on my own setup.

Three columns showing a 300K context window: a fresh task with 200K left, the same window after loading an Instruments trace file with 40K left, and after summarizing with 180K left and a 20K summary
The same 300K context window in three moments: a fresh task, after loading a trace, and after the agent summarized the session.

Read the columns from left to right:

  • Fresh task: before I write a prompt, 100K is already gone. The system prompt and tool definitions take 20K, skills and MCP tools 50K, and AGENTS.md 30K. That leaves 200K for the task.
  • Trace loaded: the trace file takes 160K. Only 40K is left to analyze it, plan a fix, and change the code.
  • After the reset: when the window is full, the agent summarizes the session and continues in a fresh window. The summary takes 20K and leaves 180K, but it’s the agent that decides what ends up in it.

That last step is where details get lost. If I told my agent earlier to support dark mode and that instruction doesn’t make it into the summary, the next view it writes might not support it. That’s also why the same model feels great for one developer and disappointing for another: the setup around it is different.

If you’re curious where your context goes, my article on how to reduce token usage in Claude Code, Codex, and Cursor shows how to find out.

Parse the trace once, in code

The scripts of all three runs did the same job: read the trace, add up what matters, and rank the results. You don’t need an agent to figure that out every time. You can do it once, in deterministic code, and let the agent read only the outcome.

That’s why I built RocketTrace. It analyzes a recording on your Mac, ranks the findings by measured impact, and hands your agent a compact evidence package. You can copy an Agent Prompt per finding, or let your agent run the rockettrace CLI with the Agent Skill. I wrote about how that works in Introducing RocketTrace.

The RocketTrace overview of a performance recording, with top opportunities ranked by impact and checks for hangs, hitches, SwiftUI, and concurrency
RocketTrace ranks the findings of a recording, so your agent starts with the strongest lead.

I ran the same trace with the same model in a fresh task. The agent finished in 28 seconds and used about 30 times fewer tokens. The result had the same main suspect, with the evidence and a suggestion on how to fix it. Two details matter here:

  • The analysis time moved into the Mac app instead of disappearing. The agent just doesn’t spend it.
  • RocketTrace only returns the findings that matter most for the recorded time span. It doesn’t list every small issue.

Cursor’s context usage panel shows how that looked for each run. Prompts 1 to 3 are the three runs from the table, and prompt 4 is the run with RocketTrace:

Four columns showing the context window after each prompt: 80% used after prompt 1, 54% after prompt 2, 74% after prompt 3, and 25% after the RocketTrace run, with 225.8K tokens left for the task
The context window after each run, measured with Cursor’s context usage panel.

The percentages show how full the window was at the end of each run, not the total tokens spent. After the first prompt, only 59.9K was left for the task. After the RocketTrace run, 225.8K was left, which is the room your agent needs to plan and apply the fixes.

The difference grows with every run. When I improve RocketSim, I often use 10 to 15 runs to validate a change, and paying for three prompts’ worth of parser scripts every time adds up quickly.

You can also count on the output. If an issue doesn’t show up in a second run, it’s actually solved, instead of the agent deciding to skip it this time. In a more controlled benchmark with 20 planted issues, both models found more issues using about 6 times fewer tokens. The 30 times in this article comes from one demo trace, so treat it as a single data point.

Subagents and the new xctrace commands in Xcode 27.2

There are two other options I want to be honest about.

Using a subagent

A subagent can run the whole trace analysis and give only its output back to your main agent. That keeps the main context lean, and it’s a good approach. The catch is the model choice. You often use a cheaper model for subagents, but reading the trace is where the issues are found. You want the smart model there, which makes it a fight for tokens again.

The xctrace commands in Xcode 27.2

Xcode 27.2 adds three commands to xctrace: toc, show, and triage. Xcode 26.6 doesn’t have them. toc lists the tracks of a trace, show prints a call tree, summary, or list of one track as text or Markdown, and triage reports the hangs of one process together with what the main thread was doing. Apple lists them as new features in the Xcode 27.3 beta release notes, which also mention two Apple specialists for coding agents: one for xctrace and one for hangs.

They’re a welcome step, and I use xctrace show inside RocketTrace to look deeper into a specific time range. They’re also limited:

  • triage covers hangs only and needs both the Hangs and Time Profiler instruments in your recording.
  • show returns one detail of one track per call, so your agent still decides what to ask for.
  • Every call opens the trace again. On my 1.5 GB recording, xctrace triage took almost two minutes, and on a 334 MB recording about 20 seconds.

For me, they didn’t give the in-depth output I wanted, which is why I keep using RocketTrace.

What I took away from this

I used an Instruments trace as the example, but the lesson applies to anything an agent has to parse. If you can do the reading statically, you save tokens and you get the same answer every time. Beyond that:

  • Care about your agent context. Ask your agent to review your last sessions and tell you where your tokens went. A large AGENTS.md that loads into every task is a common culprit.
  • Compound your learnings. An agent only remembers within a task. A reference file or skill makes sure the next task starts with what the last one learned.
  • Automate the compounding. I use a hook that injects a learning prompt every tenth prompt and stores the outcome in my AGENTS.md. You can read how hooks work in Agent hooks in Claude Code, Cursor, and Codex.

If you want to see the agent workflow without the trace parsing, read how I made RocketSim’s accessibility fetching 25 times faster in Xcode Time Profiler with AI Agents.

Frequently asked questions

What is xctrace?

xctrace is the command line tool for Xcode Instruments. You can use it to record a trace, export the recorded data to XML, and, since Xcode 27.2, print call trees, summaries, and hang reports as text. It is also what AI agents use when you ask them to analyze an Instruments .trace file.

Can an AI agent read an Xcode Instruments trace file?

Yes, but not directly. A .trace file is a package of tables, so the agent exports data with xctrace, writes scripts to parse it, and reads the results. That works, but it takes a lot of time and tokens, and the findings can differ from run to run.

What did Xcode 27.2 add to xctrace?

Xcode 27.2 adds xctrace toc, xctrace show, and xctrace triage. They print the tracks of a trace, a call tree, summary, or list from one track, and a report of the hangs in a trace, all as text or Markdown. Xcode 26.6 doesn't have them.

Should you use a subagent to analyze a trace?

A subagent keeps the trace analysis out of your main context, which is a good start. The trade-off is that you often pick a cheaper model for subagents, while reading the trace is the part that decides which issues you find.

How do you get consistent results from a trace analysis?

Parse the trace with code instead of letting the agent write a new parser every time. The same input then gives the same findings, so an issue that's missing in a second run is actually fixed. The agent only reads the findings and works on the code.

Conclusion

Agents can parse Xcode Instruments traces, but they do it slowly, and the results change every run. Moving the parsing into code gives you consistent findings and leaves your agent’s context for the part where it matters: fixing the code. Whatever setup you use, keep an eye on how much context the analysis costs.

These workflows are a subset of what I teach in my dedicated course. If you want to learn how to manage context, skills, hooks, and MCPs step by step, the AI Fundamentals course covers it.

Feel free to contact me or tweet me on Twitter if you have any additional tips or feedback.

Thanks!