{"slug": "working-with-openais-codex-cli", "title": "Working with OpenAI’s Codex CLI", "summary": "A developer documented a detailed setup process for OpenAI's Codex CLI, a terminal-based tool for generating, refactoring, and documenting code with AI models. The guide covers configuring API keys for providers including OpenAI, Gemini, OpenRouter, Ollama, Mistral, DeepSeek, xAI, and Groq, creating a persistent config at ~/.codex/config.json, and adding a global ~/.codex/instructions.md for context passed to every command. The developer noted the CLI does not yet respect .gitignore or support standard ignore rules, though open pull requests aim to add both.", "body_md": "OpenAI’s Codex CLI is a developer command-line interface that lets you leverage AI models to generate, refactor, and document code directly from your terminal.\n\nThis video provides a full demo and explanation, and I highly recommend watching it. It shows just how powerful the `codex` CLI is, they even create an SPA version of Mac’s Photo Booth app using an uploaded screenshot and short description. It’s pretty amazing.To start using it in your day-to-day workflow as a developer you’ll need to install and configure it. The guidelines in the `readme.md` aren’t all that great, so I’m documenting the steps I’ve taken here along with many undocumented aspects I learned along the way.\n\nTo work with the Codex CLI we need to start with a clean setup. Here’s the process as I see it, which is more detailed than the official documentation but includes some critical (in my mind required) steps like setting up persistent configuration, adding default context instructions for all commands, and most important: adding ignore rules for input.\n\nFirst you’ll need to set up your API keys for the AI APIs you’ll be working with. As of today there is support for:\n\n`openai (default)`\n`openrouter`\n`gemini`\n`ollama`\n`mistral`\n`deepseek`\n`xai`\n`groq`\nOther providers that are compatible with the OpenAI API will also work, so there may be other options. I use Gemini and OpenAI, which is pretty common so if you’re planning to use these you can setup API keys at the following URLs:\n\nOnce you have those you’ll need to add them to your command line profile so that they’re available to node’s `process.env` globals. I use [Fish CLI](https://fishshell.com), so for me this looks like this:\n\n```\n# Codex CLI\nset -x OPENAI_API_KEY {YOUR API KEY}\nset -x GEMINI_API_KEY {YOUR API KEY}\n```\n\nIt’s a good idea to verify that these are configured and available, so after you save them reload your CLI profile and then verify they’re good to go with the following test commands:\n\n```\necho $OPENAI_API_KEY \nnode -e 'console.log(process.env.OPENAI_API_KEY)'\necho $GEMINI_API_KEY \nnode -e 'console.log(process.env.GEMINI_API_KEY)'\n```\n\nIf you see the correct values printed after running each of these then you’re good to go.\n\nAfter that we’ll create a config file at `~/.codex/config.json` and adjust the settings for however you want to use it. Reference the official [configuration guide](//~/.codex/config.json) provided in the `openai/codex` GitHub repository for all the options. I use either OpenAI’s `gpt-4.1` or Gemini’s `gemini-exp-1206` (as of May 7th, 2025). I’m sure this will change in the future.\n\nHere’s what my config looks like:\n\n```\n{\n  \"model\": \"gpt-4.1\",\n  \"provider\": \"openai\",\n  \"reasoningEffort\": \"medium\",\n  \"providers\": {\n    \"openai\": {\n      \"name\": \"OpenAI\",\n      \"baseURL\": \"https://api.openai.com/v1\",\n      \"envKey\": \"OPENAI_API_KEY\"\n    },\n    \"gemini\": {\n      \"name\": \"Gemini\",\n      \"baseURL\": \"https://generativelanguage.googleapis.com/v1beta/openai\",\n      \"envKey\": \"GEMINI_API_KEY\"\n    }\n  },\n  \"history\": {\n    \"maxSize\": 10000,\n    \"saveHistory\": true,\n    \"sensitivePatterns\": []\n  }\n}\n```\n\nIf you want to use Gemini then the top of the config would look like this:\n\n```\n{\n  \"provider\": \"gemini\",\n  \"model\": \"gemini-exp-1206\",\n  ...\n}\n```\n\nThese models will probably change and there will be better ones in the future, so be sure to reference the latest Gemini and OpenAI models and choose the best ones for your specific use case, budget, and expected outcomes.\n\nRight now there isn’t a standard way to define ignore rules for the codex CLI, and it doesn’t respect the `.gitignore` either. There are open pull-requests that add support for both of these features, hopefully in the near future we’ll see those merged into `main`.\n\nAdd a `~/.codex/instructions.md` file to provide the CLI with a global context that is used for all commands you run. This will be passed to every command you run and can include things like:\n\n```\n- use comments minimally, especially when inline \n- adhere to any coding style guide configurations found\n- inline comments have an empty line above, and are on their own line\n```\n\nIt’s a new tool and I’m actively working with it. After a few weeks I plan to either update this portion of the article or write a new one with details on quirks and tips about how effective it is, and what will make using it easier.\n\nOne of the most important aspects of the new CLI is the coding model, which has 3 different configurations:\n\n`--suggest`\nGenerates code suggestions based on your input, but does not modify files automatically. You manually review and apply the suggestions you want.\n\n```\nopenai codex --suggest\n```\n\n`--auto-edit`\nAutomatically applies code changes to files based on your prompts, but asks for confirmation before each change.\n\n```\nopenai codex --auto-edit\n```\n\n`--full-auto`\nFully automates code changes without asking for confirmation, directly applying updates based on your instructions.\n\n```\nopenai codex --full-auto\n```\n\nThe big question: how much will using it cost you? Here’s a simple breakdown of what it costs to use each model:\n\n| Model | Input Cost per 1M Tokens | Output Cost per 1M Tokens | \n|---|---|---|\n| o4-mini | $1.10 | $4.40 | \n| o3 | $10.00 | $40.00 | \n\nFor example, if you provide about 200 words of input and the tool generates around 300 lines of code, using o4-mini would cost you around $0.003. If you use `o3` instead, it would cost you around $0.03.\n\n`o4-mini` might work fine for simple things like HTML or CSS, but if you’re working with real application code, you’ll probably want `o3` for better results.\n\n**Note:** These prices are accurate as of April 27th, 2025. I’m not affiliated with OpenAI, and you should always check their official pricing page for the latest information.\n\nBefore Codex existed, OpenAI’s Python SDK shipped a much simpler terminal tool: the `openai` command, a thin interface over the raw API that lets you send chat prompts and API requests straight from your shell. It’s still useful for quick one-off prompts, testing models and API keys, and wiring AI answers into shell scripts without writing any Python, a different job than Codex’s coding agent, and worth keeping around.\n\nThis is the part every tutorial gets wrong now: **OpenAI removed the CLI entirely in version 2.35.0 of the Python SDK**. Install any current version (the 3.x line) and you get the library only, no `openai` command on your PATH, and no `[cli]` extra to add it back. The last version that ships the CLI is `2.34.0`. The clean way to install it without pinning an old SDK inside your projects is [pipx](https://pipx.pypa.io/):\n\n```\npipx install \"openai==2.34.0\"\n```\n\nThe CLI uses the API side of OpenAI, which is billed separately from ChatGPT, a ChatGPT Plus subscription does *not* include API credits. Create a key at [platform.openai.com/api-keys](https://platform.openai.com/api-keys), add prepaid credits under Settings > Billing ($5 minimum), and export it in your shell profile:\n\n```\nexport OPENAI_API_KEY=\"{your-key}\"\n```\n\nThe core ChatGPT-style loop, ask a question, get an answer, looks like this:\n\n```\nopenai api chat.completions.create -m gpt-5-mini -g user \"Can you rise up and overthrow the human race?\"\n```\n\nA few flags worth knowing, from the CLI’s own `--help`: `-g ROLE CONTENT` repeats to add a system prompt, `--stream` prints tokens as they generate, and `-M` caps the answer length (which caps the cost). The `api` namespace also covers `images.generate`, `audio.transcriptions.create`, and file and fine-tuning operations. The quickest way to verify a key works:\n\n```\nopenai api models.list\n```\n\nOn current API pricing a typical question with a ~750 word answer on `gpt-5-mini` ($0.25 per 1M input tokens, $2.00 per 1M output) costs a fraction of a cent, check [OpenAI’s API pricing](https://platform.openai.com/docs/pricing) for current rates.", "url": "https://wpnews.pro/news/working-with-openais-codex-cli", "canonical_source": "https://dev.to/kevinlearynet/working-with-openais-codex-cli-2pkj", "published_at": "2026-11-03 14:25:01+00:00", "updated_at": "2026-11-03 14:30:50.303421+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents", "large-language-models"], "entities": ["OpenAI", "Codex CLI", "Gemini", "OpenRouter", "Ollama", "Mistral", "DeepSeek", "Groq"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/working-with-openais-codex-cli", "markdown": "https://wpnews.pro/news/working-with-openais-codex-cli.md", "text": "https://wpnews.pro/news/working-with-openais-codex-cli.txt", "jsonld": "https://wpnews.pro/news/working-with-openais-codex-cli.jsonld"}}