5.3 KiB
Basic Usage Examples
⚠️ CRITICAL: Always Use codex exec
ALL commands in this document use codex exec - this is mandatory in Claude Code.
❌ NEVER: codex -m ... (will fail with "stdout is not a terminal")
✅ ALWAYS: codex exec -m ... (correct non-interactive mode)
Claude Code's bash environment is non-terminal. Plain codex commands will NOT work.
Example 1: General Reasoning Task - Queue Design
User Request
"Help me design a queue data structure in Python"
What Happens
- Claude detects the coding task (queue design)
- Skill is invoked autonomously
- Codex CLI is called with gpt-5.1 (general high-reasoning model):
codex exec -m gpt-5.1 -s read-only \
-c model_reasoning_effort=high \
"Help me design a queue data structure in Python"
- Codex responds with high-reasoning architectural guidance on queue design
- Session is auto-saved for potential continuation
Expected Output
Codex provides:
- Queue design principles and trade-offs
- Multiple implementation approaches (list-based, deque, linked-list)
- Performance characteristics (O(1) enqueue/dequeue)
- Thread-safety considerations
- Usage examples and best practices
Example 2: Code Editing Task - Implement Queue
User Request
"Edit my Python file to implement the queue with thread-safety"
What Happens
- Skill detects code editing request
- Uses gpt-5.1-codex-max (maximum capability for coding - 27-42% faster):
codex exec -m gpt-5.1-codex-max -s workspace-write \
-c model_reasoning_effort=high \
"Edit my Python file to implement the queue with thread-safety"
- Codex performs code editing with maximum capability model
- Files are modified (workspace-write sandbox)
Expected Output
Codex:
- Edits the target Python file
- Implements thread-safe queue using
threading.Lock - Adds proper synchronization primitives
- Includes docstrings and type hints
- Provides usage examples
Example 3: Explicit Codex Request
User Request
"Use Codex to design a REST API for a blog system"
What Happens
- Explicit "Codex" mention triggers skill
- Codex invoked with coding-optimized settings:
codex exec -m gpt-5.1 -s read-only \
-c model_reasoning_effort=high \
"Design a REST API for a blog system"
- High-reasoning analysis provides comprehensive API design
Expected Output
Codex delivers:
- RESTful endpoint design (GET/POST/PUT/DELETE)
- Resource modeling (posts, authors, comments)
- Authentication and authorization strategy
- Data validation approaches
- API versioning recommendations
- Error handling patterns
Example 4: Complex Algorithm Design
User Request
"Help me implement a binary search tree with balancing"
What Happens
codex exec -m gpt-5.1 -s read-only \
-c model_reasoning_effort=high \
"Help me implement a binary search tree with balancing"
Expected Output
Codex provides:
- BST fundamentals and invariants
- AVL vs Red-Black tree trade-offs
- Rotation algorithms (left, right, left-right, right-left)
- Insertion and deletion with rebalancing
- Complexity analysis
- Implementation guidance
Example 5: Maximum Reasoning with xhigh
User Request
"Refactor the authentication system with comprehensive security improvements"
What Happens
codex exec -m gpt-5.1-codex-max -s workspace-write \
-c model_reasoning_effort=xhigh \
"Refactor the authentication system with comprehensive security improvements"
Expected Output
Codex provides:
- Deep architectural analysis of current system
- Comprehensive security vulnerability assessment
- Multi-layered refactoring strategy
- Implementation of security best practices
- Detailed reasoning about trade-offs
- Long-horizon planning for complex changes
When to use xhigh: Complex architectural refactoring, security-critical changes, long-horizon tasks where quality is more important than speed.
Model Selection Summary
| Task Type | Model | Sandbox | Example |
|---|---|---|---|
| General reasoning | gpt-5.1 |
read-only |
"Design a queue" |
| Architecture design | gpt-5.1 |
read-only |
"Design REST API" |
| Code review | gpt-5.1 |
read-only |
"Review this code" |
| Code editing (standard) | gpt-5.1-codex-max |
workspace-write |
"Edit file to add X" |
| Code editing (maximum reasoning) | gpt-5.1-codex-max + xhigh |
workspace-write |
"Complex refactoring" |
| Implementation | gpt-5.1-codex-max |
workspace-write |
"Implement function Y" |
| Backward compatibility | gpt-5.1-codex |
workspace-write |
"Use standard model" |
Note: gpt-5.1-codex-max is 27-42% faster than gpt-5.1-codex and uses ~30% fewer thinking tokens. It supports a new xhigh reasoning effort level for maximum capability.
Tips for Best Results
- Be specific in your requests - detailed prompts get better reasoning
- Indicate task type clearly (design vs. implementation)
- Mention permissions when you need file writes ("allow file writing")
- Use continuation for iterative development (see session-continuation.md)
Next Steps
- Continue a session: See session-continuation.md
- Advanced config: See advanced-config.md
- Full documentation: See ../SKILL.md