18. Skills, Plugins, and Hooks
Skills, plugins, and hooks extend Codex without code changes, and each works at a different point. A skill is a Markdown file of instructions that enters the prompt as one catalog line until the model or user selects it. A plugin is a directory that bundles skills, Model Context Protocol (MCP) servers, apps, and hooks behind one install. A hook is a command that runs at one of 14 lifecycle events, and it is the only extension that can block or rewrite a tool call.
Chapter 17 showed how MCP adds tools from other processes. This chapter covers the three extension surfaces that sit closer to the prompt and the turn. Skills teach the model procedures. Plugins package skills and tools so that one install brings both. Hooks let a user or administrator run their own code before and after the agent acts, with power to veto. A short section on apps and connectors closes the chapter. The order in which context fragments are assembled is in Chapter 7, the extension API and its extensions are in Chapter 19, and sub-agents are in Chapter 20.
The picture
Read the diagram left to right. Two sources hold the extensions on
disk: the config layers (config.toml,
hooks.json, and each layer’s skills folder) and the plugin
store under $CODEX_HOME/plugins/cache. The green lines show
one plugin feeding four loaders at once through its default files. The
skills service turns skills into prompt fragments, and the MCP
connections and the Apps server turn tools into registry entries, beside
tools from in-process extensions. Hooks take a different path. They do
not add to the prompt or the tool list; they act on the turn loop
itself, which is why the red line is the only one that can stop a
call.
Skills
The SKILL.md format
A skill is a folder with a SKILL.md file: YAML
frontmatter, then Markdown instructions. SkillFrontmatter
in codex-rs/skills/src/parser.rs reads three fields:
name, description, and
metadata.short-description. Only description
is required; it is the text the model reads in the catalog when it
decides whether the skill applies. A missing name falls
back to a default the caller supplies, and names are capped at 64
characters. The system skill
codex-rs/skills/src/assets/samples/review-agent/SKILL.md
begins:
---
name: review-agent
description: Perform a read-only, defect-first review of a specified code change and return every actionable finding. Use when another agent delegates review of uncommitted changes, a base-branch diff, a commit, or custom review instructions.
---
# Review Agent
Inspect the requested target directly and return every finding that the author would likely fix.
Some third-party skills write prose such as
description: Build for AWS: ECS, which is invalid YAML.
When strict parsing fails, repair_frontmatter_scalar_fields
quotes such scalars and retries once. An optional sidecar,
agents/openai.yaml, adds interface text, tool dependencies,
and policy. The sidecar of review-agent sets
policy.allow_implicit_invocation: false, and that one line
changes how the skill is used, as the invocation section shows.
Discovery
Skill roots come from the config layers.
roots_from_layer_stack in
codex-rs/ext/skills/src/host_roots.rs maps each layer to a
folder and a scope. The table lists the roots in the order
resolve_skill_roots adds them, before duplicate paths are
removed.
| Source | Folder | Scope |
|---|---|---|
| Project config layer | <layer folder>/skills |
Repo |
| User config layer | $CODEX_HOME/skills (deprecated),
~/.agents/skills |
User |
| User config layer | $CODEX_HOME/skills/.system |
System |
| System config layer | <layer folder>/skills |
Admin |
| Installed plugins | each plugin’s skills/ |
User, with a plugin namespace |
| Repository | .agents/skills in each directory from the project root
down to the cwd |
Repo |
The scanner descends at most 6 levels and visits at most 2,000 skill
directories per root. System skills ship inside the binary:
include_dir! embeds src/assets/samples, and
install_system_skills writes them to
$CODEX_HOME/skills/.system, skipping the write when a
marker file holds a matching hash of the embedded tree. At the pinned
commit the samples are create-statusline,
imagegen, openai-docs,
review-agent, skill-creator, and
skill-installer.
How skills appear in context
Skills use progressive disclosure: the model sees a catalog of names
and descriptions, and a skill’s body loads only when it is used.
AvailableSkillsInstructions in
codex-rs/ext/skills/src/fragments.rs is a developer-role
fragment wrapped in <skills_instructions>, with
sections ## Skills, ### Skill roots, and
### Available skills. A snapshot in
codex-rs/core/tests/suite/snapshots shows the shape; root
aliases such as r1 keep each line short:
### Skill roots
- `r0` = `<SKILLS_ROOT>`
- `r1` = `<SKILLS_ROOT>/.system`
### Available skills
- ...
- skill-creator: Create or update a Codex skill with appropriately scoped instructions and any needed supporting resources. (file: r1/skill-creator/SKILL.md)
The catalog has a budget, computed by
skill_metadata_budget in
codex-rs/ext/skills/src/render.rs:
where
skills.max_context_tokens from config, and
Over budget, allocate_skill_lines degrades in three
tiers. If every full line fits, all are kept. If every line fits without
its description, the remaining budget is shared out as description
characters, so descriptions are cut. Otherwise all descriptions are
dropped, and each line, in catalog order, is kept if it still fits and
omitted if not, with the warning “Exceeded skills context budget…”. In
the core-compatible render style, catalog order is scope first (System,
Admin, Repo, User) and then name, so user skills are the first to fall
out. Each description is also capped at 1,024 characters.
Explicit and implicit invocation
Explicit invocation is the user naming a skill. A $name
mention, or the linked form [$name](path), selects it;
collect_explicit_skill_mentions in
codex-rs/skills/src/selection.rs resolves structured
selections by path first and plain names only when unambiguous. Common
environment variables such as $PATH and $HOME
never count. Core then reads the file and injects it as a user-role
<skill> fragment holding the name, path, and full
text. On this Core path, only Agent Plugin skill bodies are truncated,
to 8,000 bytes.
Implicit invocation is the model choosing a skill on its own. The
catalog prompt says: “If the user names a skill (with
$SkillName or plain text) OR the task clearly matches a
skill’s description shown above, you must use that skill for that turn.”
The model then opens SKILL.md itself through the listed
path. Codex notices this after the fact:
detect_implicit_skill_invocation_for_command in
codex-rs/skills/src/invocation.rs flags a shell command
that reads a skill’s SKILL.md or runs a script under its
scripts/ folder. The result is telemetry only, a
codex.skill.injected counter with
invoke_type=implicit, emitted once per skill per turn.
A skill whose sidecar sets
allow_implicit_invocation: false is marked
hidden_from_prompt. It stays out of the catalog, so the
model never sees it, and it runs only when someone names it.
review-agent is built that way; its description says it
serves review that another agent delegates, so hiding it keeps the model
from choosing it on its own. A mentioned skill can also declare MCP
server dependencies; when they are missing, first-party clients ask
“Install” or “Continue anyway”.
Plugins
What a plugin bundles
A plugin is a directory with a manifest. Codex first accepts a root
plugin.json that declares an Agent Plugins
$schema, then looks for
.codex-plugin/plugin.json,
.claude-plugin/plugin.json, or
.cursor-plugin/plugin.json
(DISCOVERABLE_PLUGIN_MANIFEST_PATHS). The manifest is
camelCase JSON with name, version,
description, keywords, paths for
skills, mcpServers, apps, and
hooks, and an interface block of display text.
When the manifest omits a path, the loader in
codex-rs/core-plugins/src/loader.rs uses defaults:
skills/, .mcp.json, .app.json,
and hooks/hooks.json. The hooks default applies only to the
older manifest locations, not to an Agent Plugins
plugin.json.
The only plugin in the repository is the message board, whose manifest is three fields:
{ "name": "message-board", "version": "0.1.0",
"description": "Shared agent discussion boards through MCP." }It declares no paths, so its MCP server comes from the default
.mcp.json, which points a required streamable
HTTP server at http://127.0.0.1:7777/mcp with
bearer_token_env_var = "CODEX_MESSAGE_BOARD_TOKEN". The
design is convention over configuration: a plugin author writes skill
folders, an MCP server map, and a hooks file, and the loaders that read
user config read them too.
Install and archive verification
codex plugin add <plugin>@<marketplace>
installs a plugin; a plugin id always has the form
<plugin>@<marketplace>.
PluginsManager in
codex-rs/core-plugins/src/manager.rs runs the install:
resolve_installable_pluginfinds the plugin in the marketplace catalogs and checks marketplace policy from config requirements.install_resolved_pluginfetches the source: a local path, a Git checkout, or an npm package of at most 50 MiB (250 MiB extracted).- A plugin from a remote marketplace takes
install_remote_plugininstead: a bundle of at most 100 MiB downloaded and 512 MiB extracted, verified before extraction as described below. PluginStorerejects the install when theplugin.jsonname differs from the marketplace name, then swaps in$CODEX_HOME/plugins/cache/<marketplace>/<plugin>/<version>atomically. The version label defaults tolocal.- The manager writes
enabled = truefor the plugin into user config.
RemotePluginArchiveDownload::verify in
codex-rs/plugin-archive-verification/src/archive_verification.rs
checks the downloaded bytes in two steps. It compares the archive’s
Secure Hash Algorithm 256 (SHA-256) digest with the one in the signing
metadata, then checks an RSA PKCS#1 v1.5 SHA-256 signature
(RSA_PKCS1_SHA256) with a public key fetched from the
plugin service. Malformed metadata fails the download. Absent metadata
returns NotRequired and the install proceeds, which keeps
older catalogs working. Every outcome is counted in the
codex.plugins.archive_verification metric, tagged with
values such as digest_mismatch or
signature_mismatch.
Marketplaces and mentions
A marketplace is a catalog file at
.agents/plugins/marketplace.json,
.agents/plugins/api_marketplace.json,
.claude-plugin/marketplace.json, or
.cursor-plugin/marketplace.json.
codex plugin marketplace add accepts a local path,
owner/repo[@ref], an HTTPS Git URL, or an SSH Git URL.
codex plugin has four subcommands: add,
list, marketplace, and
remove.
A user mentions a plugin with the @ sigil, and the
linked form carries a plugin://<id> path.
collect_explicit_plugin_ids matches plugins by exact config
id from that path, never by display name. A mentioned plugin adds a
developer hint naming its skill namespace, apps, and MCP servers, capped
at 4 KiB by MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES.
Enablement follows a simple rule in allows_plugin: a
per-plugin enabled wins, then
[plugins._default], and with neither the plugin is
allowed.
Hooks
Fourteen events
HOOK_EVENT_NAMES in
codex-rs/hooks/src/lib.rs lists 14 events. Nine of them use
a matcher; the others ignore it. The table shows when each fires, what
its matcher tests, and what a hook can do there.
| Event | Fires | Matcher tests | A hook can |
|---|---|---|---|
PreModelRequest |
Before a sampling request | Nothing | Observe |
PostModelRequest |
After a sampling request | Nothing | Observe; an MCP hook may add a charge |
PreToolUse |
Before a tool runs | Tool name | Deny, or allow with rewritten input |
PermissionRequest |
When approval is needed | Tool name | Allow or deny |
PostToolUse |
After a tool returns | Tool name | Block or replace the result |
PreCompact |
Before compaction | Trigger | Stop the turn |
PostCompact |
After compaction | Trigger | Stop the turn |
SessionStart |
Start, resume, clear, compact, fork | Source | Add context, stop |
SessionEnd |
Session ends | Reason | Observe |
UserPromptSubmit |
User input arrives | Nothing | Add context, stop |
SubagentStart |
A sub-agent starts | Agent type | Add context, stop |
SubagentStop |
A sub-agent finishes | Agent type | Block the stop |
Stop |
Turn is about to end | Nothing | Block, which continues the turn |
Interrupt |
Turn is interrupted | Nothing | Observe |
A matcher of "" or * matches everything. A
pattern made only of letters, digits, _, and |
matches exactly, with | as alternation. Anything else is a
regular expression (HookMatcher in
codex-rs/hooks/src/engine/matcher.rs). The shell tool’s
hook name is Bash, and an MCP tool’s is its joined name,
such as mcp__docs__search.
Configuration
Each config layer can declare hooks in TOML under
[hooks] or in a hooks.json file in its folder,
and Codex warns when one layer uses both. The TOML below comes from the
test fixture in
codex-rs/core/src/config/config_loader_tests.rs:
[[hooks.PreToolUse]]
matcher = "^Bash$"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "python3 /tmp/user-hook.py"A command hook runs through $SHELL -lc (falling back to
/bin/sh) or through COMSPEC with
/C on Windows. Codex clears the environment, rebuilds it
from the session snapshot, and writes the event as JSON on stdin; for
PreToolUse that JSON includes tool_name,
tool_input, tool_use_id, cwd, and
permission_mode. The default timeout is 600 seconds, while
SessionEnd and Interrupt default to 1 second
and are clamped to 3. Matching synchronous hooks run concurrently, and
async: true hooks run in the background, at most 8 at a
time. The handler type mcp_tool calls a tool on a
configured MCP server instead of a command. The types
prompt and agent parse, but discovery skips
them with “prompt hooks are not supported yet” and “agent hooks are not
supported yet”.
A hook answers on stdout. This output, the shape used in
codex-rs/core/tests/suite/hooks.rs, blocks the call:
{"hookSpecificOutput": {"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "rm -rf is not allowed here"}}Exit code 2 with the reason on stderr blocks too. Core turns the
block into a message the model reads:
Command blocked by PreToolUse hook: <reason>. Command: <command>
for the shell and apply_patch, or
Tool call blocked by PreToolUse hook: <reason>. Tool: <name>
otherwise.
Trust: untrusted hooks do not run
A hook is a command that runs on your machine, and a repository can
ship one in its project config. Codex therefore runs a hook only when it
is trusted. hook_trust_status in
codex-rs/hooks/src/engine/discovery.rs treats built-in and
managed hooks as trusted by definition. Any other hook is trusted only
when the trusted_hash stored in config under
[hooks.state] equals the hash of the hook’s normalized
identity. With no stored hash the hook is Untrusted, and
with a different hash it is Modified. Either way discovery
lists it but does not load it. For a plugin hook, the hash also covers
the plugin’s contents, so editing any file in the plugin invalidates the
trust.
This is trust on first use with a content hash. In the terminal UI
(TUI), the /hooks command views and manages hooks.
--dangerously-bypass-hook-trust runs enabled hooks without
stored trust for one invocation; its help text says it is “Intended only
for automation that already vets hook sources.” An administrator can go
further with allow_managed_hooks_only, which limits
discovery to managed hooks.
The only surface that changes a tool call
Hooks are the one extension surface that can block or rewrite a tool
call. In PreToolUse,
permissionDecision: "deny" with a non-empty reason blocks
the call, and "allow" with updatedInput
replaces the tool’s input. parse_pre_tool_use in
codex-rs/hooks/src/engine/output_parser.rs rejects the
other options there, such as ask or
continue: false, so a hook cannot pause the call half-way.
PostToolUse can block a result or replace what the model
sees with feedback text.
Extensions cannot do this by design. The doc comment on
ToolLifecycleContributor in
codex-rs/ext/extension-api/src/contributors.rs says
implementations “can observe tool execution and process MCP responses
without rewriting the invocation”, and points to “hooks for policy that
changes tool payloads”. Its on_tool_start callback runs
only after pre-tool hooks finish, so a blocked call never reaches an
extension. Keeping mutation in one place makes tool policy auditable: to
know what can change a call, you read the hooks configuration and
nothing else.
Apps and connectors
Apps are ChatGPT connectors, such as a drive or a calendar, served as
tools of one host-owned MCP server named codex_apps.
apps_enabled_for_auth in
codex-rs/features/src/lib.rs turns them on only when the
apps feature is on and the user signed in with ChatGPT.
Codex derives the list of accessible connectors from
codex_apps tools that carry a connector_id,
and caches the connector directory for 3,600 seconds.
Approval for an app tool follows its own precedence in
app_tool_policy_from_apps_config in
codex-rs/connectors/src/app_tool_policy.rs: a managed
requirement, then the tool’s approval_mode, the account
link default, the app default, [apps._default], and finally
auto. The mode then feeds the decision table in Chapter 17. Plugins declare apps in
.app.json. In config, each enabled plugin’s
apps table merges first and explicit top-level
[apps] fields apply last, so the top-level table wins.
Status at commit 081295be9d.
hooks, plugins, remote_plugin,
apps, skill_mcp_dependency_install: STABLE, on
by default; apps also needs ChatGPT sign-in.
skill_catalog_deltas, omit_skill_descriptions,
skip_host_skill_discovery: UNDER DEVELOPMENT, off.
plugin_hooks: REMOVED. Hook handler types
prompt and agent: parsed but skipped. Command
hooks are PLATFORM-SPECIFIC in their shell: $SHELL -lc on
Unix, COMSPEC /C on Windows. Read in code, not run.
What breaks
| Symptom | Cause | Check |
|---|---|---|
| Skill missing from the catalog | No description, or YAML still invalid after repair |
Warning “missing field description” |
| “Exceeded skills context budget” | Catalog over
|
Raise skills.max_context_tokens (cap 10,000) |
| Model never uses a skill on its own | allow_implicit_invocation: false hides it |
agents/openai.yaml policy block |
| Plugin install fails on name | plugin.json name differs from marketplace entry |
PluginStore error “does not match” |
| Remote plugin rejected | Digest or signature mismatch | codex.plugins.archive_verification outcome tag |
| Hook configured but never runs | Untrusted, or changed since trust | trusted_hash under [hooks.state];
/hooks |
deny ignored |
Empty reason, or allow without
updatedInput |
Hook completed event’s invalid reason |
| App list empty | apps off, or not a ChatGPT sign-in |
apps_enabled_for_auth |
Code map
| What it is | Where it lives | Identifier |
|---|---|---|
| SKILL.md parser | codex:codex-rs/skills/src/parser.rs |
parse_skill_frontmatter_metadata |
| Skill roots | codex:codex-rs/ext/skills/src/host_roots.rs |
roots_from_layer_stack |
| Catalog budget | codex:codex-rs/ext/skills/src/render.rs |
skill_metadata_budget |
| Implicit invocation | codex:codex-rs/skills/src/invocation.rs |
detect_implicit_skill_invocation_for_command |
| Plugin install | codex:codex-rs/core-plugins/src/manager.rs |
install_resolved_plugin |
| Archive verification | codex:codex-rs/plugin-archive-verification/src/archive_verification.rs |
RemotePluginArchiveDownload |
| Hook events | codex:codex-rs/hooks/src/lib.rs |
HOOK_EVENT_NAMES |
| Hook trust | codex:codex-rs/hooks/src/engine/discovery.rs |
hook_trust_status |
Recall check
When does a skill’s full text enter the
context?
When the user names it, as a <skill> fragment, or
when the model opens its SKILL.md after matching the
catalog description.
How large is the skills catalog budget for a model with a
200,000-token window and no config?
2 percent of the window, 4,000 tokens.
What four component files does a plugin load by
default?
skills/, .mcp.json, .app.json,
and hooks/hooks.json.
Why does a new project hook not run?
It has no stored trusted_hash, so it is
Untrusted until the user trusts it.
Which extension surface can rewrite a tool call’s input, and
how?
Only hooks: a PreToolUse hook returns
permissionDecision: "allow" with
updatedInput.