r/ClaudeCode • • 9h ago

Tips & Workflows Claude Code kills a session after 3 compactions in a row. A UT lab let the agent choose when to compact: 0/150 tests became 147/150

If you've had a long Claude Code run die after compacting over and over, a UT Austin lab measured exactly that. Claude Code ends a session when context refills right after compaction three times in a row.

Their test: Opus 5.5 building a Mastodon style server with a 100K context budget. Vanilla Claude Code compacted 6 times in 22 steps, hit that rule and finished with 0/150 tests passing. Their wrapper, ext, let the agent decide when to compact and what to keep. Same model, 128 steps, 10 compactions, 147/150 tests.

ext runs on top of Claude Code without touching its source. The agent writes small policies (compaction, reasoning effort, spend) through typed hooks, and a Z3 solver proves each one follows the operator's rules before it loads. Over 550 runs they report zero rule violations.

Other results from the post:

  1. On nine coding tasks from DeepSWE, SWE-bench Pro and Terminal-Bench 2.1 at the default 1M window, a reusable policy took Opus from 14/27 to 22/27 solves at the same cost.
  2. Haiku 5.5 on 11 tasks: 6 were solved every time at low effort, and always using max effort cost up to 5.9x the cheapest level that worked.
  3. Showing the agent a live context meter backfired. Long task success went from 92% to 52%, which they call context anxiety.

Code isn't out yet (waitlist). What you can do today from the same findings: keep long runs on a bigger window if your plan allows it, and when a run starts compacting every few turns, stop it and restart from a written handoff note instead of letting it grind into the auto stop.

Post: https://ut-infraai.github.io/2026/12/01/agent-harnesses-need-their-ebpf/

1 Upvotes

7 comments sorted by

•

u/AutoModerator 9h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/CandidSystem6155 6h ago

The part that helped us most with long runs was not trusting the compacted summary at all. We keep a handoff file per working folder, a SessionStart hook injects it into the next session, and another hook writes it when the session goes idle, so starting fresh is cheap and compaction is only for limping through to the next save point. A fresh session reading a short handoff beats a third compaction every time for us.

1

u/michaelTM_ai 6h ago

thats basically what i ended the post with, but ur version with the hooks is better. writing the handoff on idle instead of waiting for the agent to remember is the key bit. do u keep it per folder so parallel sessions dont overwrite each other?

2

u/bostonaholic 6h ago

Z3 checking the policy before it loads is what makes letting the agent write its own rules OK, since something outside the model decides if they're allowed. The 0/150 mostly shows the 3-compaction kill is a bad fit for long runs, though. I'd want to see it against vanilla with that limit raised.

1

u/michaelTM_ai 6h ago

yeah fair, they dont run that baseline. the 0/150 is mostly the kill rule. the cleaner comparison in the post is the 9 short coding tasks at the default 1M window where compaction barely matters, opus went 14/27 to 22/27 at the same cost. thats the number id trust more

2

u/Long-Barracuda-7521 6h ago

The pattern in that report matches a failure mode that has nothing to do with the task being hard: the run dies because, after enough compaction cycles, the original task description is simply not in the context any more.

Two things that make long runs survive without a wrapper:

  • Externalise state. Have the agent keep a PLAN.md / STATE.md in the repo: what is done, what is next, and the exact command that verified the last step. After a compaction it re-reads the file instead of trying to reconstruct the task from a summary. A few seconds per step, and the run stops depending on what survived the last squeeze.
  • Feed it less. Most of what refills context is tool output nobody reads: full test logs, a diff of the whole tree, directory listings. pytest -q, git diff --stat, --no-pager, | tail -40 cut the biggest offenders by an order of magnitude, and you get more steps before compaction regardless of who decides when to compact.

The UT lab result is interesting for the opposite reason: it moves the decision to the model, which is the only party that knows which parts of the transcript still matter. But even without that, small steps plus a state file get most of the way there.

1

u/michaelTM_ai 4h ago

yeah the post lists "keep the original task statement" as one of the rules the harness enforces no matter what, so they hit the same thing. the exact verify command in STATE.md is a good touch, makes it cheap to check where u actually are after a restart