Notes archive

Codex Practical Development Guidebook

A practical development guidebook for who is new to Codex, or who wants to use Codex in a more efficient way.

Published

Codex Practical Development Guidebook

A concise, beginner-friendly guide to using Codex efficiently for web apps, mobile apps, and personal software projects.

AI disclosure: This article was drafted and revised with assistance from AI.


1. What Codex Is

Codex is an AI coding agent from OpenAI.

It can help with:

  • understanding a codebase
  • planning features
  • writing code
  • editing files
  • running tests
  • fixing bugs
  • refactoring
  • reviewing diffs
  • generating documentation
  • integrating with external tools via MCP

The correct mental model is:

Codex is not just a chatbot. Codex is an AI engineering partner that can work inside your repository.

You should use Codex like you would delegate work to a capable engineer:

  • give clear goals
  • provide constraints
  • define success
  • ask it to verify the result

2. Where You Use Codex

Codex can be used through several surfaces.

Codex IDE

Best for:

  • interactive feature development
  • reviewing diffs
  • editing code while staying inside your editor
  • asking questions about selected files
  • small to medium coding tasks

Use it when you want to stay close to the code.

Codex CLI

Best for:

  • repository-wide tasks
  • refactoring
  • running tests
  • debugging failing commands
  • fixing CI issues
  • working directly from the terminal

Use it when you want Codex to operate on your local project directory.

Codex Web / Cloud

Best for:

  • delegating larger tasks
  • parallel development
  • long-running work
  • working across branches or worktrees

Use it when you want Codex to work more independently.

Codex SDK

Best for:

  • custom automation
  • CI bots
  • internal developer tools
  • issue-to-PR workflows
  • persistent coding workflows

Most beginners do not need the SDK at first.


3. Recommended Mindset

Bad usage:

text
Build my app.

Better usage:

text
Inspect this repository and propose a plan to implement user authentication.
Do not modify files yet.
After I approve the plan, implement it, add tests, and run verification commands.

Best usage:

text
Goal:
Implement email/password authentication.

Requirements:
- Users can sign up with email and password.
- Passwords must be securely hashed.
- Login returns a valid session.
- Invalid credentials return a clear error.

Constraints:
- Follow the existing project architecture.
- Do not introduce a new auth provider unless necessary.
- Do not change unrelated files.
- Add tests for signup, login, and invalid credentials.

Workflow:
1. Inspect the repository.
2. Explain the current relevant architecture.
3. Propose a file-level implementation plan.
4. Wait for approval before editing.
5. Implement with minimal diff.
6. Run tests, lint, typecheck, and build.
7. Summarize changes and risks.

Codex works best when you provide:

  • goal
  • context
  • constraints
  • expected workflow
  • verification commands
  • definition of done

4. The Core Codex Workflow

Use this loop:

text
Understand → Plan → Implement → Verify → Review

Step 1: Understand

Start with a read-only analysis.

text
Inspect this repository and explain:
- project structure
- main framework
- build/test commands
- important modules
- current architecture
- risks before changing code

Do not modify files.

Step 2: Plan

Ask for a plan before edits.

text
Create an implementation plan for [feature].

Include:
- files to modify
- files to create
- tests to add
- commands to run
- possible risks

Do not modify files yet.

Step 3: Implement

Give permission to modify files.

text
Implement the approved plan.
Keep the diff minimal.
Follow existing conventions.
Do not refactor unrelated files.

Step 4: Verify

Ask Codex to validate its work.

text
Run the relevant verification commands:
- lint
- typecheck
- tests
- build

Fix failures caused by your changes.
If a failure is unrelated, explain it clearly.

Step 5: Review

Ask for an engineering summary.

text
Summarize:
- files changed
- behavior added or changed
- tests added or updated
- commands run
- known risks
- recommended follow-up tasks

5. What to Prepare Before Using Codex

Before asking Codex to build features, make your repository Codex-friendly.

Recommended structure:

text
project/
├── README.md
├── AGENTS.md
├── .codex/
│   └── config.toml
├── .env.example
├── package.json
├── src/
├── tests/
├── docs/
│   └── architecture.md
└── scripts/

