How to Use ChatGPT From the CLI

OpenAI's Codex CLI is the official command-line coding agent. Here is how it differs from third-party ChatGPT CLI wrappers, how to set it up for a development workflow, and how to keep project rules in fenbs.

Updated 5 min read

OpenAI's Codex CLI is the official command-line coding agent from OpenAI. It reads your project files, executes commands, and edits code based on plain-language instructions you give it in the terminal. Third-party CLI clients that call the ChatGPT API also exist, but they are not from OpenAI and work differently: they send messages to the chat completions API rather than acting as a coding agent with file access.

Knowing which tool you are using matters for setting up the right workflow. Codex CLI can read your repository, run tests, and apply changes. A plain API wrapper sends your message and returns a completion. The ChatGPT Codex guide covers Codex CLI in depth. Tools like fenbs keep your project rules and progress in one place that a CLI coding agent can read at session start, so the context is available without pasting a project summary each time.

Codex CLI vs third-party ChatGPT CLI wrappers

Codex CLI is a coding agent: it starts in a directory, reads files, executes shell commands in a sandbox, and can open, edit, and create files. It is designed for software development tasks: writing code, running tests, debugging, and summarizing changes. It requires an OpenAI API key.

Third-party CLI wrappers such as sgpt and similar tools are thin clients for the OpenAI chat completions API. They let you ask ChatGPT a question from your terminal and get a response in the terminal, but they do not have file access or the ability to run commands in your project unless you build that integration yourself. They are useful for quick questions; they are not the same as a coding agent.

The choice comes down to the task. If you need an agent that can read your code, make changes, and run tests, use Codex CLI. If you need to ask a quick question without opening a browser, a lightweight API wrapper may suffice.

Setting up Codex CLI

Install Codex CLI via npm: npm install -g @openai/codex (check the current package name on the OpenAI GitHub repository, as it can change). You will need an OpenAI API key set as the OPENAI_API_KEY environment variable.

Run Codex CLI from the root of your project directory so it can read your files. Start a session with a brief description of the project and the current task. By default, Codex CLI runs in a sandbox and asks for confirmation before executing commands or applying changes. Review each proposed change before approving it.

On the first session, tell the agent the key constraints: the language and version, the build and test commands, which directories to avoid, and any patterns the codebase uses. This context shapes the quality of its suggestions for that session. Without it, the agent makes reasonable guesses that may not match your project.

A basic development workflow with Codex CLI

A typical Codex CLI session for a development task follows this pattern.

  1. Navigate to your project root in the terminal.
  2. Start a Codex CLI session and give it the project context: language version, build command, test command, and the current task.
  3. Ask it to read the relevant files before suggesting changes.
  4. Review each proposed change in the diff output. Approve changes you are satisfied with; reject or modify those that do not fit.
  5. Run your test suite after each set of changes to confirm nothing broke.
  6. Save a summary of what was completed and what remains before ending the session.

The review step is not optional. Codex CLI can make plausible-looking changes that are logically incorrect, introduce unnecessary dependencies, or modify files you did not intend to touch. Checking the diff before approving each change is the main way to catch these problems.

Keeping project rules available across sessions

Each Codex CLI session starts fresh without memory of previous sessions. Project constraints you described in Monday's session must be re-described on Tuesday unless they are stored somewhere the agent can read. Two approaches work: a short context file in your project root, or a connected project tool the agent queries at startup.

A context file is the simpler approach: a short markdown file with the language version, build commands, key conventions, and current task. Include it in your repository and ask Codex CLI to read it at the start of each session. Update it when the project constraints change.

A connected tool is more maintainable for a project that evolves: decisions update in one place and are available to every session without anyone remembering to update the file. The chatgpt-alternatives guide covers other AI coding tools that also benefit from this pattern.

How fenbs helps

Keep project rules and progress available to every CLI session

Connect Codex CLI to fenbs via MCP from Integrations. At the start of each session, the agent reads the current project context: Rules first, then Where we left off, then the current tasks. Before ending the session, ask it to save progress so the next session starts from the current state rather than from zero.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

How to do this with fenbs

  1. Create a free account and add your project.
  2. Write the key constraints as Decisions and rules: language version, build command, test command, which directories the agent should avoid, any patterns the project follows.
  3. Add the current tasks to the board with their status and any relevant constraints.
  4. Connect Codex CLI to fenbs via MCP from Integrations. Ask it to read the project context at the start of every session.
  5. Before ending a session, ask the agent to save progress: which tasks it completed, what it changed, and what remains for the next session.

Questions people ask.

What is the difference between Codex CLI and the ChatGPT web interface?

ChatGPT in a browser is a conversation interface: you type a message, it responds. Codex CLI is a coding agent: it runs in your terminal, reads your project files, executes commands in a sandbox, and applies changes. Codex CLI is designed for software development tasks that require interacting with a real codebase; the web interface is better for explanations, drafts, and questions.

Do I need a ChatGPT subscription to use Codex CLI?

Codex CLI uses the OpenAI API directly, which requires an API key and incurs usage costs based on the models and token counts involved. This is separate from a ChatGPT Plus or Teams subscription. Check OpenAI's pricing page for current costs.

Is it safe to let Codex CLI execute commands in my project?

Codex CLI runs commands in a sandbox and asks for confirmation before applying changes by default. Review every proposed change and command before approving. Run it from a clean branch so you can easily revert if a session produces unwanted changes. Do not run it with elevated permissions or in a directory containing secrets.

Can Codex CLI work with any programming language?

Codex CLI can read files in any language and suggest changes. The quality of its suggestions is better for languages with more training data, which includes most mainstream languages. For specialized domains or unusual patterns, give it explicit context about what is conventional in your codebase.

How do I point Codex CLI to a specific file or task?

Start the session with a message that names the file and describes the task. For example: "Look at src/auth/login.js. The login function is not handling the case where the token is expired. Suggest a fix." The more specific your instruction, the more targeted the suggestion.

More in Agent harness (for developers)

All Agent harness (for developers) articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.