# Skill: Compact an agent's context at the right moment to prevent mid-task memory loss > Use this skill to control when the agent's conversation history is compressed -- choosing the safe window (task boundary) instead of letting auto-compact fire at the worst possible moment. Source: sodigi-learn -- vibecoding/kompakt-chistka - https://sodigi.io/learn/vibecoding/kompakt-chistka ## When to use - A long session is accumulating large amounts of file content, logs, and iteration history. - You are finishing one task chunk and about to start a different one. - The agent is starting to repeat itself, slow down, or confuse details -- signs of context overflow. - You want to prevent auto-compact from firing mid-debugging and erasing the bug trail. ## Core rules - Compacting frees desk space but destroys all details that were only in the conversation -- not in files. - What survives a compact: files on disk, project rules, the todo list, git history, memory files. - What is lost: chunks of files the agent read but did not write anywhere, inline reasoning, in-chat requests ("move the button left"), intermediate variable state. - Any decision you want to survive must be written to a file BEFORE the compact, not just mentioned in chat. - A manual compact (you trigger it) is safer than an auto-compact (fires at a random moment, usually inconvenient). - Never compact mid-debugging -- you will erase exactly the details you were tracking. - Never compact right before the agent is about to apply an important decision -- it will forget the reasoning. ## Procedure (the 3-step pre-compact ritual) 1. Are you at a task boundary? If the work is still in progress, stop -- do not compact. 2. Is the important stuff written to a file? Ask the agent to write current decisions, agreements, and the next task description to a file (e.g., DECISIONS.md) before compacting. 3. Give a short hint with the compact: one line about what the next task is, so the agent starts oriented with a fresh context. ### Safe compact windows - After research is done and before implementation begins (you only need the conclusion, not all the raw material). - After a feature is completed, before starting the next one. - After a dead-end attempt, before trying a fresh approach. - Before switching to a completely different part of the project. ### Unsafe compact windows (never do these) - Mid-debugging a tricky bug. - In the middle of a large multi-file edit. - Right before the agent applies an important decision. ## Ready-to-use prompt ``` We just finished [describe completed task]. Before starting [next task]: 1. Write the key decisions to DECISIONS.md: [list what to preserve]. Also note the next task and the current problem state. 2. Now compact -- free up the context, there is a separate task ahead. 3. From here, work on [next task] WITHOUT compacting until [completion condition]. ``` ## Pitfalls - Waiting for auto-compact -- it fires at a random moment, typically mid-debugging. Trigger it yourself at a safe boundary. - Assuming the chat history persists -- anything not written to a file is gone after a compact. - Compacting too often "just in case" -- every compact is lost context; only do it when there is a clear reason. - Forgetting to give a hint after compacting -- without a brief "next we are doing X," the agent may not know where to pick up. - Treating a compact as a system failure -- it is normal housekeeping; the fix is to save important things to files ahead of time.