Skip to main content

Overview

Codex provides comprehensive tracing and logging capabilities to help you understand what’s happening under the hood. This is especially useful for:
  • Debugging unexpected behavior
  • Troubleshooting integration issues
  • Understanding performance characteristics
  • Filing detailed bug reports
Verbose logging can generate large amounts of output and may include sensitive information. Use with caution in production environments.

Quick Start

Enable verbose logging with the RUST_LOG environment variable:

RUST_LOG Environment Variable

The RUST_LOG variable controls logging verbosity using the standard Rust tracing infrastructure.

Log Levels

error
level
Only critical errors that prevent operation
warn
level
Warning messages about potential issues
info
level
High-level informational messages (default for Codex crates)
debug
level
Detailed debugging information
trace
level
Extremely verbose tracing output

Syntax

Set the same level for all modules:

Common Logging Scenarios

Debug API Requests

Output includes:
  • Request URLs and headers
  • Request body payloads
  • Response status codes
  • Response bodies
  • Timing information

Debug File Operations

Shows:
  • Files being read
  • Patches being applied
  • File system operations
  • Permission checks

Debug Command Execution

Includes:
  • Commands being executed
  • Working directory
  • Environment variables
  • stdout/stderr output
  • Exit codes

Debug Sandboxing

Reveals:
  • Sandbox initialization
  • Policy rules being applied
  • Permission checks
  • Blocked operations

Exec Mode Logging

In exec mode, logs are written to a file to avoid interfering with output:

Log File Location

By default, logs are written to:

Enable File Logging

Logs are automatically written to file when you set RUST_LOG:

Log Rotation

Log files are rotated automatically. Old logs are kept for debugging but can be safely deleted.

OpenTelemetry Integration

Codex supports OpenTelemetry for distributed tracing:

Configuration

~/.codex/config.toml

Environment Variables

Alternatively, use standard OTEL env vars:

Viewing Traces

Use Jaeger or another OTEL-compatible backend:
1

Start Jaeger

2

Configure Codex

3

View Traces

Open http://localhost:16686 in your browser

Legacy TypeScript CLI

For the legacy TypeScript implementation, use DEBUG:
The TypeScript CLI is deprecated. Consider migrating to the Rust implementation for better performance and features.

Practical Examples

Look for:
  • API request latency
  • File I/O timing
  • Long-running operations
Shows:
  • Token acquisition
  • Token refresh attempts
  • Authentication errors
  • API key validation
Reveals:
  • MCP server initialization
  • Tool calls and responses
  • Connection errors
  • Message parsing
Displays:
  • Config file locations checked
  • Loaded configuration values
  • Override application
  • Validation errors
Captures all Codex modules at debug level and saves to file.

Performance Considerations

Log Level Impact

Higher log levels (trace/debug) can slow down execution by 10-50%

File I/O Overhead

Writing logs to disk adds latency, especially with trace level

Memory Usage

Verbose logging increases memory usage for buffering

Network Tracing

OTEL tracing adds ~5-10ms per span to network requests
For production use, stick with info or warn level logging. Use debug or trace only for active troubleshooting.

Filtering Output

Grep for Specific Events

Focus on Specific Modules

Troubleshooting Logging

  • Verify RUST_LOG is set: echo $RUST_LOG
  • Check log file location: ls -lh ~/.codex/logs/
  • Try higher verbosity: RUST_LOG=trace
  • Ensure Codex has write permissions to log directory
  • Lower the log level: RUST_LOG=info instead of debug
  • Filter to specific modules: RUST_LOG=codex_core=debug
  • Use grep to filter: RUST_LOG=debug codex 2>&1 | grep pattern
  • Increase verbosity: RUST_LOG=debug or RUST_LOG=trace
  • Check you’re targeting the right module
  • Some modules may not have debug logging implemented
  • Codex attempts to redact secrets automatically
  • Review logs before sharing publicly
  • Use RUST_LOG=info in production to minimize exposure
  • Set otel.sampling_ratio = 0.1 to reduce trace data

Filing Bug Reports

When reporting issues, include relevant logs:
1

Reproduce with Logging

2

Redact Sensitive Data

Review the log file and remove:
  • API keys
  • Tokens
  • Personal information
  • Proprietary code
3

Attach to Issue

Include the redacted log file when filing a GitHub issue:https://github.com/openai/codex/issues/new

Advanced Configuration

Custom Log Format

Codex uses tracing-subscriber for logging. You can customize the format:

Span Tracing

View function call spans:
Output includes:

See Also

Exec Mode

Non-interactive execution for automation

Configuration

Configure Codex behavior

Troubleshooting

Common issues and solutions

Contributing

Help improve Codex