Codex Complete Hands-On Guide: 10 Most-Used Commands and Your First Automation Script
๐ Glossary
AI Box (also known as Agent Computer / Agent PC), is a dedicated local hardware device that runs AI Agents. Pre-installed with an AI agent management system, plug-and-play, running 24/7. Users can remotely command AI to work via Discord, Slack, Telegram, WhatsApp, and more.
Abstract: From installation to proficiency, master Codex's 10 most frequently used commands in one sitting and build your first automation script. Zero programming experience required โ just follow along.
If you follow AI coding tools, you've heard of OpenAI's Codex. But it's more than a "code-writing tool" โ it's a coding partner that understands project context, reads files automatically, runs commands, and debugs errors. More importantly, it does automation beyond coding: data queries, email reports, competitor monitoring.
This guide takes you from zero to your first automated script using Codex's 10 most-used commands. No prior coding experience needed.
1. Installation & Setup (3 Minutes)
Codex currently supports macOS and Linux. Open a terminal and run:
curl -fsSL https://update.codex.openai.com/install.sh | sh
Once installed, launch Codex:
codex
The first run prompts a login โ a browser window opens to connect your OpenAI account. After login, verify with a test:
codex -p "output the current time in ISO 8601 format"
If the terminal returns the result immediately, you're good to go.
2. Codex's Two Working Modes
Before diving into commands, understand Codex's two modes:
Interactive Mode: Type codex and hit enter for conversational coding. You describe what you want step by step, and Codex writes code, runs tests, and fixes bugs in real time. Best for new projects, refactoring, and debugging.
One-Shot Mode: codex -p "your request" executes once and returns the result. Best for quick fixes, formatting files, or data lookups โ more of an "AI command-line tool" than an "AI programmer."
Most of the 10 commands below are for interactive mode; a few are more efficient in one-shot mode.

