| name | codex-exec |
| description | Execute development tasks using OpenAI Codex CLI for code generation, refactoring, feature implementation, and bug fixes. Use when the user asks to create code, add features, refactor, fix bugs, or generate tests. Requires Codex CLI installed. |
| allowed-tools | Bash, Read, Write, Edit, Grep, Glob |
Codex Exec Skill
Use OpenAI Codex CLI to execute development tasks that involve code modifications. This skill modifies code.
When to Use
- User asks to "add", "create", "implement", or "generate" code
- User wants to refactor existing code
- User needs to fix a bug
- User wants to create tests
- User asks to "update" or "modify" code
Prerequisites
Verify Codex CLI is available:
codex --version # Should display installed version
Basic Usage
Step 1: Understand the Task
Parse what needs to be done:
- What to create/modify?
- Which files are affected?
- What's the expected outcome?
- Any constraints or requirements?
Step 2: Gather Context
Before executing, understand current state:
git status # Check for uncommitted changes
git diff # See existing modifications
Read relevant files to understand patterns.
Step 3: Execute Codex
Run Codex with clear instructions:
codex exec "[TASK]
Follow these guidelines:
- Follow existing code patterns and conventions
- Add appropriate error handling
- Include necessary imports
- Maintain code quality and readability
- Use TypeScript types where applicable
- Add comments for complex logic
Project context:
- Language: [e.g., TypeScript, Python, Go, Rust]
- Framework: [e.g., React, Django, Express]
- Build tool: [e.g., Vite, webpack, cargo, go build]
- Coding style: [Reference style guide or linter config]"
Step 4: Verify Changes
After execution:
git status # See what changed
git diff # Review modifications
<lint-command> # Check for errors
<test-command> # Run tests
Step 5: Report Results
Provide clear summary:
- What files were modified/created
- What changes were made
- Verification results (lint, types, tests)
- Any issues or warnings
Example Tasks
Generate New Code
codex exec "Create a UserProfile component in src/components/ with:
- Props: name (string), email (string), avatar (string optional)
- Display user info in a card layout
- Use TypeScript types
- Follow existing component patterns
- Add CSS modules for styling"
Refactor Code
codex exec "Refactor the validation logic in src/components/LoginForm.tsx:
- Extract validation into separate src/utils/validation.ts file
- Create validateEmail and validatePassword functions
- Maintain all existing functionality
- Add TypeScript types"
Fix Bugs
codex exec "Fix the memory leak in src/hooks/useWebSocket.ts:
- The WebSocket connection is not being cleaned up
- Add proper cleanup in useEffect return function
- Ensure connection closes on unmount"
Add Features
codex exec "Add email validation to ContactForm.tsx:
- Use regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/
- Show error message below input field
- Validate on blur and submit
- Prevent submission if invalid
- Style error message in red"
Create Tests
codex exec "Create unit tests for src/utils/validation.ts:
- Test validateEmail with valid/invalid inputs
- Test validatePassword with edge cases
- Test error messages
- Use Jest and React Testing Library
- Aim for 100% coverage"
Execution Modes
Safe Mode (Default)
codex exec "[TASK]"
# Prompts for approval before each action
Preview Mode
codex exec "[TASK]" --dry-run
# Shows what would be done without executing
Automated Mode ⚠️
codex exec "[TASK]" --yes
# Auto-approves all actions - use with caution!
Only use --yes for:
- Low-risk tasks (formatting, comments)
- Isolated environments
- Well-tested operations
Never use --yes for:
- Production code
- Security-sensitive changes
- Database operations
- File deletions
Verification Workflow
After Codex executes, ALWAYS:
Review changes:
git diffRun linter:
<lint-command>Run tests:
<test-command>Manual testing:
Start your development server and test the functionality manually.
Report status:
- ✅ Changes applied successfully
- ✅ Linter passed
- ✅ Tests passed
- ✅ Manual testing confirmed
Best Practices
✅ DO:
- Be specific in task descriptions
- Include file paths
- Specify expected behavior
- Review all changes with
git diff - Run linter and tests
- Test manually before declaring success
❌ DON'T:
- Use vague instructions like "make it better"
- Skip verification steps
- Use
--yesfor critical code - Commit without reviewing
- Ignore errors or warnings
Error Handling
If execution fails:
- Check the error message
- Verify Codex authentication
- Try with more specific instructions
- Break task into smaller steps
If changes are incorrect:
- Revert:
git restore .orgit restore <file> - Re-execute with better instructions
- Or fix manually
If tests fail:
- Review what broke
- Ask Codex to fix the test failures
- Or fix manually
Writing Effective Tasks
Good Task Description
"Add email validation to ContactForm.tsx using regex pattern.
Show error message below the input field on blur.
Prevent form submission if email is invalid.
Style the error message in red (#dc2626).
Follow existing form validation patterns."
Poor Task Description
"Add validation" # Too vague
"Fix the form" # No specifics
Safety Checklist
Before using codex-exec:
- Understand what will be modified
- Have clean git state (can rollback)
- Know which files will be affected
- Have tests to verify correctness
After using codex-exec:
- Reviewed changes with
git diff - Ran linter (language-specific)
- Ran type checker (if applicable)
- Ran tests (language-specific)
- Tested manually
- Ready to commit
Related Skills
- codex-ask: For understanding code before modifying
- codex-review: For reviewing changes after modification
Tips for Success
- Start small: Test with simple tasks first
- Be specific: Include file paths, requirements, constraints
- Follow patterns: Reference existing code to follow
- Verify always: Never skip the verification workflow
- Iterate: Use codex-ask → codex-exec → codex-review cycle
Limitations
- Cannot run code or execute tests itself
- May not understand complex business logic
- Limited by context window size
- Requires manual verification
- Cannot guarantee correctness
Remember: This skill MODIFIES code. Always review changes before committing!