Introduction
Within Codex, the term “reset” is not a single universal command. It corresponds to four distinct operations for different engineering scenarios: context compression for continued work, spawning a new conversation thread, clearing all historical dialogue, and restoring interrupted sessions. Improper command selection often leads to irreversible problems. Developers may accidentally erase critical conversation records or fail to release occupied token space when context windows hit capacity limits. This article systematically breaks down each applicable scenario, contrasts command behaviors, and provides standardized operational workflows.
Before exploring command operations, it is essential to understand Codex’s context mechanism. Every Codex conversation maintains an independent context window. Messages, source code segments, and tool calling logs continuously consume space inside this window. Once capacity is exhausted, the system outputs the error message: Codex ran out of room in the model’s context window.
This limitation stems from inherent LLM constraints rather than software defects. Once the token threshold is reached, developers must adopt one of three solutions: compress historical dialogue, initialize a new conversation thread, or roll back to an earlier saved session checkpoint. This principle serves as the core standard for selecting all reset operations.
Four Core Commands for Four Reset Modes
/compact: Compress Context and Continue the Ongoing Task
Applicable Scenario: The context window is nearing saturation, yet the ongoing task remains unfinished, and progress must be retained.
When developers execute /compact, Codex summarizes the full conversation history into condensed abstract text. The summary replaces raw historical dialogue entries, freeing token capacity to sustain the active workflow. This approach creates minimal disruption to ongoing tasks. Best practice dictates running /compact proactively before hitting hard context limits, instead of waiting for automatic error prompts. Active compression allows engineers to control which information is preserved; passive compression triggered by overflow errors delivers limited controllability.
After executing compression, developers can run /status to verify token consumption reduction. The /status command outputs real-time metrics including current token usage, loaded model identifier, and applied policy rules. A successful compression operation will display an obvious decline in token consumption figures.
/new: Initialize a Fresh Conversation Thread
Applicable Scenario: One task is fully completed, and developers intend to launch an unrelated assignment without legacy context interfering with new requirements.
The /new command creates an independent dialogue thread within the same Codex process. All historical conversation records stop feeding into model reasoning. Importantly, this command does not terminate the Codex process, and existing local files and code artifacts remain intact.
It is critical to distinguish /new from /clear. The table below outlines key differences:
| Command | Erase Dialogue History | Clear Terminal View | Terminate Process |
|---|---|---|---|
| /new | Yes | No | No |
| /clear | Yes | Yes | No |
Many developers mistakenly treat Ctrl+L as a full reset shortcut. In reality, Ctrl+L only refreshes terminal display. The complete context data is retained, and the model still accesses all historical records. This shortcut delivers only visual cleaning, without releasing token resources.
/clear: Full Reset (Purge History + Refresh Terminal Display)
Applicable Scenario: Engineers need to switch to completely new work and require a clean terminal interface simultaneously.
Functionally, /clear equals executing /new plus Ctrl+L. After invocation, all dialogue history vanishes from the model context, and the terminal output panel is cleared. The Codex background process keeps running, while configuration files located at ~/.codex/config.toml and AGENTS.md remain unaffected.
codex resume: Restore Interrupted Conversation Sessions
Applicable Scenario: The terminal was closed unexpectedly, and developers want to resume unfinished work.
Codex persists all session records under the local directory ~/.codex. The command codex resume --last skips the session selector and directly loads the most recent conversation. Users can also run codex resume without parameters to open a selector and manually pick target historical sessions. Inside active dialogue threads, the /resume slash command triggers the same selector panel.
One important constraint requires attention. Resume restores raw historical context. If the recovered session carries extremely long conversation logs, the restored context may immediately approach token limits. Developers should execute /compact right after reloading long sessions to avoid instant overflow errors.
Standard Workflow for Context Overflow Troubleshooting
When encountering the “Codex ran out of room” error, developers should follow tiered handling logic based on task status.
Case A: The active task is incomplete and requires continuation
- Run
/compactto summarize and compress historical dialogue. - Invoke
/statusto confirm token consumption has decreased. - Resume submitting task instructions.
If /compact still fails to free sufficient capacity, developers must initialize a new thread via /new. They need to manually migrate core project background information into the fresh conversation.
Case B: The task concludes, and new work is scheduled
Select either /new or /clear according to terminal display preferences to initialize a new working session.
Case C: Terminal shut down accidentally, task continuation required
Execute codex resume --last to recover the latest session. Check token usage with /status after loading. Run /compact if context size approaches the model threshold.
Maintain Cross-Session Project Memory with AGENTS.md
Frequent reset operations carry a common risk: project background information disappears once dialogue history is cleared. Every new conversation forces developers to repeatedly explain project frameworks, coding specifications and constraints. The AGENTS.md file solves this pain point.
Place an AGENTS.md file within the project root folder. Codex automatically loads its content as persistent initial context on every startup. Engineers can run /init inside Codex to generate a standard template automatically. Recommended content for AGENTS.md includes:
- Brief project overview
- Technical stack and coding constraints
- Mandatory testing rules and commit standards
- Common variable naming conventions and API format specifications
Compared with restoring lengthy historical sessions via resume, AGENTS.md consumes far fewer tokens and delivers stable cross-session background delivery. It avoids repeated context reconstruction after every reset.
Permanent Deletion of Sensitive Conversation Records
For sessions containing confidential source code or private credentials, simple context clearing is insufficient. Developers need to permanently erase complete records.
- CLI Local Sessions: Session files are stored under
~/.codex/sessions. Delete targeted JSON files directly. Once removed,codex resumecannot recover these records. - ChatGPT App Cloud Sessions: Navigate to the Codex conversation list, hover over session titles, and trigger deletion via the sidebar menu.
Post-Reset Configuration Inspection
Commands including /clear and /new do not alter ~/.codex/config.toml settings under normal circumstances. After Codex version upgrades, occasional configuration format incompatibility may emerge. Developers can execute /debug-config to validate provider endpoints, model parameters and environment variable parsing.
Multi-model testing and frequent model switching increase configuration maintenance overhead. When teams manage multiple LLM endpoints, 4sapi serves as an API gateway to standardize request routing and streamline provider configuration management.
Common Troubleshooting Questions
Q1: Will /compact eliminate critical details in dialogue?
A: Compression converts full history into abstract summaries. Minor granular details may be omitted. For complex multi-phase engineering tasks, developers can use /mention to reload key file content and restore missing technical context after compression.
Q2: Do sessions remain accessible after closing the terminal?
A: Saved session files persist locally and can be reloaded with codex resume --last. Background running processes started inside Codex will terminate after terminal shutdown.
Q3: What is Codex’s token context limit?
A: Limits are determined by the underlying LLM. Developers can check supported window sizes via official model documentation, while /status displays real-time consumption and active model information.
Q4: How many tokens does AGENTS.md consume?
A: Every startup loads the complete AGENTS.md content. Longer documents accelerate context overflow. It is recommended to keep the document within 500 words, only retaining core constraints and specifications. Excess content triggers frequent token exhaustion.
Conclusion
All Codex reset operations are essentially context management mechanisms. The four core commands deliver differentiated capabilities: /compact sustains ongoing workflows through compression; /new and /clear switch task threads; codex resume recovers terminated dialogue. Combined with AGENTS.md, developers can retain stable project background information across session restarts, eliminating repeated background explanation.
Mastering this set of workflows effectively addresses context overflow, session stalling and uncleared historical records. Standardized context management reduces redundant communication and prevents accidental data loss during frequent engineering iterations. For teams building long-term coding workflows based on Codex, standardized reset protocols greatly improve development stability and engineering efficiency.