Minimum useful setup:

text
README.md
AGENTS.md
.env.example
working dev/test/lint/build commands

For most personal projects, this is more important than advanced MCP or custom agents.


6. README.md: Human + AI Project Overview

Your README.md should explain the project to humans and Codex.

Recommended structure:

markdown
# Project Name

## Purpose

Briefly explain what this app does.

## Tech Stack

- Frontend:
- Backend:
- Database:
- Auth:
- Deployment:

## Local Development

```bash
npm install
npm run dev
```

## Common Commands

```bash
npm run lint
npm run typecheck
npm run test
npm run build
```

## Folder Structure

```text
src/
├── app/
├── components/
├── lib/
├── services/
└── tests/
```

## Development Rules

- Keep changes small.
    
- Add tests for new business logic.
    
- Do not modify generated files manually.
    
- Do not commit secrets.
    

7. AGENTS.md: The Most Important Instruction File

AGENTS.md is the main instruction file for Codex.

Use it to tell Codex:

  • what the project does
  • how the codebase is organized
  • what commands to run
  • what coding style to follow
  • what files not to touch
  • how to test changes
  • when to ask before making changes

Think of it as:

The onboarding document for Codex.

You can have:

text
~/.codex/AGENTS.md          # global personal preferences
project/AGENTS.md           # project-specific instructions
project/subdir/AGENTS.md    # directory-specific instructions

For a personal project, start with one root-level AGENTS.md.


8. Starter AGENTS.md Template

Copy this into AGENTS.md.

markdown
# AGENTS.md

This file contains project-specific instructions for Codex.

## Project Overview

This is a [web app / mobile app / backend service] for [brief purpose].

Main stack:

- Language:
- Framework:
- Database:
- Auth:
- Deployment:

## Development Principles

- Prefer simple, maintainable solutions.
- Keep diffs small and focused.
- Follow existing project conventions.
- Do not introduce new dependencies unless necessary.
- Ask before making large architectural changes.
- Prioritize correctness, readability, and testability.

## Common Commands

Use these commands when relevant:

```bash
npm run dev
npm run lint
npm run typecheck
npm run test
npm run build
```

If a command fails, investigate and explain the root cause before making more changes.

## Project Structure

```text
src/
├── app/          # routes/pages
├── components/   # reusable UI components
├── lib/          # shared utilities
├── services/     # business logic / API clients
├── db/           # database schema and migrations
└── tests/        # tests
```

## Coding Style

- Use TypeScript.
    
- Prefer explicit types for public functions.
    
- Avoid `any` unless there is a strong reason.
    
- Keep functions small and focused.
    
- Prefer composition over inheritance.
    
- Avoid duplicated logic.
    
- Use meaningful names.
    

## UI Rules

- Reuse existing components before creating new ones.
    
- Keep styling consistent with the current design system.
    
- Avoid large visual redesigns unless explicitly requested.
    
- Make UI responsive by default.
    
- Include loading and error states where appropriate.
    

## Backend Rules

- Validate all external input.
    
- Do not expose secrets.
    
- Handle errors explicitly.
    
- Keep API responses consistent.
    
- Avoid changing public API contracts without approval.
    
- Add logging only when useful and safe.
    

## Database Rules

- Do not modify existing migrations unless explicitly asked.
    
- Create new migrations for schema changes.
    
- Explain migration risks before applying database changes.
    
- Never use production credentials.
    
- Prefer read-only inspection unless modification is explicitly required.
    

## Testing Rules

For new features:

- Add or update tests.
    
- Cover happy path and important failure cases.
    
- Run the relevant test command.
    
- If tests cannot be run, explain why.
    

## Git Rules

- Do not commit changes unless explicitly asked.
    
- Before suggesting a commit, summarize the diff.
    
- Use clear commit messages.
    
- Do not rewrite Git history unless explicitly asked.
    

## Security Rules

Never read, print, modify, or commit:

- `.env`
    
- `.env.*`
    
- secret files
    
- private keys
    
