How to Install and Use OpenAI’s Codex CLI Locally?

Badrinarayan M Last Updated : 29 May, 2025
6 min read

The power of OpenAI’s latest reasoning models is delivered straight to your terminal with the OpenAI Codex CLI, an open-source command-line tool. It serves as a portable coding assistant that can read, edit, and execute code locally on your computer to speed up feature development, fix issues, and help you understand complex code. Your source code never leaves your environment unless you choose to share it, as the CLI operates locally, according to OpenAI. In this article, I will show you how to install and use OpenAI’s Codex CLI locally.

Why Codex CLI?

Codex CLI is designed for developers who are comfortable in the terminal and want ChatGPT-level reasoning combined with the ability to run code, manage files, and iterate, all while keeping version control intact. In short, it’s chat-driven development that understands and executes your code. Some of its key features are:

  • Zero Setup: No configuration required, just bring your OpenAI API key, and you’re ready to go!
  • Minimal Requirements: You’ll need Node.js (v22+) and npm (v10+), but overall, the setup is quick and lightweight.
  • Full Auto Mode: Operates in a directory sandbox with the network disabled, ensuring your data remains private and secure.
  • Multimodal Support: Send in screenshots or diagrams, Codex CLI can interpret and replicate the requirements shown in your images.
  • Open Source: The tool is completely open-source, so you can explore the codebase and even contribute to its development

Please note that Codex CLI is an ongoing experimental project. It may have issues, lack features, or experience disruptive changes because it is not yet stable.

Also Read: How to Access and Use OpenAI Codex?

Approval Modes

Approval modes control the level of access granted to the AI system (Codex CLI). There are three approval modes available, each described below:

Mode What the Agent Can Do When to Use
Suggest (default) Read files. Proposes edits & shell commands, but requires your approval before making changes or executing commands. Safe exploration, code reviews, learning a codebase.
Auto Edit Read and write files automatically. Still asks before running shell commands. Refactoring or repetitive edits where you want to keep an eye on side-effects.
Full Auto Read, write, and execute commands autonomously inside a sandboxed, network-disabled environment scoped to the current directory. Longer tasks like fixing a broken build or prototyping features while you grab a coffee.

Sandboxing Details

macOS 12+

Codex CLI uses Apple Seatbelt (sandbox-exec) to sandbox commands.

  • Most of the filesystem is placed in a read-only jail, with a few exceptions such as $PWD, $TMPDIR, and ~/.codex, which remain writable.
  • By default, outbound network access is completely blocked—even if a child process tries to use curl, it will fail.

Linux

Sandboxing is not enabled by default. OpenAI recommends using Docker for sandboxing.
Codex CLI runs inside a lightweight container image, with your repository mounted in the same location for read/write access. A custom iptables/ipset firewall script blocks all egress except access to the OpenAI API. This ensures repeatable, predictable execution without requiring root access on the host. To enable this, use the run_in_container.sh script to configure the sandbox environment.

New codex-mini-latest

codex-mini-latest is a fine-tuned version of o4-mini specifically for use in Codex CLI. It has a context window of 200k, and can output a max of 100,000 tokens. codex-mini-latest’s is pricing between GPT-4.1 and o4-mini, and below is the image showing the pricing of input, cached input, and output per million tokens. 

New codex-mini-latest
Source: OpenAI

How to Access Codex CLI?

Follow these simple steps to access Codex CLI:

  1. Go to a project that you are working on

    If you would like to experiment with a dummy repository, suggesting you to clone this repository so that we can start testing out codex cli. Github Repository link

    Use the command “git clone https://github.com/Badribn0612/warren_buffet_persona” to clone this repository. You can use a even smaller repository as well. 

  2. Go to the directory where the repository is present

    Use the command “cd <working directory>” to go to that directory.

  3. Install Codex CLI

    Now that we are set to start accessing Codex CLI. Let’s install the same. Use the command:
    npm install -g @openai/codex – this command will install codex cli globally in your system. install Codex cli

  4. Get the API

    OpenAI provides 5$ worth of codex-mini-latest api for Plus users and 50$ worth of credits for Pro users. In order to redeem that use the command. 

    codex — login 

    This will ask you to login or use an API key.Get the API

  5. Now you can Signin with Codex CLI with ChatGPT

    signin to codex cli with chatgpt

  6. Successful Redemption Message

    After successfully Signing in into Codex CLI, you should be able to see a successful redemption message in your terminal as well as your OpenAI dashboard. successful redemption message

  7. Check if you can access Codex CLI in terminal

    Start accessing codex cli:access Codex CLI in terminal

  8. Scan your repository

    After 3 entire minutes of skimming and scanning the repository it gave me a comprehensive response about the repository. Scan your repository

  9. Make changes in the repo

    Let’s now ask Codex CLI to make some changes.

    Prompt:Enhance the chainlit application app.py, this has the persona of warren buffet:
    1. Add search tools
    2. Improve the code quality, 3. Enhance the chainlit applicationMake changes in the repo

Output:

After running the codex cli for around 15+ min, and having gone through changes made by the agent and approving them, the execution stopped. 

Output 1 | Codex CLI
Output 2 | Codex CLI
Output 3 | Codex CLI

Above are some screenshots in between the Codex CLI agent execution. 

Also Read: 12 AI Code Generator Tools in 2025

Inference from Using Codex CLI

Based on my experience using the Codex CLI agent, I found that it takes a cautious and deliberate approach when making changes. It verifies each step, applies modifications only where necessary, and consistently aims to find the best possible solution. However, the process can be noticeably slower compared to making similar changes manually using tools like Cursor or Windsurf.

Of course, this is just my personal experience, your results may vary depending on the domain or tech stack you’re working with. In this case, the codebase involved recently updated libraries, which Codex struggled with. (Note: Codex has a knowledge cutoff of June 1, 2024)

You might also consider experimenting with Claude Code to see how it handles your use case, and decide which tool works best for your workflow.

Also Read: Building a CodeBase Explorer with Google’s Gemini-2.0

Conclusion

Codex CLI is a powerful command-line tool that brings OpenAI’s advanced reasoning capabilities directly to your local development environment. It allows developers to interact with their code, using natural language, enabling tasks like debugging, refactoring, and feature development, all while keeping sensitive data local and secure.

With built-in sandboxing, multimodal support, and minimal setup, Codex CLI is ideal for developers who prefer working in the terminal and want to maintain full control over their codebase. While it remains experimental and may be slower than other tools in certain scenarios, its careful approach to code changes and strong emphasis on privacy make it a compelling choice for integrating intelligent code assistance into your workflow.

Data science Trainee at Analytics Vidhya, specializing in ML, DL and Gen AI. Dedicated to sharing insights through articles on these subjects. Eager to learn and contribute to the field's advancements. Passionate about leveraging data to solve complex problems and drive innovation.

Login to continue reading and enjoy expert-curated content.

Responses From Readers

Clear