Codex CLI Skills
Skills are Codex CLI's extension mechanism, allowing you to create custom workflows and automation tasks. With skills, you can define how Codex behaves in specific scenarios.
What are skills?
A skill is a configurable behavior pattern that tells Codex how to handle a specific type of task. You can create your own skills to:

- Automate common development tasks
- Define domain-specific processes
- Customize code review standards
- Create project-specific templates and rules
The skill system lets Codex adapt to different projects and workflows, as if you had assigned a dedicated development assistant to your team.
Skill directories
Codex loads skills from the following locations:
| Position | Description |
|---|---|
~/.codex/skills/ |
The global skill directory, available to all projects |
{项目目录}/.codex/skills/ |
The project-level skill directory |
配置指定的目录 |
Specified via skills.directory in config.toml |
Configure the skill directory
Customize the skill directory
[skills]
enabled = true
directory = "~/my-codex-skills"
Skill file structure
Each skill is a separate folder containing the following files:
skill-name/
├── skill.md # 技能定义文件(必需)
└── (可选的辅助文件)
The skill.md file format
Example skill definition
name: Code Review
description: Perform an in-depth code review and provide improvement suggestions
trigger: /review
Code Review Skill
When the user requests a code review, perform the following steps:
Review criteria
Code Readability
Performance Issues
Security risks
Adherence to best practices
Test coverage
Output formats
Provide the following structured report:
List of issues (sorted by severity)
Improvement suggestions
Code rating (1-10)
Skill metadata
The beginning of each skill file must contain metadata in YAML format:
| Field | Type | Description | Required |
|---|---|---|---|
name |
string | Skill names | Is |
description |
string | Skill description | Is |
trigger |
string | Trigger keywords | No |
When your input matches a skill's trigger, Codex automatically uses that skill to handle the task.
Create a custom skill
Let's create a simple skill as an example:
Step 1: Create the skill directory
Create the skill folder
mkdir
-p
~
/
.codex
/
skills
/
Generate Tests
Step 2: Write the skill definition
Create skill.md
name: Generate Tests
description: Generate unit tests for code
trigger: test
Generate Tests Skill
When the user requests test generation, perform the following steps:
Step
Analyze the functionality of the existing code
Identify edge cases that need testing
Choose an appropriate testing framework
Generate test cases
Testing standards
Coverage should include normal cases, edge cases, and error cases
Each test case should be independent and not rely on the execution order of other tests
Use clear test function names
Output formats
Generate test code that can be run directly and includes the necessary test data.
Step 3: Use the skill
Now, when you type something related to "tests", Codex automatically uses this skill:
Trigger the skill
These inputs trigger the "Generate Tests" skill
Help me generate tests for this function
Please test this module
Built-in skills
Codex comes with several common skills:
| Skill names | Trigger words | Description |
|---|---|---|
| Code review | review, review | Perform a code review and provide improvement suggestions |
| Debugging | debug, debug | Help locate and fix issues |
| Refactor | refactor, refactor | Optimize code structure without changing functionality |
| Document | doc, documentation | Generate code documentation |
You can override the behavior of built-in skills and create versions that fit your project's needs.
Skill priority
When multiple skills match, Codex selects by the following priority:
- Exact match (identical trigger word)
- Contains match (input contains the trigger word)
- Semantic match (AI determines relevance)
Force the use of a specific skill
You can force the use of a skill with a slash command:
Force a skill
Use the skill command
@
skill-name your task description
Advanced skill configuration
Conditional triggering
You can configure skills to trigger under specific conditions:
Conditional trigger example
name: Python Skill
description: Python project-specific handling
trigger: python
when:
file_pattern: "*.py"
directory: "src/"
Python Project Skill
This skill only takes effect when working with Python files.
Multi-step tasks
Skills can define complex multi-step workflows:
Multi-step Skill
name: Full Feature Development
description: Full process from requirements to implementation
trigger: develop feature
Full Feature Development Process
Phase 1: Requirements analysis
Understand the feature requirements
Identify edge cases
Design data structures
Phase 2: Design
Design function/class structures
Define interfaces
Choose algorithms
Phase 3: Implementation
Write the code
Add comments
Write documentation
Phase 4: Testing
Write unit tests
Verify edge cases
Check coverage
Phase 5: Commit
Create a Git commit
Write the commit message
Skill best practices
Naming Convention
- Use clear, descriptive names
- The name should express the skill's function
- Avoid Chinese names (they may cause encoding issues)
Trigger word selection
- Choose commonly used keywords
- Avoid overly broad trigger words
- Consider how users naturally express themselves
Skill granularity
- Keep each skill's responsibility single-purpose
- One skill solves one class of problems
- Complex workflows can be achieved by combining skills
A good skill should make users feel that "Codex understands my needs", rather than requiring them to learn special syntax.
Manage skills
List available skills
View the skill list
Type in Codex
/
skills
Disable a skill
If you don't want to use a skill, you can delete its file or move it to another directory.
Update a skill
After modifying a skill file, you need to restart Codex for the changes to take effect.
Skill example library
OpenAI officially provides some prebuilt skills for your reference and use:
Visit the GitHub repository to see more examples:https://github.com/openai/codex/tree/main/skills
Common questions
Q: A skill isn't triggering?
Check that the skill file's metadata format is correct, ensure the YAML header is well-formed, and that the file ends with .md a proper closing delimiter.
Q: How do I debug a skill?
You can use the /debug command in Codex to view detailed information about skill matching.
Q: Do skills affect Codex's normal behavior?
Skills only provide guidelines; Codex still makes independent judgments. If a skill is poorly configured, Codex will use its default behavior.