- production credentials
    

Use `.env.example` for documenting required environment variables.

## Task Workflow

For non-trivial tasks:

1. Inspect the relevant files.
    
2. Explain the current behavior.
    
3. Propose a plan.
    
4. Wait for approval if the change is large.
    
5. Implement with minimal diff.
    
6. Run verification commands.
    
7. Summarize the result.
    

## Definition of Done

A task is done when:

- The requested behavior is implemented.
    
- Relevant tests are added or updated.
    
- Lint/typecheck/test/build pass, or failures are explained.
    
- The final response includes:
    
    - changed files
        
    - verification result
        
    - risks or follow-up tasks
        

9. Global AGENTS.md

Use a global AGENTS.md for your personal default preferences.

Example path:

text
~/.codex/AGENTS.md

Example:

markdown
# Global Codex Instructions

## Personal Preferences

- Prefer concise explanations.
- Use practical engineering reasoning.
- Keep changes minimal.
- Do not over-engineer.
- Ask before large architecture changes.
- Prefer TypeScript for JavaScript projects.
- Prefer explicit validation and clear error handling.

## Default Workflow

For non-trivial tasks:

1. Inspect first.
2. Plan before editing.
3. Implement in small steps.
4. Run verification commands.
5. Summarize changes and risks.

## Safety

- Never access secrets unless explicitly allowed.
- Never modify `.env` files.
- Never run destructive commands without confirmation.

Use global instructions for preferences that apply to all projects.

Use project AGENTS.md for rules specific to one repo.


10. .codex/config.toml

Codex can use configuration files to control behavior.

Common locations:

text
~/.codex/config.toml
project/.codex/config.toml

Use config for:

  • default model/settings
  • approval behavior
  • sandbox behavior
  • MCP servers
  • profiles
  • skills
  • project-specific settings

For beginners, keep it simple.


11. Starter .codex/config.toml Template

Create:

text
.codex/config.toml

Starter template:

toml
# .codex/config.toml
# Project-level Codex configuration

# Keep project config small and explicit.
# Put personal preferences in ~/.codex/AGENTS.md.
# Put project rules in AGENTS.md.

# Example profile for normal development
[profiles.dev]
approval_policy = "on-request"

# Example profile for safer review-only work
[profiles.review]
approval_policy = "on-request"

# Example profile for more autonomous local work
# Use only when you trust the repo and commands.
[profiles.autonomous]
approval_policy = "on-failure"

# Optional: project-specific environment variables can be referenced
# by tools or MCP servers, but do not hardcode secrets here.

Important beginner principle:

Do not over-configure Codex on day one.

Start with:

text
AGENTS.md
README.md
basic commands

Add config only when you know what behavior you want to control.


12. Safe Permission Mindset

Codex may run commands depending on your environment and approval settings.

Beginner safety rules:

  • Start with manual approval.
  • Allow test/lint/build commands.
  • Be careful with destructive shell commands.
  • Never allow production credentials.
  • Never hardcode secrets in config files.
  • Review diffs before accepting changes.

Safe commands:

bash
npm run lint
npm run typecheck
npm run test
npm run build
git status
git diff

Commands to treat carefully:

bash
rm -rf
sudo
chmod 777
curl | sh
database migration commands
deployment commands
production scripts

13. MCP: What It Is

MCP means Model Context Protocol.

It lets Codex connect to external tools and data sources.

Examples:

  • documentation
  • GitHub
  • issue trackers
  • databases
  • logs
  • monitoring tools
  • design tools
  • internal APIs

MCP is useful when Codex needs information outside the repository.

Do not add MCP just because it sounds advanced.


14. When You Actually Need MCP

Ask:

text
Does Codex repeatedly need information that is not in the repo?

If no, do not add MCP.

If yes, add the smallest useful MCP.

Good reasons to add MCP:

  • You keep copying GitHub issue details into prompts.
  • You want Codex to inspect PRs or issues.
  • You want Codex to query documentation.
  • You want Codex to inspect database schema.
  • You want Codex to read logs or error tracking data.
  • You want Codex to reference design files.

