/compact
Compacts the current chat’s context.
Summarizes the visible chat history to free up tokens in the context window. In the Codex CLI's source code, the purpose is literally named: "summarize conversation to prevent hitting the context limit" — so /compact is meant to proactively prevent the conversation from hitting the context limit.
According to the source code, the command can't be triggered while Codex is actively working on a task; you have to wait until the current turn is finished. Codex now also compresses the history automatically in the background once a token budget threshold is reached — according to release notes (including rust-v0.143.0 and rust-v0.145.0, July 2026), now with configurable fallback settings and session-start hooks around this automatic compression. /compact additionally gives you the option to trigger this proactively yourself before Codex does it on its own. The command appears both in the terminal CLI reference and in the general app composer overview.
🔄 THE SAME TASK (“COMPACT CONTEXT”) ON OTHER PLATFORMS
- Claude Code: /compact
- Cursor CLI: /summarize
✅ WHEN TO USE IT?
Free up space before a long task
Call /compact before starting a new, extensive research task, so the existing history doesn't unnecessarily block context.
Compress manually instead of waiting
Enter /compact right after a long debugging section instead of waiting for automatic background compression.
⛔ WHEN NOT TO?
While Codex is still actively working
According to the source code, /compact is one of the commands that isn't available while a task is running.
Better: wait for the current task to finish (or cancel it), then call /compact
The conversation is still short
Summarizing costs detail; as long as there's enough context window free, it doesn't help much.
Better: just keep working
SOURCES
- Codex CLI docs: Slash Commands ↗ learn.chatgpt.com
MORE COMMANDS · Codex CLI