How to Integrate Codex with VS Code & GitHub Copilot (2026)
Step-by-step guide to setting up OpenAI Codex alongside GitHub Copilot in VS Code
Start Building with Hypereal
Access Kling, Flux, Sora, Veo & more through a single API. Free credits to start, scale to millions.
No credit card required • 100k+ developers • Enterprise ready
How to Integrate Codex with VS Code & GitHub Copilot (2026)
OpenAI's Codex CLI and GitHub Copilot are two of the most powerful AI coding tools available in 2026. While Copilot handles inline completions directly in your editor, Codex operates as a terminal-based coding agent that can read, write, and refactor entire files autonomously. Combining both gives you the best of both worlds: real-time suggestions in your editor and autonomous task execution from your terminal.
This guide walks you through setting up both tools in VS Code, configuring them to work together, and practical workflows that maximize your productivity.
Prerequisites
Before starting, make sure you have the following:
| Requirement | Minimum Version | Notes |
|---|---|---|
| VS Code | 1.96+ | Latest stable recommended |
| Node.js | 18.0+ | Required for Codex CLI |
| GitHub Copilot subscription | Active | Individual or Business plan |
| OpenAI API key | Valid key | For Codex CLI access |
| Git | 2.40+ | Codex requires a git repo |
Step 1: Install GitHub Copilot in VS Code
If you do not already have Copilot installed:
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "GitHub Copilot"
- Install both GitHub Copilot and GitHub Copilot Chat
- Sign in with your GitHub account when prompted
Verify the installation by opening any code file. You should see ghost text suggestions as you type.
Configure Copilot Settings
Open your VS Code settings (Ctrl+, / Cmd+,) and adjust these key settings:
{
"github.copilot.enable": {
"*": true,
"yaml": true,
"markdown": true,
"plaintext": false
},
"github.copilot.advanced": {
"length": 500,
"temperature": 0.1
}
}
Setting a lower temperature (0.1) produces more deterministic suggestions, which is better for production code.
Step 2: Install OpenAI Codex CLI
Codex CLI is a terminal-based agent that can autonomously execute coding tasks. Install it globally:
npm install -g @openai/codex
Set your OpenAI API key as an environment variable. Add this to your shell profile (~/.bashrc, ~/.zshrc, or equivalent):
export OPENAI_API_KEY="sk-proj-your-api-key-here"
Verify the installation:
codex --version
Configure Codex CLI
Codex CLI uses a configuration file at ~/.codex/config.yaml. Create it with recommended settings:
# ~/.codex/config.yaml
model: o4-mini
approval_mode: suggest
The three approval modes control how much autonomy Codex has:
| Mode | Behavior | Best For |
|---|---|---|
suggest |
Shows proposed changes, requires approval | Learning, reviewing |
auto-edit |
Automatically edits files, asks before running commands | Daily development |
full-auto |
Fully autonomous execution | Trusted, sandboxed tasks |
Start with suggest mode until you are comfortable with how Codex operates.
Step 3: Use Codex from the VS Code Integrated Terminal
The simplest integration is running Codex directly in the VS Code integrated terminal:
- Open the VS Code terminal (Ctrl+
/ Cmd+) - Navigate to your project directory
- Run Codex with a task description:
codex "Add input validation to the signup form in src/components/SignupForm.tsx"
Codex will analyze your project structure, read relevant files, and propose changes. In suggest mode, it shows you a diff before applying anything.
Practical Example: Adding Error Handling
Suppose you have a basic API call:
// src/api/users.ts
export async function fetchUsers() {
const response = await fetch('/api/users');
const data = await response.json();
return data;
}
Run Codex:
codex "Add proper error handling, retry logic, and TypeScript types to src/api/users.ts"
Codex will propose something like:
// src/api/users.ts
interface User {
id: string;
name: string;
email: string;
}
interface FetchUsersResponse {
users: User[];
total: number;
}
export async function fetchUsers(retries = 3): Promise<FetchUsersResponse> {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const response = await fetch('/api/users');
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data: FetchUsersResponse = await response.json();
return data;
} catch (error) {
if (attempt === retries) {
throw new Error(
`Failed to fetch users after ${retries} attempts: ${error instanceof Error ? error.message : 'Unknown error'}`
);
}
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
}
throw new Error('Unreachable');
}
Step 4: Create a Combined Workflow
The most productive workflow uses Copilot for inline coding and Codex for larger refactoring or scaffolding tasks. Here is a recommended workflow:
For New Features
Use Codex to scaffold the feature structure:
codex "Create a new API route at src/app/api/webhooks/stripe/route.ts that handles Stripe checkout.session.completed events"Use Copilot to fill in implementation details as you edit the generated files
Use Codex to add tests:
codex "Write unit tests for the Stripe webhook handler in src/app/api/webhooks/stripe/route.ts"
For Bug Fixes
Use Copilot Chat to analyze the bug:
- Select the problematic code
- Press Ctrl+I / Cmd+I to open inline chat
- Ask: "Why might this function return undefined when the input array is empty?"
Use Codex to apply the fix across related files:
codex "Fix the null reference error in the user dashboard. The issue is that fetchUserProfile can return undefined but the Dashboard component doesn't handle that case."
Step 5: Configure Codex Project Instructions
Create a AGENTS.md file in your project root to give Codex project-specific context:
# Project Instructions
## Tech Stack
- Next.js 15 with App Router
- TypeScript strict mode
- Tailwind CSS for styling
- Drizzle ORM with PostgreSQL
- tRPC for API routes
## Conventions
- Use named exports, not default exports
- Prefer server components; add "use client" only when necessary
- All API responses use the Result<T> type from src/lib/types.ts
- Error handling uses the AppError class from src/lib/errors.ts
## Testing
- Use Vitest for unit tests
- Place tests next to source files as *.test.ts
- Use MSW for API mocking
Codex reads this file automatically and follows the specified conventions.
Copilot vs Codex: When to Use Each
| Task | Use Copilot | Use Codex |
|---|---|---|
| Writing a single function | Yes | Overkill |
| Inline code completion | Yes | No |
| Multi-file refactoring | No | Yes |
| Scaffolding new features | Partially | Yes |
| Writing tests for existing code | Partially | Yes |
| Debugging with context | Chat works well | Better for large codebases |
| Code review suggestions | Copilot Chat | Yes |
| Repetitive changes across files | No | Yes (full-auto mode) |
Troubleshooting Common Issues
Copilot Suggestions Not Appearing
# Check Copilot status in VS Code
# Look for the Copilot icon in the bottom status bar
# If it shows a warning, click it for details
# Common fix: reload the window
# Press Ctrl+Shift+P / Cmd+Shift+P > "Developer: Reload Window"
Codex CLI Fails to Read Files
Codex requires your project to be a git repository:
# Initialize git if needed
git init
git add -A
git commit -m "Initial commit"
# Now Codex can read the project
codex "Describe the project structure"
API Rate Limits
If you hit OpenAI rate limits with Codex, you can configure the model:
# ~/.codex/config.yaml
model: o4-mini # Uses less quota than o3
Cost Considerations
| Tool | Pricing Model | Approximate Cost |
|---|---|---|
| GitHub Copilot Individual | $10/month | Fixed |
| GitHub Copilot Business | $19/user/month | Fixed |
| Codex CLI (o4-mini) | Pay-per-token | ~$0.50-2.00/task |
| Codex CLI (o3) | Pay-per-token | ~$2.00-10.00/task |
For most developers, the combination of Copilot ($10/month) plus Codex on o4-mini ($15-30/month typical usage) provides excellent value.
Conclusion
Integrating Codex CLI with VS Code and GitHub Copilot creates a powerful AI-assisted development workflow. Copilot handles the moment-to-moment coding suggestions while Codex tackles larger architectural tasks, refactoring, and test generation. The key is using each tool where it excels rather than trying to force one tool to do everything.
If you are building applications that require AI-powered media generation -- images, video, voice cloning, or talking avatars -- Hypereal AI provides simple API endpoints you can integrate directly into your codebase. Combined with tools like Codex and Copilot, you can scaffold entire AI-powered features in minutes rather than days.
Related Articles
Start Building Today
Get 35 free credits on signup. No credit card required. Generate your first image in under 5 minutes.
