Gemini CLI: Google's Command-Line AI Coding Agent
An exploration of Gemini CLI, Google's terminal-based AI coding assistant that brings Gemini's multimodal capabilities to your development workflow
OpenAI has long been at the forefront of AI-powered code generation, from the original Codex model that powered GitHub Copilot to their latest GPT-4 offerings. With the Codex CLI, OpenAI brings their advanced capabilities directly to the command line, offering developers an open-source tool for AI-assisted coding in their terminal.
Codex CLI is OpenAI’s open-source local coding agent that runs in your command line interface. It’s designed for pair programming—you work alongside the AI to write, edit, and understand code. Unlike cloud-only solutions, Codex CLI runs locally and communicates with OpenAI’s API, giving you control over your development environment.
Codex CLI embodies several key principles:
Your code stays on your machine:
The tool is designed for collaboration:
The codebase is open for:
Generate code from natural language:
codex "Create a Python function that parses CSV files and converts
them to JSON, handling encoding issues gracefully"
Modify existing code:
codex edit --file api.py "Add retry logic with exponential backoff
to all HTTP requests"
Understand unfamiliar code:
codex explain --file complex_algorithm.py
Work across your project:
codex "Refactor the authentication logic to use JWT tokens.
Update both the user service and the middleware."
Generate and execute shell commands:
codex shell "Find all JavaScript files modified in the last week
that contain async/await patterns"
Install via npm:
npm install -g @openai/codex-cli
Or clone and build:
git clone https://github.com/openai/codex
cd codex
npm install
npm link
Set up your API key:
export OPENAI_API_KEY=your-api-key
Or use the configuration file:
codex config set api_key your-api-key
Start an interactive session:
codex
Run single commands:
codex "Explain this function" --file utils.py
Describe what you need:
codex "Create a rate limiting middleware for Express.js.
Use Redis for tracking, allow 100 requests per minute per IP,
return 429 with retry-after header when exceeded."
Point at the problem:
codex "The sort function in list_utils.py doesn't handle
None values correctly. Fix it to sort None values to the end."
Generate comprehensive tests:
codex "Write unit tests for the PaymentProcessor class.
Cover success cases, error handling, and edge cases."
Get AI feedback:
codex review --file new_feature.py
Generate docs from code:
codex "Generate JSDoc documentation for all exported
functions in src/api/"
Codex CLI supports various OpenAI models:
Best for complex tasks:
codex --model gpt-4 "Complex refactoring task..."
Faster with large context:
codex --model gpt-4-turbo "Process this large file..."
Cost-effective for simpler tasks:
codex --model gpt-3.5-turbo "Simple utility function..."
Control what context is sent:
# Include specific files
codex --include "src/**/*.ts" "Update all API handlers"
# Exclude files
codex --exclude "node_modules/**" "Find security issues"
Different output formats:
# Diff format
codex --output diff "Add error handling"
# Full file
codex --output file "Rewrite this module"
# Explanation only
codex --output explain "What does this do?"
Interactive development:
codex interactive
> Add user model
> Now add authentication middleware
> Add tests for both
> Show me the changes
Customize behavior:
codex --system "You are a Python expert focusing on clean,
PEP-8 compliant code" "Refactor this script"
Work with version control:
# Review staged changes
git diff --staged | codex "Review these changes"
# Generate commit message
codex "Write a commit message for staged changes"
Use in pipelines:
- name: AI Code Review
run: codex review --file ${{ github.event.pull_request.diff_url }}
Combine with your editor:
# Vim
:!codex explain %
# VS Code
# Use terminal integration
| Feature | Codex CLI | GitHub Copilot | Claude Code | Aider |
|---|---|---|---|---|
| Interface | Terminal | IDE | Terminal | Terminal |
| Open Source | Yes | No | No | Yes |
| Multi-file | Yes | Limited | Yes | Yes |
| Native Git | Basic | No | Yes | Yes |
| Local Model | No | No | No | Yes |
| Streaming | Yes | Yes | Yes | Yes |
Include relevant information:
# Good
codex --include "src/models/*.py" "Add validation to User model
matching the pattern used in Product model"
# Less effective
codex "Add validation"
Clear instructions get better results:
# Good
codex "Add input validation to the register endpoint:
- Email: valid format, max 255 chars
- Password: min 8 chars, 1 uppercase, 1 number
- Name: required, 2-100 chars
Return 400 with field-specific error messages"
# Less effective
codex "Validate the register form"
Always verify AI-generated code:
# Check the diff before applying
codex --output diff "Make changes" | less
# Apply after review
codex --apply "Make changes"
Build up complex changes:
codex interactive
> First, show me the current auth flow
> Now propose how to add OAuth
> Implement the OAuth provider interface
> Add Google OAuth implementation
> Add tests
Protect your credentials:
# Use environment variables
export OPENAI_API_KEY=$(cat ~/.secrets/openai-key)
# Don't commit keys
echo "OPENAI_API_KEY" >> .gitignore
Understand what’s sent:
AI can generate vulnerable code:
Always review security-sensitive code.
Requires internet and API access:
Model context windows apply:
AI suggestions need verification:
Track API consumption:
codex usage --month current
Reduce costs:
Prevent runaway costs:
codex config set max_tokens_per_request 4000
codex config set monthly_limit 100
OpenAI continues development with:
OpenAI’s Codex CLI brings powerful AI assistance to the command line. Its open-source nature, combined with access to GPT-4’s capabilities, makes it a valuable tool for developers who prefer terminal-based workflows.
The pair programming model—where you work alongside the AI rather than delegating entirely—strikes a balance between automation and control. For developers who want to leverage OpenAI’s models while maintaining oversight of their code, Codex CLI offers a solid foundation.
Whether you’re generating new code, fixing bugs, writing tests, or just trying to understand a complex codebase, Codex CLI provides the AI assistance needed without requiring you to leave your terminal.
Explore more AI coding tools and agents in our Coding Agents Directory.
An exploration of Gemini CLI, Google's terminal-based AI coding assistant that brings Gemini's multimodal capabilities to your development workflow
A comprehensive guide to major Terminal User Interface (TUI) AI coding assistants: Claude Code, Gemini Code, and OpenAI Codex
Explore Qwen Code, Alibaba's command-line AI workflow tool optimized for the Qwen3-Coder models, bringing advanced code understanding and intelligent assistance to your terminal