Systematic Debugging Across Surfaces
It is 3 AM and your pager fires. The payments service is returning 500 errors. The error log shows a stack trace pointing to a dependency you upgraded yesterday. You need to diagnose the issue, identify the root cause, and ship a fix — all before customers wake up. This is where Codex’s multi-surface architecture turns a stressful incident into a methodical debugging session.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- A structured debugging workflow that works across all Codex surfaces
- Surface-specific debugging techniques: App for visual diff review, CLI for scriptable diagnosis, Cloud for isolated reproduction, IDE for real-time editing
- Copy-paste prompts for the most common debugging scenarios
- Strategies for debugging race conditions, intermittent failures, and production-only bugs
The Debugging Framework
Section titled “The Debugging Framework”- Reproduce: Confirm the bug exists and identify the minimal reproduction steps.
- Isolate: Narrow down which component, module, or change introduced the bug.
- Diagnose: Find the root cause in the code.
- Fix: Implement the minimal change that resolves the issue.
- Verify: Run the test suite, add a regression test, and confirm the fix.
Surface-Specific Debugging
Section titled “Surface-Specific Debugging”Best for: Quick diagnosis, scriptable debugging, and CI failures.
# Diagnose a test failurecodex exec --full-auto \ "Run npm test, capture the output, identify why the payments test is failing, find the root cause in the source code, and fix it. Run the test again to verify."
# Analyze a production errorcodex "Here is a production stack trace from our payments service:[paste stack trace]Find the root cause in the codebase. The service was working untilwe upgraded stripe-node from 14.x to 15.x yesterday."Best for: Visual diff review, parallel investigation threads, and worktree isolation.
Open a Worktree thread so your debugging does not affect your current work:
- Select “Worktree” mode, base it on your production branch
- Drop a screenshot or paste the error message into the composer
- Let Codex investigate while you continue other work
- Review the diff in the App’s visual diff pane
- Sync the fix to your local checkout when satisfied
Best for: Reproducing environment-specific issues, heavy analysis, and best-of-N diagnosis.
# Submit a cloud debugging taskcodex cloud exec --env production-mirror \ "The /api/payments endpoint returns 500 with the error 'TypeError: Cannot read property of undefined'. Reproduce the issue, find the root cause, implement a fix, and add a regression test."Common Debugging Scenarios
Section titled “Common Debugging Scenarios”CI Failure After Dependency Upgrade
Section titled “CI Failure After Dependency Upgrade”Our CI started failing after upgrading typescript from 5.3 to 5.5.The errors are in src/types/. Read the TypeScript 5.5 migration guideand fix the type errors. Do not downgrade TypeScript. Run the typechecker after each change.Production Error with Stack Trace
Section titled “Production Error with Stack Trace”Here is a production error from Sentry:[paste full error with stack trace]
Find the exact code path that leads to this error. The error startedappearing after commit abc1234. Use git diff abc1234~1..abc1234 toidentify what changed. Implement a fix and add a regression test.Memory Leak Investigation
Section titled “Memory Leak Investigation”Our Node.js service's heap grows by 50MB/hour under load. The leakwas introduced sometime in the last 2 weeks. Analyze recent commitsto src/services/ for common leak patterns: event listeners not removed,closures capturing large objects, growing arrays or maps without eviction.Identify the likely cause and propose a fix.Image-Based Debugging
Section titled “Image-Based Debugging”The Codex App and CLI support image input. For UI bugs, drop a screenshot into the composer:
# CLI with screenshotcodex -i screenshot-broken-layout.png \ "This screenshot shows a broken layout in the dashboard header. The navigation items should be horizontally aligned but they are stacking vertically. Find the CSS issue and fix it."In the App, hold Shift while dropping an image to add it as context.
When This Breaks
Section titled “When This Breaks”- Agent cannot reproduce the bug: The bug may depend on environment state (database, cache, external service). Provide as much context as possible: error messages, stack traces, recent changes, and environment details.
- Fix works but introduces a regression: The agent focused too narrowly. Ask it to run the full test suite, not just the failing test.
- Intermittent bug disappears during debugging: Add explicit logging or assertions. Ask Codex to add temporary debug instrumentation that captures the state when the error would occur.
- Agent blames the wrong commit: Provide the exact timeframe when the bug appeared and the git log. Ask the agent to analyze each suspect commit individually.
What’s Next
Section titled “What’s Next”- Review Strategies — Review debugging fixes with appropriate rigor
- Context Patterns — Keep debugging context sharp across long investigation sessions
- Prompt Engineering — Write better debugging prompts