OpenAI's Codex CLI Now Runs Locally on Your Machine. Here's Why That Matters.
OpenAI's Codex CLI, an open-source coding agent, can now run locally on your own hardware using Ollama, eliminating cloud API costs and keeping your code off external servers. The tool reads your codebase, edits files, and executes commands directly in your terminal. By default it connects to OpenAI's cloud models, but a single flag redirects it to a local instance, giving developers complete control over their data and inference costs.
Why Are Developers Running Codex Locally Instead of in the Cloud?
Three practical reasons drive the shift toward local execution. First, privacy matters when you're building software for partners across multiple industries; some code simply cannot leave your network. Second, cloud API calls accumulate quickly, especially during experimentation and iteration. Third, running a model locally strips away the abstraction layer and forces you to understand what these systems actually need to function effectively.
The timing is significant because it comes as the broader AI coding ecosystem faces scrutiny over token usage and data handling. Earlier this month, a Reddit post with over 300 upvotes claimed that Codex's auto-review feature was silently draining usage quotas. While the community debate revealed the claim was more nuanced than initially framed, it underscored developer concerns about hidden costs and data transparency.
What Hardware Do You Actually Need to Run Codex Locally?
The barrier to entry is surprisingly low. Codex works with OpenAI's open-weight gpt-oss models, which come in two sizes. The 20-billion-parameter model requires about 16 gigabytes of RAM and represents the practical choice for most developers on a laptop or desktop. The 120-billion-parameter model demands an 80-gigabyte GPU, which is overkill for typical development work.
If you have a machine with a decent graphics processing unit (GPU) or an Apple Silicon Mac, performance improves noticeably. But the 20-billion-parameter model will run on a standard CPU, albeit more slowly. The model uses OpenAI's MXFP4 quantization format, which Ollama supports natively, making it possible to fit a 21-billion-parameter model into 16 gigabytes of memory.
Steps to Set Up Codex CLI with Ollama
- Install Prerequisites: You'll need Node.js for installing Codex CLI via npm, Ollama installed and running on your system, a machine with at least 16 gigabytes of RAM for the 20-billion-parameter model, and patience for the initial model download.
- Download Ollama: Grab Ollama from ollama.com/download, which is available on macOS, Linux, and Windows. Once installed, start the Ollama service; on macOS it runs as a menu bar app, while on Linux you can start it from the command line.
- Pull the Model: Download the gpt-oss:20b model, which will take a few minutes depending on your connection speed. This model uses OpenAI's MXFP4 quantization format to fit into 16 gigabytes of memory.
- Launch Codex with Local Mode: Navigate to a project directory and run Codex with the --oss flag to use your local Ollama instance instead of OpenAI's cloud. Codex will start its terminal interface and connect to the Ollama server running on localhost:11434.
- Configure Profiles for Convenience: Set up a configuration profile so you don't have to pass flags every time. You can create multiple profiles for different models or providers, which is useful if you want to switch between local and cloud models depending on the task.
One developer explained the appeal: "I like knowing what's happening on my machine. When I use a tool, I want to understand what it's doing, where my code is going, and what I'm paying for," noted Chad Michel, a software engineer at Don't Panic Labs.
What Are the Real Trade-Offs Between Local and Cloud?
The gpt-oss:20b model running locally is noticeably slower than cloud-based alternatives. For quick questions and small edits, it works well. For complex multi-file refactoring or large codebase analysis, you'll feel the latency difference. However, for the work most developers use it for most often, like explaining unfamiliar code, writing quick utility functions, and generating test scaffolding, the local model does the job without incurring token costs or raising data privacy concerns.
One important consideration: Codex recommends a context window of at least 32,000 tokens, ideally 64,000 tokens. Make sure your Ollama model configuration supports that capability. The context window determines how much code and conversation history the model can process at once.
Ollama supports a wide range of models beyond gpt-oss:20b. You can point Codex at other coding-focused models available in Ollama's library, like DeepSeek Coder or Qwen, by passing the model name with the -m flag. Experimenting with different models on different tasks is a good way to build intuition about what these systems are actually good at.
Is Local Codex Actually Free to Use?
Yes, with important caveats. The gpt-oss:20b model is released under an Apache 2.0 license, so you can use it without restrictions. The Codex CLI itself is open source. You pay only in electricity and hardware, not in API fees. However, the setup does require upfront investment in a machine with sufficient RAM or GPU capacity, and the slower inference speed means tasks take longer to complete.
The broader context matters here. GitHub experienced a major outage earlier this month that lasted six hours and 42 minutes, affecting pull requests, issues, the API, and Copilot itself. This was the seventh significant incident on GitHub's status page in just 15 days. That reliability crisis has pushed some developers and organizations to explore alternatives and local-first workflows.
For developers who prioritize understanding their tools and maintaining control over proprietary code, running Codex locally is worth the 10-minute setup time. You'll gain insight into how these models behave under real constraints, and you'll have a useful coding agent that works even when you're offline or when cloud services experience disruptions.