Bad reasons to add MCP:

  • “I want an advanced setup.”
  • “Agents need tools.”
  • “Maybe I will need it later.”
  • “I want to automate everything before building the app.”

For a beginner personal project, start without MCP.


15. Practical MCP Setup Strategy

Recommended order:

Phase 1: No MCP

Use only repository context.

Good for:

  • early MVP
  • local development
  • simple personal apps
  • learning Codex basics

Phase 2: Docs MCP

Useful when:

  • you use unfamiliar libraries
  • API docs change often
  • you want fewer hallucinated API calls
  • you want Codex to check official docs

Phase 3: GitHub MCP

Useful when:

  • you manage issues on GitHub
  • you want Codex to review PRs
  • you want Codex to connect work to issue requirements

Phase 4: Database MCP

Useful when:

  • schema becomes complex
  • debugging requires read-only DB inspection
  • you want Codex to reason from real table structure

Use read-only credentials whenever possible.

Phase 5: Observability MCP

Useful when:

  • the app is deployed
  • users report bugs
  • you need logs, traces, or metrics
  • you want Codex to diagnose production issues

Phase 6: Design / Docs MCP

Useful when:

  • you use Figma
  • product specs live in Notion or docs
  • UI consistency matters

16. MCP Configuration Example

You can manage MCP servers through Codex commands or config.

Example conceptual config:

toml
# ~/.codex/config.toml or .codex/config.toml

[mcp_servers.example_docs]
command = "npx"
args = ["-y", "example-docs-mcp-server"]

[mcp_servers.example_docs.env]
EXAMPLE_API_KEY = "${EXAMPLE_API_KEY}"

Do not hardcode secrets.

Bad:

toml
API_KEY = "real-secret-key"

Good:

toml
API_KEY = "${API_KEY}"

General MCP safety rules:

  • Prefer read-only access.
  • Use least privilege.
  • Avoid production credentials.
  • Use separate development tokens.
  • Review what each MCP server can access.
  • Remove MCPs you no longer need.

17. Codex Skills

Skills are reusable packages of instructions, scripts, and resources for specific workflows.

Use Skills when you repeatedly ask Codex to do the same kind of task.

Good Skill use cases:

  • generate project documentation
  • perform security review
  • create release notes
  • review API design
  • generate test cases
  • apply project-specific code review checklist
  • migrate code using a known pattern

Do not create Skills on day one.

Start with AGENTS.md.

Create Skills later when repeated workflows become obvious.


18. When to Build Custom Agents

Most personal projects do not need custom agents.

Codex itself already acts as the coding agent.

Build custom agents only when you want automation such as:

  • CI failure fixing
  • automatic PR review
  • issue triage
  • dependency upgrade assistant
  • release assistant
  • test generation bot
  • internal developer platform assistant

Recommended maturity path:

text
1. Use Codex manually
2. Add AGENTS.md
3. Add project config
4. Add MCP
5. Add Skills
6. Build custom agents with SDK

Do not start at step 6.


19. Useful Codex Prompt Templates

19.1 Project Onboarding

text
Inspect this repository and explain it to me as if I just joined the project.

Include:
- tech stack
- folder structure
- main data flow
- build/test commands
- important risks
- where I should start reading

Do not modify files.

19.2 Feature Development

text
I want to implement [feature].

Requirements:
- [requirement 1]
- [requirement 2]
- [requirement 3]

Constraints:
- Follow existing architecture.
- Keep the diff small.
- Add tests.
- Do not introduce new dependencies unless necessary.
- Do not modify unrelated files.

First inspect the repo and propose a file-level plan.
Do not modify files until I approve.

19.3 Bug Fix

text
There is a bug:

[describe bug or paste error]

Please:
1. Reproduce or locate the issue.
2. Explain the root cause.
3. Propose a minimal fix.
4. Implement the fix.
5. Add or update tests.
6. Run verification commands.

19.4 Refactor

text
Refactor [module/file] to improve maintainability.

