Comprehensive Guide to Codex Commands: 10 Essential Commands for Efficient Project Refactoring
This is a sincere tutorial for complete beginners who have never used Codex. I will first explain the core functionalities of the commands, then break down their application scenarios in simple terms, and finally provide copyable examples. By the end of this article, you will be able to get started right away.
Conclusion: Codex is not a chatbot; it’s more like an AI programming colleague sitting in your project directory. It can help you read code, modify files, run commands, and conduct reviews. But the premise is: you need to learn how to control it. Otherwise, while it is very smart, it can also be “too smart.”
1. What are Codex Commands?
In Codex, inputs are divided into two types:
- Regular Prompts (Tasks): For example, “Help me refactor this function” or “Fix the login bug.”
- Slash Commands (Management Tools): Commands that start with a /, such as /plan or /diff.
In one sentence:
- Regular Prompt = What you want Codex to do.
- Slash Command = How you manage Codex as a tool.
2. Three Essential Rules to Remember
- Commands must be at the beginning: Codex only triggers a command if it recognizes the first character as a /.
- Forgot a command? Just type /: Typing a slash will automatically bring up the current list of available commands. The local list is the most accurate because it updates dynamically based on your version.
- Do not copy Claude Code: Stop looking for CLAUDE.md; Codex recognizes AGENTS.md.
3. 10 Core Commands Every Beginner Should Know
Mastering these 10 commands can solve 90% of your daily development needs.
1. /init — Onboarding
- Scenario: Codex is new to the project and unfamiliar with everything.
- In simple terms: Send the AI an “onboarding manual.”
- Example: Input /init to generate AGENTS.md, then manually add: “This project uses pnpm, do not modify the dist directory.”
2. /status — Check Status
- Scenario: Suspect the model has switched incorrectly or unsure of your current context.
- In simple terms: Check who the AI is, where it is, and what it can do.
3. /model — Switch Engine
- Strategy: Use a fast model for small tasks (like modifying text or debugging code); for larger tasks (like major refactoring or fixing complex bugs), don’t skimp on using a powerful model.
4. /permissions — Manage Permissions
- Scenario: Concerned about the AI making uncontrolled changes to the code.
- In simple terms: Decide whether to let it “view only” or “modify with reporting.”
5. /plan — Strategize Before Action
- Scenario: The task is large, and the risks are unclear.
- In simple terms: “Don’t rush into action; first, give me a plan.”
- Example: /plan help me analyze the refactoring plan, don’t modify the code yet.
6. /mention — Targeted Action
- Scenario: Global scanning is too slow, and you only want to focus on specific files.
- In simple terms: “Call out” to make the AI only look at these specific files.
7. /diff — What Changed?
- Scenario: The AI claims it has fixed something, but you’re not sure.
- In simple terms: Don’t just listen to its summary; check the actual code differences.
8. /review — Cross-Check
- Scenario: Preparing to submit code.
- In simple terms: Let the AI switch to a “critical reviewer” perspective to find bugs and vulnerabilities.
9. /compact — Compress Dialogue
- Scenario: Conversations have gone on too long, and the AI is starting to lag.
- In simple terms: A weight-loss program. Compress the history into a summary to save costs and speed up.
10. /resume — Return to Work
- Scenario: Tasks from yesterday were not completed and need to continue today.
- In simple terms: Retrieve the archive and pick up where you left off yesterday.
4. Common Confusion: /side vs /fork
These are two concepts that beginners often confuse:
- /side (Temporary Side Chat): Like turning to a colleague and asking, “Can you look up this syntax for me?” After asking, you move on without interrupting the main line.
- /fork (Create a Branch): Like a Git branch. You want to try a completely different implementation route but don’t want to delete the current solution.
5. The Golden Workflow for First-Time Users
- Enter directory: cd my-project
- Set rules: /init (complete AGENTS.md)
- Check status: /status
- Research first: “Don’t modify the code yet; read the project structure.”
- Create a plan: /plan fix a bug.
- Perform the operation: After confirming the plan, let it execute.
- Verify results: /diff + /review.
6. Final Usage Mnemonic
First /init to understand the project, then /status to confirm the status. For large tasks, first /plan; for key files, use /mention. After changes, always /diff; run /review before submission. If the conversation is long, use /compact; return tomorrow with /resume. For quick questions, use /side; for trying new routes, use /fork.
In conclusion: Those who know how to use Codex do not completely hand over the steering wheel to AI; instead, they let AI sit in the passenger seat. It helps you check maps, fix cars, and monitor traffic; you are responsible for decision-making, braking, and final acceptance.
Comments
Discussion is powered by Giscus (GitHub Discussions). Add
repo,repoID,category, andcategoryIDunder[params.comments.giscus]inhugo.tomlusing the values from the Giscus setup tool.