3. The 10 Most-Used Commands
Command 1: /clear โ Reset Context
Codex remembers your entire conversation. When you switch tasks, old context will confuse it. Use /clear to reset memory.
> write a Python web scraper โ
> /clear
> fix the README typos โ
Key rule: always clear context when switching tasks, or it will mix requirements from both.
Command 2: /init โ Initialize Project Memory
Every good project should have an AGENTS.md file. It tells Codex "who I am," "what the project does," and "how you should behave." Type /init and Codex auto-generates a template:
> /init
Edit AGENTS.md with project description, coding standards, and test frameworks. Codex reads this file whenever you open the project, making it far more accurate.
Command 3: /add-dir โ Include a Folder in Context
By default, Codex only reads the current directory. If your code references other folders (e.g., a shared library):
> /add-dir ../shared-lib
Codex will now include that folder's code in all future responses. Essential for large projects.
Command 4: /model โ Switch Models
Codex supports multiple models. To see what's currently in use or switch to a more powerful/cheaper one:
> /model # list available models
> /model gpt-5 # switch to GPT-5
Default models work fine for daily scripting; switch to stronger ones for complex refactoring.
Command 5: /status โ View Global State
See which model is in use, what files are loaded, token count, and memory usage:
> /status
Outputs a concise stats line. Invaluable for debugging โ when behavior seems off, run /status first. It's probably context overload.
Command 6: /compact โ Compress Context
Codex auto-manages context, but long conversations still fill up. /compact compresses conversation history into a summary:
> /compact
Use when you've been working for a while but only need recent information.
Command 7: /doctor โ Self-Check & Repair
Codex depends on environment variables, API keys, and toolchains. When something breaks:
> /doctor
It auto-checks all dependencies and attempts to fix common issues. Ten times faster than manual troubleshooting.
Command 8: /save & /restore โ Save & Restore Sessions
Codex sessions are temporary โ close the terminal and they're gone. But you can save the current session:
> /save fixing-login-bug-context
Next time you open Codex, restore it:
> /restore fixing-login-bug-context
Use with /compact: compact first, then save. When you restore, the context is clean and complete.
Command 9: /run โ Execute Shell Commands
Let Codex run commands and read the output, then decide the next step:
> /run npm test
Output appears directly in the conversation. Codex sees errors and auto-fixes them. Much faster than manually running, screenshotting, and pasting.
Command 10: /review โ Review Current Changes
Pre-commit self-check. Codex compares current changes against the last commit and analyzes potential issues line by line:
> /review
It doesn't auto-fix โ it lists risks for you to confirm. Spend 10 seconds running this before every commit.
4. Your First Automation Script: Morning AI News Digest
Let's tie all the commands together with a real-world scenario.
Goal: Every morning at 8 AM, automatically pull the latest headlines from 3 AI news sources, generate a digest, and push it to a WeChat notification.
Step 1: Create the project
mkdir ai-news-digest
cd ai-news-digest
codex
Step 2: Initialize memory
> /init
Edit the generated AGENTS.md:
# AI News Digest
Daily AI news aggregation and digest delivery
Stack: Python + requests
Delivery: WeCom Webhook
Step 3: Write the script
> Write a Python script news_digest.py that:
1. Fetches the latest 5 headlines from 3 RSS sources
2. Summarizes them into a 200-word digest using OpenAI API
3. Sends the digest via WeCom Webhook
4. Logs results to a file
Use APScheduler, run every day at 8:00 AM
Codex will write the complete script. Test it:
> /run python news_digest.py
Step 4: Review and fix
> /review
Codex will flag issues โ e.g., hardcoded Webhook URL as a security risk, missing error handling. Fix them:
> Move the Webhook URL to an environment variable and add try/except blocks
Step 5: Deploy to Kaihe AIBOX for 7ร24 execution
The script is ready, but you can't keep your computer on all day waiting for 8 AM. This is where a local AI box comes in.
Copy the project folder to your AI box:
scp -r ai-news-digest/ user@aibox-ip:~/scripts/
Launch it on the AI box:
cd ~/scripts/ai-news-digest
nohup python news_digest.py &
Shut your laptop and go to sleep. The next morning, the digest is already in your WeChat. At 8 PM last night, the box ran the script on its own โ you never even turned on the screen.
This is the essence of local Agent + cloud LLM collaboration: Codex used GPT to write the script, but executing the script doesn't require you to be online. The AI box sits on your LAN, on duty 24/7, executing on schedule. Even if you're out for the weekend, it keeps delivering.
5. Daily Power Tips
Review someone else's code: Drop the project into Codex and command > review every file, list all security risks and performance issues. Much faster than manual code review.
Auto-fix bugs: > /run npm test to see failures โ > fix all the above errors โ Codex auto-edits, re-tests, and confirms everything passes.
Write technical docs: > write a README for this project covering installation, usage, and API reference, in both English and Chinese.
Refactor legacy projects: > /add-dir old-project โ > analyze the codebase structure, suggest refactoring, and prioritize by impact.

6. Why Running Locally Beats Cloud-Only
Codex is powerful, but cloud-only usage has three pain points:
First, no network means no Codex. Halfway through a command, the connection drops โ start over.
Second, privacy. Your project code, database connection strings, and key files โ all transmitted to OpenAI servers through the API. Your compliance team won't approve.
Third, no 7ร24 execution. Codex must be manually started โ it won't run scheduled scripts on its own.
With a local AI box, deploy Codex and your working environment on it. The box connects to your LAN; data never leaves. Scheduled tasks run on the box โ even when your laptop is off, it's still executing. Plus, the box runs Hermes and WorkBuddy alongside Codex โ three coding partners, all local, from writing code to scheduling tasks, all in one place.
Final Thoughts
Codex isn't "an AI that replaces programmers" โ it's "a partner that multiplies programmer productivity by ten." Once you master these 10 commands, you'll find yourself increasingly delegating repetitive work to it: fix bugs, write docs, run tests, generate reports. You confirm; it delivers.
Better yet, pair this partner with an AI box, and it keeps working even when you're away. Morning news digests, evening data analysis, late-night cleanup โ you're offline, but it's still running.
Further Reading
- Codex vs Claude Code vs WorkBuddy: 2026's Best AI Coding Partner
- AI Coding Tools Roundup: Codex, Cursor, Copilot Compared
- Hermes Desktop App: No More Command Line โ AI Agent in One App
- Kaihe AIBOX Store โ Full Line of AI Agent Computers
Learn more, search for "Kaihe AIBOX" | Email: [email protected] #KaiheAIBOX #AIAgent #OpenSource #Codex #Automation #AICoding #AgentComputer
Kaihe AIBOX ยท Your Private AI Assistant Working 7ร24 | AI Agent