AI Model Wiki

    Skip to main content
    10 min read
    Lesson 3 of 5

    Configuration & Customization

    From the course OpenAI Codex CLI

    Customize Codex CLI for your workflow with configuration files, environment variables, and project-specific settings.

    Configuration File

    Create ~/.codex/config.yaml:

    model: o3
    approval_mode: auto-edit
    providers:
      openai:
        api_key_env: OPENAI_API_KEY
    

    Project Instructions

    Create a codex.md in your project root:

    # Project: E-commerce API
    
    ## Stack
    - Node.js 20 + TypeScript
    - Express with Zod validation
    - Prisma ORM with PostgreSQL
    
    ## Conventions
    - Use barrel exports
    - Error handling via AppError class
    - All routes in src/routes/
    
    ## Commands
    - npm test — Jest
    - npm run build — tsc
    - npm run lint — ESLint
    

    Environment Variables

    VariablePurpose
    OPENAI_API_KEYAPI authentication
    CODEX_MODELDefault model
    CODEX_APPROVALDefault approval mode
    CODEX_SANDBOXEnable/disable sandbox

    Custom Providers

    Codex CLI supports alternative providers:

    • OpenAI (default)
    • Azure OpenAI
    • OpenAI-compatible APIs (Ollama, LM Studio)
    • Custom endpoints via configuration

    Cost Management

    • Use o4-mini for simple tasks (cheaper)
    • Reserve o3/GPT-4o for complex reasoning
    • Monitor costs with codex --cost
    • Set spending limits in your OpenAI dashboard
    • Batch simple changes to minimize API calls

    Security Best Practices

    • Never commit API keys to repositories
    • Use environment variables for all secrets
    • Review all auto-generated code before deployment
    • Restrict sandbox permissions in production environments
    • Audit Codex commands in sensitive codebases

    Key Takeaways

    • •Configure default model and approval mode in ~/.codex/config.yaml
    • •Project-level codex.md provides persistent context like CLAUDE.md
    • •Support for alternative providers including Ollama for local models
    • •Use o4-mini for simple tasks and o3 for complex reasoning to manage costs
    0 of 5 lessons marked complete

    Progress is kept in this browser only.