Constraints:
- Do not change external behavior.
- Do not change public API.
- Keep the diff focused.
- Do not refactor unrelated files.
- Add tests only if current coverage is insufficient.

Before editing, explain the refactor plan.

19.5 Code Review

text
Review the current diff.

Focus on:
- correctness
- edge cases
- security
- test coverage
- maintainability
- unnecessary complexity

Do not modify files.
Give prioritized feedback.

19.6 Test Generation

text
Add tests for [feature/module].

Cover:
- normal case
- edge cases
- invalid input
- error handling

Use the existing test style.
Run the relevant test command after adding tests.

19.7 Architecture Review

text
Review the current architecture for [area].

Tell me:
- what is good
- what is risky
- where complexity may grow
- what should be refactored now
- what can wait

Do not modify files.

19.8 CI Failure Fix

text
The CI failed with this output:

[paste CI log]

Please:
1. Identify the failing step.
2. Explain the likely root cause.
3. Inspect relevant files.
4. Propose a minimal fix.
5. Implement the fix.
6. Run the same command locally if possible.
7. Summarize the result.

19.9 Dependency Upgrade

text
Upgrade [dependency] from [old version] to [new version].

Requirements:
- Check breaking changes.
- Update code if needed.
- Keep the diff minimal.
- Run tests and build.
- Summarize any behavior changes.

20. Recommended Workflow for Building a Web App

Example stack:

  • Next.js
  • TypeScript
  • Tailwind
  • Supabase or PostgreSQL
  • Vercel

Step 1: Create the project

Set up the base app manually or with a framework starter.

Step 2: Add project instructions

Create:

text
README.md
AGENTS.md
.codex/config.toml
.env.example

Step 3: Ask Codex to inspect

text
Inspect this project and suggest improvements to make it more maintainable.
Do not modify files.

Step 4: Build feature by feature

Do not ask Codex to build the whole app at once.

Use small tasks:

text
Implement the landing page.
text
Implement user signup.
text
Implement login.
text
Implement user profile editing.
text
Implement dashboard data loading.

Step 5: Verify after each feature

text
Run lint, typecheck, tests, and build.
Fix failures caused by your changes.

21. Recommended Workflow for Building a Mobile App

For React Native / Expo:

Document these clearly:

text
app navigation
screen structure
state management
API client
local storage
environment config
build commands

Mobile-specific additions for AGENTS.md:

markdown
## Mobile App Rules

- Follow the existing navigation pattern.
- Keep screens thin.
- Put business logic in services/hooks.
- Keep reusable UI in components.
- Avoid platform-specific code unless necessary.
- Test both iOS and Android assumptions when possible.
- Do not change app permissions without approval.
- Do not introduce native modules unless necessary.

Useful prompt:

text
Implement [screen name].

Requirements:
- [UI behavior]
- [API behavior]
- [loading state]
- [error state]

Constraints:
- Follow existing navigation.
- Reuse existing components.
- Keep business logic outside the screen component.
- Do not add native dependencies unless necessary.

First propose a plan.

22. How to Use Codex Efficiently

22.1 Start with read-only tasks

Before allowing edits:

text
Analyze the codebase. Do not modify files.

22.2 Ask for plans before big changes

text
Propose a plan before editing.

22.3 Keep tasks small

Bad:

text
Build the whole app.

Good:

text
Implement the login form UI only.

Better:

text
Implement the login form UI using existing components.
Do not connect the API yet.

22.4 Use verification commands

Always ask Codex to run relevant commands:

text
npm run lint
npm run typecheck
npm run test
npm run build

Adjust for your stack.

22.5 Ask for a final engineering summary

text
Summarize:
- files changed
- behavior added
- tests added
- commands run
- known risks

23. Common Beginner Mistakes

Mistake 1: Asking too broadly

Bad:

text
Make this app better.

Better:

text
Review the dashboard page for maintainability and suggest 5 concrete improvements.
Do not modify files.

Mistake 2: Skipping tests

Always require verification.

Mistake 3: Letting Codex change too much

Use constraints:

text
Keep the diff minimal.
Do not refactor unrelated files.

