Hooks, rules and customization
Instructions, prompts, memories, hooks, rules, imports, skills and subagents.
Customization has three layers: instructions explain how to work, controls constrain permitted behavior, and tools connect data and actions.
| Layer | Purpose | Files or entry points |
|---|---|---|
| Instructions | Rules, style, workflow and completion criteria | AGENTS.md, prompts, memories, skills |
| Controls | Commands, approvals and lifecycle enforcement | Rules, hooks, sandbox, approvals |
| Tools | External data and operations | MCP, plugins and connectors |
#AGENTS.md
Use project instructions for:
- Directory structure and important modules.
- Install, start, test and build commands.
- Code style and architecture constraints.
- PR and review standards.
- Protected areas and completion criteria.
Codex loads applicable user and project instructions along the directory path. More specific instructions refine broader guidance.
# Project instructions
## Commands
- npm run lint
- npm run typecheck
- npm run build
## Done when
- Relevant checks pass
- Diff is reviewed
- No unrelated refactorGenerate a draft:
/init#Custom prompts
Reusable prompts suit fixed instructions such as release checks, PR descriptions or log analysis. When the workflow also requires reference files, scripts, templates or multiple steps, a skill is a better package.
#Memories
| Mechanism | Scope | Suitable content |
|---|---|---|
| AGENTS.md | Repository/directory | Project facts, commands and team standards |
| Memories | User/workspace where available | Preferences and recurring habits |
| Prompt | Current task/thread | One-off constraints |
Do not store credentials, private customer data or temporary tokens in memory.
#Hooks
Hooks run at lifecycle events and can implement checks or notifications. They can be loaded from hooks.json or inline TOML.
| Location | Scope |
|---|---|
| ~/.codex/hooks.json | User hooks |
| ~/.codex/config.toml | User inline hooks |
| .codex/hooks.json | Trusted-project hooks |
| .codex/config.toml | Trusted-project inline hooks |
[[hooks.PreToolUse]]
matcher = "^Bash$"
[[hooks.PreToolUse.hooks]]
type = "command"
command = './.codex/hooks/pre_tool_use_policy.sh'
timeout = 30
statusMessage = "Checking Bash command"If one layer defines both forms, Codex can load both and warn. Prefer one representation per layer.
#Rules
Rules suit predictable command-prefix policy outside the ordinary sandbox boundary:
prefix_rule(
pattern = ["git", "push"],
decision = "prompt",
justification = "Pushing branches requires explicit review",
match = ["git push origin feature"],
)| Decision | Behavior |
|---|---|
| allow | Permit a matching action |
| prompt | Request approval |
| forbidden | Block it |
When several rules match, the more restrictive decision wins.
#Skills and plugins
Skills package repeatable workflows:
$skill-creator
/skills
$readme-skillA plugin is a distribution package that can include skills, MCP configuration, assets, app mappings and a manifest. Stabilize a useful workflow before packaging it for a team.
#Import
/import migrates supported Claude Code setup, project information or recent chats. Review imported settings instead of accepting all historical configuration unchanged.
- Import project instructions or command rules first.
- Check conflicts with existing AGENTS.md.
- Decide whether hooks, skills and prompts should migrate.
- Inspect effective configuration with /debug-config afterward.
#Subagents
Custom agent definitions can live in:
| Location | Scope |
|---|---|
| ~/.codex/agents/ | Personal agents |
| .codex/agents/ | Trusted-project agents |
Definitions include name, description and developer_instructions. Use focused roles for exploration, tests, review or migrations. Isolate concurrent edits with worktrees rather than assigning the same files to several agents.
#Adoption order
- Write a short AGENTS.md.
- Turn repeated instructions into prompts or skills.
- Use rules for explicit command policies.
- Use hooks for checks, audit and notifications.
- Connect needed external tools with MCP.
- Package stable reusable capabilities as plugins.
#Official references
Support
Need help?
For setup, billing, or model issues, email us. Check the status page for uptime.
WeChat / QQ support is available at the bottom right.

