Retaining Agent’s Persona After A Compact
“Aaah.. We discussed this already! How many times do I have to tell you the same thing?”, and then,
“Uh.. unwanted compaction happened while I was away, reload X from the conversation history please.”
I typed that today, and I have typed some version of it more times than I would like to admit.
If you use Claude Code for anything long, you know the feeling. The thread fills up, a compaction happens, and after it I find I am talking to a completely different person. Everything I said, all the instructions I gave along the way, gone! It is as if the person I was working with got hit on the head and has amnesia or something. Still polite, still eager to help, with no idea why we decided what we decided.
Now, I know the compact mechanism is not stupid. It is actually quite intelligent, it has different strategies for different types of files, skills, CLAUDE.md and what not. But it is still true that after a compact, it feels like talking to someone else, and I think I know why.
The Problem
The instructions that matter most are often not in any file. In a typical development, I do not stop every time, go back and edit CLAUDE.md, and ask the thread to reload it; I doubt anyone does. I just say it in the chat, when it comes up. One review at a time. Alembic, not Flyway. Please stop doing that thing you keep doing, and so on.
These are exactly the things a compact can lose, or keep only in its own words. And once they are gone, everything goes for a toss. I start correcting the same things again, the work starts drifting from what we agreed, and it does not feel like a useful thread anymore.
What We Did
So we built compact-brief, a skill in our agentic workflow. The thread writes it just before the compact, while it still remembers everything, and it comes in two parts.
The first part is a one-line compact command, with an instruction on what the summary must keep, like the stage of the work, the files in play, and every correction I gave. It has to stay one line. In Claude Code, a long or multi-line paste collapses into a placeholder and goes to the model as an ordinary prompt, so nothing gets compacted, and nothing tells you so!
The second part is a resume brief, which I paste as the first message after the compact. It says where the work stands, which files to re-read from disk, and what is still waiting on me. It also carries the part I care about most, what I actually said. My decisions go in verbatim, because a paraphrase is a different decision, and so do the corrections I had to make more than once. If the files, the brief and the summary disagree, the files win, then the brief, and the summary comes last.
And this is the amazing part, it feels like talking to the same person! The thread comes back knowing how I want things done, and I can get on with the work instead of explaining myself all over again.
The 21 Days Long Build Run
This is what saved me in a 21-day migration I posted earlier about. No context lasts for 21 days, so the work had to get through compact after compact without forgetting what we had agreed. We also found a bunch of issues in main along the way, so there was plenty of new material pushing the old decisions out. Without the brief, I think I would have spent a good part of those 21 days repeating myself.
What It Does Not Do
This is not a silver bullet, and it will not solve all the problems. You have to ask for the brief before the compact. When a compaction comes on its own while you are away, as it did for me today, there is no brief, and you are back to asking the thread to dig through its history. A test run from before the compact also does not count after it, so compacting just before the final verification costs one more full run. And the brief is only as good as what the model thought to put in it.
The whole point is continuing a conversation long enough to get a meaningful code change implemented, is all. Try this out, let me know what you think!