Mistake 4: Not using AGENTS.md

If you repeat the same instruction twice, put it in AGENTS.md.

Mistake 5: Adding MCP too early

MCP is powerful, but unnecessary for a small local MVP.

Mistake 6: Hardcoding secrets

Never put API keys in:

text
AGENTS.md
config.toml
README.md
.mcp files
source code

Use environment variables.

Mistake 7: Trusting changes without review

Always review:

bash
git diff

Ask Codex:

text
Review your own diff for bugs, security issues, and unnecessary changes.

24. Practical First-Day Setup Checklist

Use this checklist when starting a new project.

Required

  • Create repository
  • Add README.md
  • Add AGENTS.md
  • Add .env.example
  • Add lint command
  • Add test command
  • Add build command
  • Add .gitignore
  • Add basic project structure

Recommended

  • Add .codex/config.toml
  • Add docs/architecture.md
  • Add basic tests
  • Add CI workflow
  • Add code formatting

Later

  • Add Docs MCP
  • Add GitHub MCP
  • Add database MCP
  • Add observability MCP
  • Add Skills
  • Add SDK-based automation

25. Minimal Setup for a Personal Project

If you want the smallest useful setup, use this:

text
README.md
AGENTS.md
.env.example
.codex/config.toml

With this minimal AGENTS.md:

markdown
# AGENTS.md

## Project Overview

This is a personal software project.

## Rules

- Keep changes small and focused.
- Follow existing code style.
- Do not introduce dependencies unless necessary.
- Do not read or modify `.env` files.
- Add tests for new logic.
- Run lint/test/build when relevant.
- Explain risks before major architecture changes.

## Commands

```bash
npm run lint
npm run test
npm run build
```

## Workflow

For non-trivial tasks:

1. Inspect files.
    
2. Propose a plan.
    
3. Implement.
    
4. Verify.
    
5. Summarize.
    

26. Best Default Prompt for Daily Use

Use this as your default prompt:

text
I want to work on [task].

Please follow this workflow:
1. Inspect the relevant files.
2. Explain the current implementation.
3. Propose a concise plan.
4. Ask for approval before large changes.
5. Implement with minimal diff.
6. Run relevant verification commands.
7. Summarize changed files, tests, and risks.

Constraints:
- Follow existing architecture.
- Do not modify unrelated files.
- Do not introduce new dependencies unless necessary.
- Do not access secrets.

27. Best Prompt for Autonomous Implementation

Use this only for well-scoped tasks.

text
Implement [task] end-to-end.

Requirements:
- [requirement 1]
- [requirement 2]

Constraints:
- Keep the diff focused.
- Follow existing patterns.
- Add tests.
- Do not change public APIs unless necessary.
- Do not modify unrelated files.

Verification:
- Run lint.
- Run typecheck.
- Run tests.
- Run build.

Final response:
- summarize changed files
- summarize tests
- list commands run
- list risks

28. Best Prompt for Learning From Codex

Codex is also useful as a teacher.

text
Explain how this feature works in this codebase.

Please cover:
- entry points
- important files
- data flow
- external dependencies
- possible failure points
- how I should safely modify it

Do not modify files.

This is useful before working in unfamiliar code.


29. Best Prompt for Product Development

When building a personal product:

text
I am building [product].

Current goal:
[goal]

User flow:
[user flow]

Technical constraints:
[constraints]

Please inspect the project and suggest a practical implementation plan.

Focus on:
- smallest useful MVP
- maintainable architecture
- testable implementation
- avoiding over-engineering

Do not modify files yet.

This helps Codex act like a product-minded engineer, not just a code generator.


30. Final Recommendation

For beginners, the best Codex setup is simple:

text
Good README
Good AGENTS.md
Small tasks
Clear constraints
Verification commands
Manual diff review

Add later:

text
.codex/config.toml
MCP
Skills
SDK automation

Do not try to build an advanced agent system first.

The main skill is learning how to give Codex clear engineering tasks with constraints and verification.

The formula is:

text
Clear goal
+ project context
+ small task scope
+ test/build verification
= effective Codex usage