Codex Workflow Modes
Codex fits into a variety of development workflows, from daily coding to complex refactoring, significantly improving efficiency.
Daily Development Workflow
Daily development is the most common workflow mode, suitable for building new features or making small-scale changes.
Workflow Steps
| Step | Operation | Codex Interaction |
|---|---|---|
| 1 | Clarify Requirements | Describe the feature you want to implement |
| 2 | Codex Analysis | Codex understands the project structure and conventions |
| 3 | Plan Discussion | Confirm the implementation plan with Codex |
| 4 | Code generation | Codex writes code and modifies files |
| 5 | Verification Testing | Run tests to confirm the feature works correctly |
| 6 | Iterative Optimization | Adjust the code based on feedback |
Example: Adding a New API Endpoint
Daily Development Flow
Step 1: Describe the Requirements
"Add a GET endpoint at the /api/users path that returns a list of users,
supporting pagination parameters page and limit"
Steps 2-3: Codex Analyzes and Confirms the Plan
Codex analyzes the existing API structure and confirms:
-
Where routes are defined
-
How database queries are performed
-
Response format conventions
Step 4: Code Generation
Codex automatically creates:
-
Route Definition
-
Data query logic
-
Error handling
-
Response formatting
Step 5: Verification Testing
"Run tests and check the new endpoint"
Step 6: Iterative Refinement
"Add caching support; response time should be less than 100ms"
Code Comprehension Workflow
Use this workflow when you need to understand legacy code or an unfamiliar project.
Exploratory Workflow
- Start from entry points and have Codex explain the overall architecture
- Drill down into key modules step by step to understand the core logic
- Trace data flow and call chains
- Summarize key points and things to note
Understanding a Legacy Project
Overall architecture
"Analyze the overall architecture of this project and explain the main modules and their relationships"
Core modules
"Explain how the src/auth module works, including the authentication flow and permission checks"
Data Flow Tracing
"Trace the complete flow from request to response after a user logs in"
Key Takeaways
"Summarize the core design patterns of this project and things to watch out for"
Quick start with a new project
New project onboarding guide
Project overview
"What is this project? What are its main features and tech stack?"
Development guide
"How do I set up the development environment locally? How do I run tests?"
Code Standards
"What are the coding standards of this project? Are there any conventions?"
Module navigation
"If I want to add feature X, which files should I modify?"
Refactoring workflow
Refactoring requires careful handling, and Codex can help you systematically improve your code structure.
Refactoring principles
- Understand the existing code structure first
- Refactor in small steps, improve gradually
- Verify each step to ensure functionality remains unchanged
- Maintain test coverage
Refactoring workflow steps
| Step | Description |
|---|---|
| Identify issues | Codex analyzes the code and identifies parts that need improvement |
| Devise a plan | Discuss the refactoring plan and confirm the direction of improvement |
| Execute step by step | Make small-scale changes and verify after each change |
| Test and verify | Run all tests to ensure correctness |
| Clean up and optimize | Remove redundant code and improve naming |
Refactoring example
Identify issues
"Analyze the src/utils module and identify code duplication and unreasonable designs"
Devise a plan
"Discuss how to refactor this module while maintaining backward compatibility"
Execute step by step
"Step 1: Extract common functions into utils/common.py"
Test and verify
"Run all tests to confirm the refactoring didn't break functionality"
Continue to the next step
"Step 2: Simplify complex functions and split them into smaller units"
When refactoring, use /plan mode to make a plan first, then execute step by step to avoid large one-time changes.
Bug fixing workflow
Codex can help you quickly locate and fix bugs.
Fixing process
| Step | Operation |
|---|---|
| Describe the problem | Describe the bug's symptoms and trigger conditions |
| Provide information | Share error messages, logs, and screenshots |
| Locate the root cause | Codex analyzes and finds the root cause |
| Generate a fix | Codex proposes a fix |
| Verify the fix | Run tests to confirm the issue is resolved |
| Prevent recurrence | Add a test to cover that scenario |
Bug fixing example
Describe the problem
"Users occasionally get a 500 error when logging in, and the error log shows:
TypeError: Cannot read property 'id' of undefined"
Provide information
"This is the full error stack trace: [paste stack information]"
Locate the root cause
After analysis, Codex found the issue: the user object is null in certain cases
Generate a fix
"Fix this issue and make sure it doesn't affect the normal login flow"
Verify the fix
"Run all tests related to login"
Prevent recurrence
"Add a test covering the scenario where the user object is null"
Screenshot-assisted debugging
Use screenshots to help Codex understand the problem:
Image input
Attach a screenshot in the CLI
codex
-i
error-screenshot.png
"Explain this error and fix it"
Paste a screenshot in the IDE
Paste the screenshot directly in the conversation and describe the problem
Code review workflow
Codex can review code changes, find issues, and provide improvement suggestions.
Review mode
| Mode | Trigger Method | Applicable scenarios |
|---|---|---|
| Review Mode | Enable in the app | Review local uncommitted changes |
| /review command | Use in CLI/IDE | Review changes in a specified scope |
| GitHub Integration | @codex review in a PR | Review a pull request |
Local review
Review Mode
Enable Review Mode in the app
Click the eye icon in the toolbar
Or use it in the CLI
/
review
Specify the review scope
/
review src
/
auth
/
Review a specific commit
/
review HEAD~
3
..HEAD
Customize review focus
Specify Review Focus
Security review
/
review
for
security issues
Performance review
/
review
for
performance regressions
Code Style
/
review
for
code style consistency
Comprehensive review
/
review
--detailed
Test writing workflow
Codex can help you write and maintain test code.
New feature testing
Writing tests
Write tests for new features
"Write unit tests for the GET endpoint of src/api/users.py,
covering scenarios such as normal responses, empty lists, and pagination boundaries"
Verification Testing
"Run the newly written tests"
Supplement coverage
"Check test coverage and add uncovered edge cases"
Test fixing
Fix failing tests
Analyze failing tests
"The test test_user_login failed; analyze the cause and fix it"
Batch fixing
"Run all tests and fix the failing ones"
Documentation generation workflow
Codex can help generate and update documentation.
Generate documentation
Documentation generation
API Documentation
"Generate API documentation for the src/api module, including the request and response formats of each endpoint"
README update
"Update README.md to add descriptions and usage examples of the new features"
Inline comments
"Add comments to complex functions to explain the key logic"
Best Practices
Workflow selection
- Daily development: continuous interaction, gradual improvement
- Refactoring: plan first, then execute, verify in small steps
- Bug fixing: provide sufficient information, verify the root cause
- Review: do it regularly, focus on security issues
Efficiency tips
- Use AGENTS.md to define project conventions and reduce repeated explanations
- Use Skills to encapsulate common workflows
- Use worktrees to isolate different tasks
- Configure a reasonable approval policy
Common questions
Q: How do I handle large-scale refactoring?
Use /plan mode to create a step-by-step plan and verify after each step.
Q: How do I prevent recurrence after fixing a bug?
Add dedicated tests to cover that scenario and add relevant checking rules in AGENTS.md.
Q: How do I make Codex understand project conventions?
Create an AGENTS.md file defining the project's tech stack, coding standards, testing requirements, and more.
Q: How do I share review results with the team?
Use GitHub integration to review in PRs; results are automatically added as comments.