OpenAI Codex Instructions

How to write OpenAI Codex
AGENTS.md instructions

OpenAI Codex is a terminal-based agentic coding tool that runs in a sandboxed environment. AGENTS.md files configure exactly how it behaves - learn how to write instructions that match your approval mode and keep autonomous tasks safe.

⏱ 10 min read Updated 2026 Works with OpenAI Codex CLI
Quick start

How to add instructions to Codex

Codex reads AGENTS.md from your project root. Here is the fastest path.

1
Create AGENTS.md in your project root (or codex.md as an alternative)
2
Add tech stack, architecture context, coding standards, and safety rules in markdown
3
Choose your approval mode: suggest (safest), auto-edit, or full-auto
4
Use codex --instructions "..." for one-off session overrides without editing AGENTS.md
Build your Codex prompt free →
12
AI tools covered
3
Prompt types built
5min
To your first prompt
$0
To start
AGENTS.md file location and Codex approval modes
Codex — AGENTS.md + suggest / auto-edit / full-auto modesUse TypeScript. Prefer functional components. Never modify files outside scope.Write tests for all new functions. Ask before adding dependencies.Architecture context: [describe your stack and patterns here]...

What makes Codex different from other AI coding tools

OpenAI Codex is a terminal-based agentic coding tool that reads AGENTS.md as its system prompt and executes tasks autonomously in a sandboxed environment with network access disabled and filesystem isolation by default. The sandboxed execution distinguishes Codex from Cursor or Windsurf - it is designed specifically for safe autonomous operation.

Codex runs in a sandbox
Unlike Claude Code or Cursor which run directly on your filesystem, Codex executes in a sandboxed environment with network access disabled. This makes full-auto mode significantly safer - but your AGENTS.md should still include explicit scope rules because the sandbox does not prevent unwanted changes within your project directory.

Understanding Codex approval modes

suggest (default, safest)

Codex shows every proposed change before applying it. You approve or reject each change individually. Best for learning Codex or working on unfamiliar codebases. AGENTS.md safety rules can be lighter in this mode since you have manual review of every change.

auto-edit

Codex applies file edits automatically but asks before running shell commands. Best for standard development tasks where you trust Codex's code changes but want to review before any commands execute.

full-auto

Codex runs completely autonomously in the sandbox without any prompts. Best for well-defined tasks with clear success criteria on codebases you know well. Your AGENTS.md must have the strictest scope rules in this mode.

⚠️
Match AGENTS.md to your approval mode
In suggest mode, "describe what you would change before changing it" is redundant - Codex already shows you. In full-auto mode, "only modify files in src/ unless I specify otherwise" is critical - Codex will not pause to ask.

What to include in AGENTS.md

# Project: [Name]

## Tech Stack
- TypeScript, Node.js 22
- Express, PostgreSQL via Drizzle ORM
- Vitest for testing

## Architecture
- API routes in src/routes/
- DB access only through src/db/ layer
- Auth in src/middleware/auth.ts - do not reimplement

## Scope Rules (critical for auto-edit / full-auto)
- Only modify files in src/ and tests/
- Never modify package.json without noting the change
- Run npm test after every significant change
- Task is complete when all tests pass and TypeScript compiles

## Coding Standards
- Named exports only
- Async/await over .then() chains
- JSDoc for all exported functions
💡
Add test criteria to AGENTS.md
Add explicit completion criteria: "A task is complete when all existing tests pass, new tests cover the new functionality, and TypeScript compiles without errors." This is especially important in full-auto mode where Codex runs until it believes the task is complete.

Common questions

What is the difference between AGENTS.md and codex.md?

Both are recognized by Codex. AGENTS.md is the primary documented filename. If both exist in the project root, AGENTS.md takes precedence.

How do I use --instructions without modifying AGENTS.md?

Run: codex --instructions "focus only on the authentication module" "implement password reset". The --instructions string is added as additional context for that session only.

How does Codex compare to Claude Code?

Both are agentic terminal tools with project-level instruction files (AGENTS.md vs CLAUDE.md). Codex runs in a sandboxed environment making full-auto safer. Claude Code uses Anthropic's Claude models. See our Claude Code guide for a direct comparison.

Build your Codex system prompt now

Answer a short set of questions and get a master prompt engineered specifically for Codex. Free, no account needed.

Build free with Codex →

Codex prompts free · 3 builds/month · Pro is $19/month for unlimited builds and Advanced mode

System prompts optimized for
understandingAI · free newsletter
Get more from your AI tools
Practical tips on system prompts, prompt engineering, and getting real results from AI. No fluff.

No spam. Unsubscribe anytime.