Codex

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.

LayerPurposeFiles or entry points
InstructionsRules, style, workflow and completion criteriaAGENTS.md, prompts, memories, skills
ControlsCommands, approvals and lifecycle enforcementRules, hooks, sandbox, approvals
ToolsExternal data and operationsMCP, 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.

AGENTS.md
# Project instructions

## Commands
- npm run lint
- npm run typecheck
- npm run build

## Done when
- Relevant checks pass
- Diff is reviewed
- No unrelated refactor

Generate 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

MechanismScopeSuitable content
AGENTS.mdRepository/directoryProject facts, commands and team standards
MemoriesUser/workspace where availablePreferences and recurring habits
PromptCurrent task/threadOne-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.

LocationScope
~/.codex/hooks.jsonUser hooks
~/.codex/config.tomlUser inline hooks
.codex/hooks.jsonTrusted-project hooks
.codex/config.tomlTrusted-project inline hooks
.codex/config.toml
[[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:

.codex/rules/default.rules
prefix_rule(
    pattern = ["git", "push"],
    decision = "prompt",
    justification = "Pushing branches requires explicit review",
    match = ["git push origin feature"],
)
DecisionBehavior
allowPermit a matching action
promptRequest approval
forbiddenBlock it

When several rules match, the more restrictive decision wins.

#Skills and plugins

Skills package repeatable workflows:

$skill-creator
/skills
$readme-skill

A 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.

  1. Import project instructions or command rules first.
  2. Check conflicts with existing AGENTS.md.
  3. Decide whether hooks, skills and prompts should migrate.
  4. Inspect effective configuration with /debug-config afterward.

#Subagents

Custom agent definitions can live in:

LocationScope
~/.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

  1. Write a short AGENTS.md.
  2. Turn repeated instructions into prompts or skills.
  3. Use rules for explicit command policies.
  4. Use hooks for checks, audit and notifications.
  5. Connect needed external tools with MCP.
  6. 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.