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.
- Navigate to your project root in the terminal.
- Start a Codex CLI session and give it the project context: language version, build command, test command, and the current task.
- Ask it to read the relevant files before suggesting changes.
- Review each proposed change in the diff output. Approve changes you are satisfied with; reject or modify those that do not fit.
- Run your test suite after each set of changes to confirm nothing broke.
- 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.
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 accountFree for one person · No credit card · Works with Claude, ChatGPT, Cursor and more
How to do this with fenbs
- Create a free account and add your project.
- 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.
- Add the current tasks to the board with their status and any relevant constraints.
- Connect Codex CLI to fenbs via MCP from Integrations. Ask it to read the project context at the start of every session.
- Before ending a session, ask the agent to save progress: which tasks it completed, what it changed, and what remains for the next session.