What you will learn
This is a Codex CLI installation guide.
You will learn:
- What Codex CLI is.
- How to check Node.js and npm.
- How to install Codex CLI.
- How to run
codex. - How beginners should understand approval modes.
- How to handle command not found, sign-in, and permission problems.
If you do not understand local AI coding agents yet, read the local AI coding agents guide first.
What is Codex CLI?
Codex CLI is OpenAI’s terminal-based AI coding tool.
CLI stands for command-line interface.
In plain language, it is a command-line tool.
You enter a project folder in the terminal, type codex, and Codex can inspect the current project, explain code, suggest changes, or directly edit files after you approve.
It is useful for Web4 learners who want to:
- Understand a website project.
- Add a new page.
- Edit Markdown articles.
- Investigate build errors.
- Build a simple personal website.
- Explain which files changed in Git.
It is an AI coding tool, not a magic button.
You still need to give it clear goals and review what it changed.
Check Node.js and npm before installation
Open your terminal and type:
node -v
If you see a version number, Node.js exists.
Then type:
npm -v
If you see a version number here too, npm exists.
npm is a common way to install Codex CLI.
If you see command not found, install Node.js first. Beginners should use the LTS version from the Node.js website.
Install Codex CLI
The official GitHub repository gives this npm installation command:
npm i -g @openai/codex
i is short for install.
-g means the package is installed as a global command.
After installation, check the version:
codex --version
If you see a version number, installation worked.
Run codex
Enter your project folder.
For example:
cd my-first-website
Then run:
codex
The first time you run it, it will prompt you to sign in or configure access.
Follow the terminal prompts.
If it opens a browser, complete sign-in in the browser.
If it asks for an API key, follow the OpenAI official setup path for your project.
Do not send your API key to anyone, and do not commit it to a public Git repository.
How beginners should understand approval modes
Permissions are an important part of Codex CLI.
You can think of them this way: you decide how much the AI is allowed to do.
The exact interface wording may change across versions, but beginners can understand the choices in three broad groups.
Read-only: let it inspect code only
Read-only means exactly that.
Codex can inspect the project, explain code, and give suggestions.
It should not edit files, and it should not run commands that change things for you.
This is a good mode when opening a project for the first time.
You can ask:
Please read this project and tell me what framework it uses, where the page directory is, and where the article directory is. Do not modify any files.
Auto: allow common development work
Auto means something like “let it help me work, but pay attention to important actions.”
It is useful for small changes.
For example:
Please add a simple About page and run a build check.
When beginners use Auto, they should build one habit:
Check git status after every change.
Full Access: give it broader permissions
Full Access gives Codex more power.
It may edit files, run commands, and take more aggressive actions automatically.
Beginners should not start here.
Only consider it when these are true:
- The project is already managed with Git.
- You know how to inspect changes.
- You know how to undo changes you do not want.
- The task does not involve private files, secrets, or production data.
Put simply: learn how to brake before you drive fast.
Beginners should use it inside a Git project
Git records file changes.
You do not need to master Git on day one.
But these two commands are very useful:
git status
See which files changed.
git diff
See exactly what changed.
After Codex CLI edits files, look at these results before deciding what to do next.
If you do not have a Git project yet, create a new practice folder first. Do not experiment inside an important documents folder.
What to ask Codex first
After opening a project, ask:
Please read this project first. Tell me its tech stack, page routes, and content file locations. Do not modify any files yet.
Then give it a very small task:
Please add a simple personal website demo page with a personal introduction, skills, projects, and contact information. Keep the existing site style.
If you want a full practice project, continue with Build a Personal Website with AI.
Common problems
codex command not found
If you see codex: command not found, first confirm whether installation worked:
npm list -g @openai/codex
If it was not installed globally, run:
npm i -g @openai/codex
If it is installed but the command is missing, your npm global command directory may not be in PATH.
Windows installation problems
Windows users should first confirm which terminal environment they used for installation.
PowerShell, Windows Terminal, Git Bash, and WSL are not exactly the same environment.
Run codex in the same environment where you installed it.
If you plan to learn web development long-term, WSL is worth understanding.
API key or sign-in problems
The first time you run codex, follow the terminal prompts to sign in or configure access.
If you use an API key, remember:
- Do not put the key in a public article.
- Do not commit the key to GitHub.
- Do not send the key to an AI chat window.
- You can store it in a local environment file such as
.env, but make sure.envwill not be committed.
The exact sign-in method depends on the official OpenAI docs and your account permissions.
npm permission problems
If installation reports EACCES or permission denied, do not immediately add sudo.
First follow the npm official docs for global installation permissions, or reinstall Node.js with a Node version manager.
Node version problems
Check:
node -v
If the version is too old, install a newer LTS version from the Node.js website.
After installation, reopen the terminal and run the install command again.
Next step
If you want to compare Claude Code, read the Claude Code Installation Guide.
If Codex CLI is already installed, go straight to the practice project: Build a Personal Website with Claude Code or Codex CLI.
Before starting, you can also return to the local AI coding agents guide for the full learning path.
Further reading
- Codex CLI documentation - OpenAI
- Codex CLI features - OpenAI
- OpenAI Codex CLI GitHub repository - OpenAI
- Node.js downloads - Node.js
- Resolving EACCES permissions errors when installing packages globally - npm Docs
FAQ
How is Codex CLI different from ChatGPT in the browser?
ChatGPT in the browser feels more like a chat window. Codex CLI works in the terminal, can read the current project, and can edit files or run commands after you approve.
Which approval mode should Codex CLI beginners use?
Start with a read-only or conservative mode and let it explain the project first. After you are comfortable, allow it to edit files. Full Access is only appropriate when you understand the risks and the project is protected by Git.
Does Codex CLI always require an API key?
Codex CLI supports multiple sign-in and usage paths, depending on the official OpenAI docs and your current account permissions. During the first run, follow the terminal prompts to sign in or configure access.