Skip to content

Reclaim a full context window with /compact

The money-handling refactor has sprawled. To move every float to integer cents you’ve had Codex read the importer, the SQLAlchemy models, the reports endpoint, and a pile of tests — and an hour of file dumps and command output has piled into the window. The agent is getting hazy: a moment ago it re-read a model it had already read, and it’s started hedging on decisions it was firm about earlier.

You’re in the worst spot for the two resets you already know. You can’t start a fresh session — the half-finished refactor is this thread, and abandoning it means re-establishing everything. And resuming a leaner session wouldn’t help, because the bloat isn’t in some other session, it’s right here. You’re not done, you’re not leaving, you’re just out of room. This is the exact situation compaction exists for: keep the understanding, spend far fewer tokens carrying it.

/compact # summarise the conversation so far, keep the essentials

Compaction replaces the long back-and-forth with a summary of itself. The load-bearing parts tend to survive — the goal you’re working toward, the decisions you reached, the current state of the code, the most recent turns. The verbose middle tends to collapse: the full file contents Codex read an hour ago, exact command output, the approaches you tried and discarded. You come out with roughly the same working understanding in a fraction of the footprint:

> /compact
⎿ Compacted. Conversation summarised.
Kept: goal (float → integer cents across importer, models, reports),
cents convention, which files are done vs pending, last few turns.
Collapsed: full file dumps and command output from earlier in the thread.
> /status
[the window has real room again]
> now convert the reports endpoint, the last float column
[carries on with the refactor's context intact, the dead weight gone]

Run /status (the next lesson) right after and you’ll see the window drop back down — same thread, same plan, far less weight.

A note on judgment over mechanism. The official docs describe /compact as a command you run; whether Codex also condenses on its own as you near the limit isn’t something to count on, so don’t build a habit around it doing the work for you. Treat compaction as a deliberate move you make at a clean boundary — between finishing one file and starting the next — rather than something you hope fires at the right instant. You choosing the moment beats anything choosing it for you in the middle of a delicate step.

What compaction keeps, and what it can’t

Section titled “What compaction keeps, and what it can’t”

Here’s the rule to take from this lesson if you take nothing else: compaction is lossy, so get unsaved work onto disk first. If a change exists only in the conversation — Codex described the exact new body of to_cents() in detail but you never actually wrote it to a file — compaction can flatten “here’s the precise implementation” down to “converted the amount to cents,” and the specifics are simply gone. They were never anywhere but the chat, and the chat just got summarised. Save, then compact: get the work into a file, a commit, or a note before you condense the thread holding it. Make that reflexive and compaction is free; skip it once on the wrong turn and you learn it the expensive way.

This is also where the chapter’s thesis comes home. Compaction is a bet about what matters — it keeps what looks load-bearing and discards what looks like noise, and on a long refactor those guesses are usually right but not always. The way you stop betting is to stop relying on the conversation to hold things that can’t afford to be summarised away. The cents convention, the category list, the test command — the context you cannot lose — shouldn’t live in a thread that a compaction might paraphrase. It belongs on disk, in AGENTS.md or a commit, where no summariser can touch it. Compaction is for the transient understanding of a session; the durable kind gets written down. Closing the gap between what the agent should know and what you’ve actually told it is the whole game — and a thread that’s about to be compacted is precisely the wrong place to keep anything you’d hate to lose.

The window has room again, the refactor’s context is intact, and the work that mattered is on disk where compaction can’t reach it. The thread is healthy.

But “the agent feels hazy” sent you to /compact on instinct this time, and instinct isn’t always right — sometimes the conversation isn’t even the biggest thing in the window. Before you reach for compaction reflexively, it’s worth being able to see what’s actually eating the budget, so you fix the real culprit instead of the assumed one. That’s a single command away: inspect what’s in the window.