How compaction works in Tarsk
What Tarsk does when a long chat fills the model's context window, and how the agent keeps working without you.
A long coding chat fills up. The agent reads files, runs tests, reads logs, and edits code, and each step adds text the model must read again on the next step. At some point the model has no room left. Compaction is how Tarsk makes room so the same chat can keep going.
The context window is a desk
Think of the context window as the model’s desk. Your request, the files it opened, command output, and its own replies all sit on that desk. A bigger model has a bigger desk, but every desk has an edge.
When the desk is full, the provider rejects the next request. In older agents that ended the turn. You typed continue, opened a new chat, or explained the job again.
You can see how full the desk is. Open the context usage view in the chat to see the fill level split into System prompt, Tool definitions, Rules, Skills, Subagent definitions, and Conversation. Conversation is the part that grows.
Two kinds of compaction
Tarsk uses two methods. They fit different moments.
| Method | Who starts it | What the model gets next |
|---|---|---|
/compact |
You | A summary the model writes, plus your most recent exchanges word for word |
| Context rollover | Tarsk | A fresh context window with a handoff record, plus full access to the old transcript |
/compact: you pick the moment
Type /compact in the chat. Add a focus if you know what comes next, for example /compact focus on the login bug.
The model then writes a summary of the chat so far. The summary keeps the project goals, technical decisions, changed files, current state, and open tasks. It drops debug noise, failed attempts, and long tool output. Your latest exchanges stay as they were.
Use /compact at a task boundary, or before a large new request in a chat that already ran for a long time. Tarsk needs at least two completed exchanges before it can compact.
Context rollover: Tarsk picks the moment
You do not need to watch the meter. When the context reaches 80% of the window, Tarsk starts a fresh context window and gives the agent a handoff record. This happens between your messages, and it also happens in the middle of a run. The agent keeps the same task and does not wait for you.
A rollover makes no extra model call. Tarsk builds the handoff from data it already has, so a rollover costs no tokens.
What the handoff contains
The handoff record carries:
- Notes. The agent writes notes as it works: decisions, constraints, things it found. Notes move into every new window.
- Todos. The open todo list moves across as it is.
- Repository state. The branch, the current commit, and the working tree status at the moment of the rollover.
- A summary of changes. For each changed file, the lines added and removed and the parts of the file that changed. The agent does not need to run a diff to learn what it already did.
- Your follow-up messages. If you sent instructions to the agent during the run, those instructions move across.
- The last few messages, so the agent knows where it stopped.
The handoff also tells the agent to check the live state before it acts. A record of the past is not proof that the work is complete.
The full transcript stays
Tarsk keeps the full transcript, and the agent can search it with its history tool. If the agent needs the exact error from an hour ago, or the wording of your first instruction, it finds the entry and reads it.
Your view stays the same too. The chat still shows every original tool card, so you keep a full record of the work.
What you see in the chat
A compaction shows as a row in the chat. While it runs, the row says Compacting. When it finishes, it says Context compacted. Expand the row to see the reason, for example:
- “Context reached 80%; started a fresh context window and continued this turn”
- “Started a fresh context window to continue this turn; history remains searchable”
When the window still overflows
Sometimes one step adds a large amount of text at once, such as a big file or a long log. The provider then rejects the request before the 80% check can act. Tarsk recovers in two steps:
- It shortens older tool results and tries again. The chat shows “Context was full; retrying with tighter tool-result compaction.”
- If that is not enough, it starts a fresh context window and continues the turn.
After two recoveries in one turn, Tarsk stops. It does not compact in a loop.
Prompt cache and cost
Many providers give a discount on text the model read in the previous request. This is the prompt cache. A fresh window resets the cache, so an early rollover can cost more than it saves.
Tarsk adjusts for this. When the chat reads from a warm cache, Tarsk waits longer before a rollover: until 85% between messages, and until 95% during a run. The overflow recovery still acts if the window fills before that point.
Limits to know
- A summary from
/compactis shorter than the chat. Details that are not in the summary leave the model’s working memory. Say them again if the next step needs them. - A single very large file read can fill a fresh window again. Ask the agent to read a smaller part of the file.
- The handoff is a recovery record. The agent checks the repository before it acts, and you see that as a short extra step after a rollover.
- For a new, unrelated job, start a new chat. It is faster than any compaction.
Try it
- Run a long task and watch the context usage view climb.
- Type
/compactwith a focus at the end of a task, and read the summary. - Let a run pass 80% and expand the Context compacted row to see what happened.
Download Tarsk or read the documentation.