How to Use Open Codex CLI with Google Gemini 2.5 Pro: Streamline Terminal AI Coding Workflows

Learn how to integrate Open Codex CLI with Google Gemini 2.5 Pro for advanced AI-powered coding in your terminal. Step-by-step guide for developers to boost productivity, code quality, and workflow security.

Emmanuel Mumba

Emmanuel Mumba

31 January 2026

How to Use Open Codex CLI with Google Gemini 2.5 Pro: Streamline Terminal AI Coding Workflows

Open Codex CLI brings the power of large language models (LLMs) directly to your terminal, making advanced AI coding assistance accessible from the command line. This guide shows developers, API engineers, and technical leads how to use Open Codex CLI with Google’s Gemini 2.5 Pro model—one of the most capable LLMs available today.

Whether you’re automating code generation, refactoring scripts, or streamlining repetitive tasks, integrating Gemini into your CLI workflow can boost productivity, code quality, and team efficiency—all without leaving your terminal.

button

What Is Open Codex CLI and Why Use It with Gemini?

Open Codex CLI is an open-source tool (npm: open-codex) originally forked from OpenAI’s Codex CLI, but now supports multiple AI providers, including Google Gemini, OpenAI, OpenRouter, and Ollama. Its terminal-native design allows you to:

Combining Open Codex CLI with Google Gemini 2.5 Pro offers:

“In just a few hours my friend forked OpenAI Codex to work with Gemini 2.5 Pro 🤯”
Sawyer Hood, April 17, 2025

Prerequisites

Before getting started, make sure you have:


Step 1: Install Open Codex CLI

Install Open Codex CLI globally using npm:

bash
npm install -g open-codex

Or, if you use Yarn:

bash
yarn global add open-codex

Verify installation:

bash
open-codex --version

If you run into permission issues, follow npm’s guide to fixing permissions.


Step 2: Configure Gemini Access

To use Gemini, you need to provide your API key and set Gemini as the provider.

Method 1: Environment Variable (Quick Start)

Set your Gemini API key as an environment variable:

bash
export GOOGLEGENERATIVEAIAPIKEY="YOURAPIKEY_HERE"
This only lasts for the current terminal session. To make it permanent, add the export line to your shell config (e.g., ~/.zshrc for Zsh, ~/.bashrc or ~/.bash_profile for Bash), then source ~/.zshrc to reload.

Each time you run Open Codex CLI, specify Gemini as the provider:

bash
open-codex --provider gemini "What is the capital of France?"

Set Gemini as the default provider in a config file:

bash
mkdir -p ~/.codex
bash
nano ~/.codex/config.json
json
{
"provider": "gemini",
"model": "gemini-2.5-pro-preview-03-25"
}
You still need to set GOOGLEGENERATIVEAIAPIKEY as an environment variable as described above. The config file sets the provider/model; the env variable provides credentials.

Now, running open-codex will default to Gemini:

bash
open-codex "Explain the concept of API versioning."

Step 3: Basic Usage Examples with Gemini

Interactive REPL Mode

Start a conversational session:

bash
open-codex
open-codex --provider gemini

You'll see:

Welcome to Open Codex CLI! Type your request, then hit Enter twice to send.
>

Type your prompt (e.g., How does Gemini 2.5 Pro differ from earlier models?), then Enter twice to send.

Direct Prompting

For quick, one-off answers:

bash
open-codex "Show a Python example of API pagination."

To specify model or provider explicitly:

bash
open-codex --provider gemini --model gemini-2.5-pro-preview-03-25 "Write a bash script to find all files larger than 10MB."

Or use a faster, cheaper model for lightweight tasks:

bash
open-codex --provider gemini --model gemini-2.0-flash "Summarize the key points of RESTful API design."

Step 4: Advanced Features—AI-Powered Development from Your Terminal

File System Interaction

Open Codex CLI can read and modify files, enabling real-world coding tasks:

bash
open-codex --provider gemini "Read 'api/routes.js' and suggest improvements for maintainability."
bash
open-codex --provider gemini "Add error handling to 'api/routes.js' for all endpoints."

The CLI will show a diff and ask: Apply patch? [y/N]

Command Execution (with Safety)

Open Codex CLI can run shell commands suggested by Gemini, but only after your approval (unless you change approval mode):

Example:

bash
open-codex --provider gemini "Install the 'requests' library using pip."

Gemini may propose pip install requests, and the CLI will ask: Run command? [y/N]

All commands are sandboxed—network disabled and directory-confined for safety.

Project Context with codex.md

Guide Gemini with persistent project instructions:

Use these files to describe API conventions, libraries, or team practices—so you don’t have to repeat them in every prompt.


Troubleshooting & Best Practices

button

Conclusion

Integrating Open Codex CLI with Google Gemini 2.5 Pro empowers API developers, QA teams, and backend engineers to harness advanced AI directly within the terminal. From generating API code snippets to refactoring scripts and automating repetitive tasks, this combination enhances productivity, code quality, and security.

By following this guide, you can set up a powerful, developer-centric AI workflow—while keeping control over your codebase and workflow. Experiment with prompt styles, approval modes, and project context for best results.

And if you’re looking to bring this level of efficiency to your API lifecycle—testing, documentation, and team collaboration included—consider exploring Apidog as your all-in-one platform.

button

Explore more

How to Send SMS and WhatsApp Messages Faster using Sent.dm API ?

How to Send SMS and WhatsApp Messages Faster using Sent.dm API ?

Learn how to use the Sent.dm API for SMS and WhatsApp messaging, then test requests, templates, and webhooks faster with Apidog.

26 March 2026

Essential Security Policies to Implement in MCP

Essential Security Policies to Implement in MCP

Learn the essential security policies to implement in MCP for bulletproof AI integrations. This guide covers practical steps, real-world examples, and best practices for MCP security.

26 March 2026

Top 10 Open Finance API Use Cases for Modern Fintech

Top 10 Open Finance API Use Cases for Modern Fintech

Explore the most impactful open finance API use cases— from personal finance management to instant payments and lending. See how these APIs fuel innovation and how platforms like Apidog streamline open finance API development.

25 March 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs