Codex Workflows
Codex can be integrated into various development workflows, from daily coding to complex refactoring, significantly improving efficiency.
* * *
## Daily Development Workflow
Daily development is the most common workflow pattern, suitable for building new features or making small-scale modifications.
### Workflow Steps
| Step | Action | Codex Interaction |
| --- | --- | --- |
| 1 | Clarify Requirements | Describe the functionality you want to implement |
| 2 | Codex Analysis | Codex understands project structure and specifications |
| 3 | Solution Discussion | Confirm implementation plan with Codex |
| 4 | Code Generation | Codex writes code and modifies files |
| 5 | Verification Testing | Run tests to confirm functionality is correct |
| 6 | Iteration & Optimization | Adjust code based on feedback |
### Example: Adding a New API Endpoint
## Daily Development Process
# Step 1: Describe Requirements
"Add a GET endpoint at /api/users path that returns user list,
supporting pagination parameters page and limit"
# Step 2-3: Codex Analysis and Confirm Plan
Codex will analyze existing API structure, confirming:
- Route definition location
- Database query method
- Response format specification
# Step 4: Code Generation
Codex automatically creates:
- Route definitions
- Data query logic
- Error handling
- Response formatting
# Step 5: Verification Testing
"Run tests and check the new endpoint"
# Step 6: Iteration & Optimization
"Add cache support, response time should be less than 100ms"
* * *
## Code Understanding Workflow
Use this workflow when you need to understand legacy code or unfamiliar projects.
### Exploratory Workflow
1. Start from the entry point, have Codex explain the overall architecture
2. Gradually dive into key modules to understand core logic
3. Trace data flow and call chains
4. Summarize key points and considerations
## Understanding Legacy Projects
# Overall Architecture
"Analyze this project's overall architecture, explain the main modules and their relationships"
# Core Module
"Explain how the src/auth module works, including authentication flow and permission checks"
# Data Flow Tracing
"Trace the complete flow from request to response after user login"
# Key Summary
"Summarize the core design patterns of this project and things to pay attention to"
### Quick Start New Project
## New Project Getting Started Guide
# Project Overview
"What is this project? What are its main features and tech stack?"
# Development Guide
"How to start local development environment? How to run tests?"
# Code Standards
"What are the code standards for this project? Any conventions?"
# Module Navigation
"If I want to add feature X, which files should I modify?"
* * *
## Refactoring Workflow
Refactoring requires careful handling, Codex can help you systematically improve code structure.
### Refactoring Principles
* Understand existing code structure first
* Small-step refactoring, gradual improvement
* Verify each step to ensure functionality remains unchanged
* Maintain test coverage
### Refactoring Workflow Steps
| Step | Description |
| --- | --- |
| **Identify Issues** | Codex analyzes code to identify parts needing improvement |
| **Plan Solution** | Discuss refactoring plan, confirm improvement direction |
| **Execute in Steps** | Small-scale modifications, verify after each change |
| **Test Verification** | Run all tests to ensure functionality is correct |
| **Cleanup & Optimize** | Remove redundant code, optimize naming |
## Refactoring Example
# Identify Issues
"Analyze src/utils module, identify code duplication and unreasonable design"
# Plan Solution
"Discuss how to refactor this module while maintaining backward compatibility"
# Execute in Steps
"Step 1: Extract common functions to utils/common.py"
# Test Verification
"Run all tests, confirm refactoring didn't break functionality"
# Continue to Next Step
"Step 2: Simplify complex functions, split into smaller units"
> Use /plan mode to create a plan first when refactoring, then execute in steps to avoid large one-time changes.
* * *
## Bug Fix Workflow
Codex can help you quickly locate and fix bugs.
### Fix Process
| Step | Action |
| --- | --- |
| **Describe Problem** | Explain bug manifestation and trigger conditions |
| **Provide Information** | Share error messages, logs, screenshots |
| **Locate Root Cause** | Codex analyzes and finds the root cause |
| **Generate Fix** | Codex proposes a fix |
| **Verify Fix** | Run tests to confirm the issue is resolved |
| **Prevent Recurrence** | add test coverage for this scenario |
## Bug Fix Example
# Describe Problem
"Users occasionally get 500 error during login, error log shows:
TypeError: Cannot read property 'id' of undefined"
# Provide Information
"Here is the full error stack: "
# Locate Root Cause
Codex analysis found the issue: user object is null in some cases
# Generate Fix
"Fix this issue, ensuring it doesn't affect normal login flow"
# Verify Fix
"Run all login-related tests"
# Prevent Recurrence
"Add a test covering the scenario where user object is null"
### Screenshot-Assisted Debugging
Use screenshots to help Codex understand the issue:
## Image Input
# Attach Screenshot in CLI
codex -i error-screenshot.png "Explain this error and fix it"
# Paste Screenshot in IDE
Paste screenshot directly in conversation, describe the problem
* * *
## Code Review Workflow
Codex can review code changes, find issues and provide improvement suggestions.
### Review Modes
| Mode | Trigger | Applicable Scenario |
| --- | --- | --- |
| **Review Mode** | Enabled in App | Review local uncommitted changes |
| **/review Command** | Used in CLI/IDE | Review specified range changes |
| **GitHub Integration** | @codex review in PR | Review Pull Request |
### Local Review
## Review Mode
# Enable Review Mode in App
Click the eye icon in toolbar
# Or use in CLI
/review
# Specify Review Scope
/review src/auth/
# Review 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 Feature
"Write unit tests for the GET endpoint in src/api/users.py,
covering normal responses, empty lists, pagination boundaries, etc."
# Verify Tests
"Run the newly written tests"
# Supplement Coverage
"Check test coverage, supplement uncovered edge cases"
### Test Fixing
## Fix Failing Tests
# Analyze Failing Tests
"Test test_user_login failed, analyze the reason and fix it"
# Batch Fix
"Run all tests, fix the failing tests"
* * *
## Documentation Generation Workflow
Codex can help generate and update documentation.
### Generate Documentation
## Documentation Generation
# API Documentation
"Generate API documentation for src/api module, including request format and response format for each endpoint"
# README Update
"Update README.md, add description and usage examples for new features"
# Inline Comments
"Add comments to complex functions, explain key logic"
* * *
## Best Practices
### Workflow Selection
* Daily Development: Continuous interaction, gradual refinement
* Refactoring: Plan first then execute, verify in small steps
* Bug Fix: Provide sufficient information, verify root cause
* Review: Conduct regularly, focus on security issues
### Efficiency Tips
* Use AGENTS.md to define project specifications, reduce repeated explanations
* Use Skills to encapsulate common workflows
* Use Worktree to isolate different tasks
* Configure reasonable Approval strategies
* * *
## FAQ
### Q: How to handle large-scale refactoring?
Use /plan mode to create step-by-step plans, verify after each step.
### Q: How to prevent bug recurrence after fixing?
Add dedicated test coverage for that scenario, and add relevant check rules in AGENTS.md.
### Q: How to make Codex understand project specifications?
Create AGENTS.md file to define project's tech stack, code standards, testing requirements, etc.
### Q: How to share review results with the team?
Use GitHub integration to review in PR, results will automatically be added as comments.
YouTip