Claude-skill-registry codex-invocation
Invoke OpenAI Codex CLI with the correct configuration for autonomous code generation. Use when you need Codex to generate or regenerate code files, implement features, or execute multi-step coding tasks.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/codex-invocation" ~/.claude/skills/majiayu000-claude-skill-registry-codex-invocation && rm -rf "$T"
skills/data/codex-invocation/SKILL.mdCodex Invocation Skill
Invoke OpenAI Codex CLI (gpt-5.1-codex) with proper configuration for autonomous code generation and file creation.
When to Use This Skill
- Generating complete code files from specifications
- Implementing complex features autonomously
- Regenerating code with specific requirements
- Executing multi-step coding tasks that require deep reasoning
- When the user explicitly requests Codex to implement something
Core Concepts
Codex CLI Configuration
Model Selection:
: Latest Codex model with extended reasoning capabilitiesgpt-5.1-codex- Use with
for production-quality codemodel_reasoning_effort="high"
Sandbox Modes:
: Codex can read files but not modify themread-only
: Codex can write files within the workspaceworkspace-write
: Full system access (required for most code generation)danger-full-access
Approval Policy:
: Codex must ask before running commandsuntrusted
: Ask only if commands failon-failure
: Codex decides when to askon-request
: Fully autonomous (use with caution)never
Essential Flags
codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Your prompt here"
Flag Breakdown:
: Use the GPT-5.1 Codex model-m gpt-5.1-codex
: Enable--dangerously-bypass-approvals-and-sandbox
sandbox anddanger-full-access
approval policynever
: Enable extended reasoning for better code quality-c model_reasoning_effort="high"- Final argument: The prompt/instruction for Codex
Pattern 1: Basic Codex Invocation
# Simple task with high reasoning codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Implement the login form component in src/components/LoginForm.tsx with email and password validation."
Pattern 2: Multi-File Implementation from Specification
# Complex implementation from a prompt file codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Implement Phase 2 as specified in CODEX_PHASE_2_PROMPT.md. Create all required files: errors.ts, cache.ts, and all query files (servers.ts, parts.ts, compatibility.ts, builds.ts). Follow all specifications exactly."
Pattern 3: Background Execution with Monitoring
# Run Codex in background and monitor output codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Your prompt here" & # Monitor using Claude's BashOutput tool # Use the process ID returned to check progress
Pattern 4: Referencing Skills in Prompts
When creating prompts for Codex, reference relevant Claude skills for guidance:
**Relevant Skills to Reference:** - `.claude/skills/api-design-principles/` - REST API design patterns - `.claude/skills/database-migration/` - Migration best practices - `.claude/skills/sql-optimization-patterns/` - Query optimization - `.claude/skills/modern-javascript-patterns/` - TypeScript patterns
This tells Codex to follow the patterns and best practices from these skill files.
Common Use Cases
1. Implementing Database Query Layer
codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Create TypeScript database query functions in src/lib/queries/ following the specification in SPEC.md. Include: - Type-safe Supabase queries - React cache wrapping - Error handling - JSDoc documentation"
2. Adding Bonus Features to Existing Code
codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Enhance the query files in src/lib/queries/ with these features: 1. Add comprehensive JSDoc documentation 2. Add pagination support 3. Add query logging 4. Add performance monitoring Follow the bonus features section in CODEX_PHASE_2_PROMPT.md"
3. Generating API Routes
codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Create Next.js 14 App Router API routes in src/app/api/ for: - GET /api/servers - List servers with filtering - GET /api/servers/[id] - Get server by ID - POST /api/builds - Create new build Follow REST API best practices from .claude/skills/api-design-principles/"
Best Practices
1. Clear, Specific Prompts
- Specify exact file paths
- Include expected behavior
- Reference specification files
- List all required features
2. Reference Specifications
- Create detailed prompt files (e.g., CODEX_PHASE_2_PROMPT.md)
- Reference existing Claude skills for patterns
- Include code examples when needed
3. Monitor Long-Running Tasks
// Use Claude's Bash tool to run Codex await bash({ command: 'codex exec -m gpt-5.1-codex --dangerously-bypass-approvals-and-sandbox -c model_reasoning_effort="high" "prompt"', run_in_background: true }); // Monitor progress await bashOutput({ bash_id: "process-id" });
4. Verify Output
After Codex completes:
- Check all files were created
- Verify TypeScript compilation
- Run tests
- Review for bonus features
- Check for proper error handling
Troubleshooting
Windows Shell Issues
If you encounter DLL initialization errors (0xC0000142):
# Kill hung processes taskkill /F /IM node.exe /T taskkill /F /IM powershell.exe /T taskkill /F /IM cmd.exe /T # Test shell works powershell -Command "echo ok" # Then retry Codex
Codex Not Creating Files
Ensure you're using the correct sandbox mode:
for full write access--dangerously-bypass-approvals-and-sandbox- Or explicitly set:
--sandbox danger-full-access
Low Quality Output
Increase reasoning effort:
- Use
for production code-c model_reasoning_effort="high" - Default is "medium" which may skip important details
Skills Referenced in Prompts
When creating Codex prompts, these skills provide excellent guidance:
- api-design-principles - REST and GraphQL API design patterns
- database-migration - Database migration best practices
- sql-optimization-patterns - Query optimization and indexing
- modern-javascript-patterns - ES6+ and TypeScript patterns
- react-modernization - React hooks and modern patterns
- frontend-design - UI component design principles
Example: Complete Codex Workflow
# 1. Create specification file cat > CODEX_TASK.md << 'EOF' ## Task: Implement User Authentication Create a complete authentication system: **Files to Create:** - src/lib/auth.ts - Auth utilities - src/app/api/auth/login/route.ts - Login endpoint - src/app/api/auth/logout/route.ts - Logout endpoint - src/components/LoginForm.tsx - Login UI **Requirements:** - Use JWT tokens - Hash passwords with bcrypt - Implement CSRF protection - Add rate limiting - Follow .claude/skills/api-design-principles/ **Bonus Features:** - Add JSDoc documentation - Add error handling - Add input validation - Add unit tests EOF # 2. Invoke Codex codex exec \ -m gpt-5.1-codex \ --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Implement the authentication system as specified in CODEX_TASK.md. Include all bonus features." # 3. Verify output npm run type-check npm test
Advanced: Iterative Refinement
# First pass - basic implementation codex exec -m gpt-5.1-codex --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Create basic query functions in src/lib/queries/" # Second pass - add enhancements codex exec -m gpt-5.1-codex --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Enhance src/lib/queries/*.ts with: - Comprehensive JSDoc - Pagination - Error handling - Performance monitoring" # Third pass - add tests codex exec -m gpt-5.1-codex --dangerously-bypass-approvals-and-sandbox \ -c model_reasoning_effort="high" \ "Create unit tests for all query functions in src/lib/__tests__/"
Summary
Use this skill to invoke Codex with the correct configuration for autonomous code generation. Always:
- Use
modelgpt-5.1-codex - Use
for write access--dangerously-bypass-approvals-and-sandbox - Use
for quality output-c model_reasoning_effort="high" - Create detailed specification files
- Reference relevant Claude skills in prompts
- Monitor long-running tasks
- Verify output after completion