10 Minutes to Codex

Install Codex CLI, let it inspect a real project, make a small change, review the diff, and learn the basic coding-agent workflow.

· 更新于 2026年6月5日

中文版本

Codex is different from a normal chat assistant.

It can read your repository, edit files, run commands, inspect errors, and then show you the result.

So learning Codex is not mainly about memorizing prompt tricks.

The important parts are:

  1. Describe the task clearly.
  2. Keep the edit scope small.
  3. Review what changed before you trust it.

This guide only covers the first real pass.

1. Install

One official setup path for the CLI is npm:

npm i -g @openai/codex

Run it:

codex

The first time you run Codex, it prompts you to sign in. You can authenticate with an OpenAI account that includes Codex access, or follow the API key flow.

Upgrade later with:

npm i -g @openai/codex@latest

On Windows, Codex can run natively in PowerShell. If your project depends on a Linux-native toolchain, WSL2 may still be the better environment.

2. Open a Real Project

Do not start in an empty folder.

Use a small project you already understand, ideally one with a build or test command:

cd ~/projects/my-app
codex

Do not ask it to edit files immediately.

Start with:

Read this project first. Do not edit files. Tell me the entry point, main folders, dev command, build command, and test command.

This is a good first request because you can observe how Codex reads files and summarizes the project without creating a large diff.

3. Give It a Small Task

Once it understands the project, give it a narrow task:

Fix the button text overflow on the homepage. Only change files related to that button. After editing, tell me which files changed. Do not commit.

This prompt has useful boundaries:

  1. The bug is specific.
  2. The edit scope is limited.
  3. It should not commit before review.

For tests:

Add 3 tests for formatPrice in src/lib/price.ts. Cover normal amount, zero, and negative values. Do not change the implementation first.

Coding agents struggle when the task boundary is vague.

Not because they cannot do the work, but because a small request can easily expand into a much larger rewrite.

4. Review the Diff

Build this habit early:

After Codex edits, review the diff.

Inside the interactive session:

/diff

Or in your terminal:

git diff

Check three things:

  1. Did it touch unrelated files?
  2. Did it make a simple problem too complex?
  3. Did it run the right verification?

If you dislike the result, say so directly:

This edit is too broad. Keep only the button style change and revert the unrelated files.

Or:

Stop writing new code. Explain why these two files need to change.

This is not being difficult.

This is your job as the project owner.

5. Useful Slash Commands

These are enough for the first week:

CommandPurpose
/diffShow current changes
/statusShow session and environment status
/permissionsAdjust what Codex can do without asking
/modelSwitch model
/clearClear the conversation and start fresh
/compactSummarize a long conversation to free context
/mentionPoint Codex at a file or folder
/initGenerate an AGENTS.md file for the project
/exitExit

If you forget the commands, type / and read the menu.

6. Run One-Off Tasks

Sometimes you do not need the full interactive session.

Ask one question directly:

codex "Explain the main modules of this project"

Set the working directory:

codex --cd ~/projects/my-app "Find why pnpm build fails. Do not edit code yet."

Attach an image:

codex --image screenshot.png "Compare this screenshot with the current page and find layout issues"

These are good for quick analysis.

For real edits, I prefer interactive mode because I can review the plan and diff as it works.

7. Start With Conservative Permissions

Codex can run commands and edit files, so permissions matter.

At the beginning, stay conservative:

codex --ask-for-approval on-request

If you only want it to inspect the project:

codex --sandbox read-only

Only use wide-open permissions in an isolated environment.

The stronger the agent gets, the more important it is to know when it is touching your real files.

8. A Beginner Prompt Template

You can start with this:

Read this project first. Do not edit files yet.

The problem I want to solve:
[describe the problem]

Constraints:
- Only change [file or folder]
- Do not touch [unrelated module]
- After editing, summarize the diff
- Do not commit

Verification:
- Prefer running [test or build command]
- If the command cannot run, explain why

This is much better than "optimize this project".

Clear boundaries make Codex feel like a useful collaborator instead of a roaming autocomplete engine.

9. When Codex Is a Good Fit

TaskFit
Understanding an unfamiliar codebaseGreat
Fixing a clear bugGreat
Writing testsGreat
Small refactorsGood
Large architecture migrationsBe careful
Unclear product directionThink first

Codex works best when you can already describe the problem.

Start with build errors, UI bugs, missing tests, confusing functions, and small refactors.

Then move toward larger tasks after you understand its rhythm.

Reference

  1. Codex CLI documentation
  2. Codex CLI Features
  3. Codex CLI Command Line Options
  4. Codex CLI Slash Commands
  5. Codex Web

Feedback

给作者反馈建议