Running Tests, Debugging, and Git Workflows
A coding agent that can only write code is only half useful. The real power of Codex CLI comes from its ability to run your test suite, debug failures, and manage your git workflow. In this lesson, you will learn how to use Codex for the full development cycle: write code, test it, fix it, and commit it.
What You Will Learn
- How to use Codex to run and interpret test results
- How Codex debugs failing tests and runtime errors
- How to use Codex for git operations like commits, branches, and pull requests
- Practical workflows that combine coding, testing, and version control
- Tips for getting the most out of Codex in your development loop
Running Tests with Codex
Codex can run any test framework. It figures out the right command by reading your project configuration:
codex "run the test suite and tell me what passed and what failed"
Codex will:
- Identify your test framework (Jest, pytest, Go test, Cargo test, etc.)
- Run the appropriate command
- Parse the output and give you a summary of results
You can also be specific:
codex "run only the tests related to the user authentication module"
Or run tests after making changes:
codex "add error handling to the payment service, then run the tests to make sure nothing is broken"
In Auto Edit or Full Auto mode, Codex will automatically chain these steps together.
Debugging with Codex
Debugging is where Codex truly shines. Instead of reading stack traces yourself and hunting through files, you can hand the problem to Codex.
Debugging Failing Tests
codex "the tests in src/services/order.test.js are failing — figure out why and fix the issue"
Codex will:
- Run the failing tests to see the actual error output
- Read the test file and the source code being tested
- Identify the root cause
- Fix the code (or the test, if the test was wrong)
- Run the tests again to verify the fix
Debugging Runtime Errors
If you have an error message or stack trace, paste it directly:
codex "I'm getting this error when I start the app: TypeError: Cannot read properties of undefined (reading 'map') at UserList.render. Find and fix the bug."
Codex will trace the error to the source, understand why the value is undefined, and implement a fix.
Debugging Build Errors
codex "the build is failing with 'Module not found: Can't resolve ./utils/helpers' — find the issue and fix it"
Codex will check file paths, imports, and module resolution to identify and resolve the problem.
Git Workflows
Codex integrates naturally with git, making version control part of the automated workflow.
Creating Commits
codex "stage the changes I just made and create a commit with a descriptive message"
Codex will review the changes, write an appropriate commit message, and create the commit.
Working with Branches
codex "create a new branch called feature/user-profile, make the changes there, and commit"
Or work on an existing branch:
codex "switch to the develop branch, pull the latest changes, and show me what's new"
Creating Pull Requests
codex "create a pull request for the current branch with a summary of all the changes"
Codex will generate a PR title and description based on the actual code changes in the branch.
Reviewing Changes
codex "show me a summary of all uncommitted changes and explain what each change does"
This is helpful before committing, especially if you have been working in Auto Edit or Full Auto mode and want to review what Codex changed.
Complete Development Workflows
The real power comes from chaining these capabilities together. Here are practical workflows:
The "Fix and Ship" Workflow
codex "fix the failing tests in the auth module, make sure all tests pass, then commit with a descriptive message"
The "Feature Branch" Workflow
codex "create a branch called feature/email-notifications, add an email notification service that sends a welcome email when a user registers, write tests for it, run the tests, and commit if they pass"
The "Code Review Prep" Workflow
codex "review all changes on this branch compared to main, check for any obvious bugs or missing error handling, fix any issues you find, and run the full test suite"
The "Dependency Update" Workflow
codex "update all npm dependencies to their latest versions, run the tests, and fix any breaking changes"
Tips for Effective Test and Debug Workflows
Always have tests before using Full Auto mode. Tests are your safety net. If Codex makes a mistake in Full Auto mode, the test suite catches it before the change is committed.
Give Codex the error output. When debugging, include the actual error message or stack trace. The more context you provide, the faster Codex identifies the root cause.
Use git as your safety net. Always work in a git repository. If Codex makes changes you do not like, git checkout . reverts everything.
Chain tasks intentionally. Combine related tasks (write code, test, commit) into a single prompt for smoother workflows. But keep unrelated tasks separate for easier review.
Key Takeaways
- Codex automatically identifies your test framework and runs the appropriate commands
- For debugging, give Codex the actual error message or stack trace for fastest resolution
- Codex can handle the full git workflow: branches, commits, and pull requests
- Chain tasks together for complete workflows: write code, test, fix, commit
- Always work in a git repository so you can revert changes if needed
- Tests are your safety net, especially in Auto Edit and Full Auto modes
- Review changes with
git diffbefore committing, particularly after autonomous operations

