You added a line to AGENTS.md telling Codex to run the formatter after every edit. It works most days. Then one day it skips the step, and you wonder whether a hook would be sturdier, or whether this should be a skill.
That question gets harder as your setup grows. This is a decision aid for Codex CLI users who run things locally, not a hooks reference.
What was and wasn't checked
Hooks were not tested hands-on for this article. The one source, a community discussion about a cleanup tool, never mentions hooks. So this article does not state event names, config file locations or exact hook behavior. Confirm those in the official OpenAI Codex documentation before you write your first hook.
What follows rests on the general design of each mechanism. Anything beyond that is labeled as inference.
Trigger: who decides when it runs
AGENTS.md is a plain text file of instructions. Codex picks these files up as context, and the community discussion confirms they are discovered per project. You write a rule, the model reads it, and the model decides whether and how to follow it.
Skills are packaged instructions the model can draw on for a particular kind of task. The discussion describes skills as "injected" and notes that some are never used yet still get injected. The model, not you, decides whether a skill is relevant.
Hooks flip that. A hook is a command you configure to run when Codex reaches a specific lifecycle event. The event is the trigger, not the model's judgment. That is the whole reason to choose one.
Reliability: advice versus a guarantee
AGENTS.md and skills are advisory. The model can misread a rule, weigh it against a long prompt, or just not apply it. For style preferences, that's fine. For "always run this check", it's a weak foundation.
A hook takes the model out of the decision to run. This is an inference from the design, not something tested here: once a hook is configured and enabled correctly, it should fire whenever its event occurs. But reliability then shifts to your script. Exit codes, timeouts, missing environment variables and a changed tool path can all make a hook fail. Check the documentation for how Codex treats a failing hook and whether the command's output goes back to the model.
Context cost: what you pay in every session
Instruction text costs context. The model has to carry AGENTS.md content, so a long, stale file is a recurring tax on every session in that project. Skills add their own descriptions and, when used, their bodies. The exact loading rules are worth checking in the documentation, but the community discussion shows the practical problem: never-used skills can keep being injected.
Hooks are the odd one out. The command itself is not an instruction the model reads. Whether a hook's output reaches the model depends on the event and its configuration, which was not verified here. A quiet hook that prints little should cost close to nothing. A noisy one could cost more than any instruction file.
Maintenance: where the clutter comes from
Instructions and skills rot quietly. A project gets renamed, a tool gets replaced, and the AGENTS.md line about it stays. Nobody notices because nothing fails.
That pile-up is why NathanZane built codex-assistant, a small npm CLI announced in a community discussion on GitHub on June 2, 2026. It looks at three things: the size of JSONL rollout files, never-used skills that are still injected, and AGENTS files found across projects.
Hooks fail the opposite way. They are loud when they break, but a script that depends on a tool you later remove will break at the worst moment.
Side-by-side comparison
| | Hooks | AGENTS.md | Skills | |---|---|---|---| | Trigger | A Codex lifecycle event, set by you | Loaded as project context; the model chooses how to apply it | The model decides a skill is relevant | | Best use | Actions that must always happen | Standing rules and project facts | Repeatable multi-step know-how | | Context cost | Low if quiet; depends on whether output is returned (unverified) | Paid every session in that project | Description always, body when used (verify in docs) | | Main risk | Runs your own commands, so a bad scope can do real damage | Gets ignored or goes stale | Piles up unused but still injected |
Worked example: format after edits
Say you want your formatter to run after Codex edits files.
As an AGENTS.md line ("run the formatter before you finish"), it costs one sentence and needs no scripting. It works most of the time, but you can't count on it. As a skill, it's overkill, since there's no multi-step know-how to package.
A hook fits best here, because the action is mechanical and has to happen every time. This mapping is an inference from how hooks are designed, so confirm in the documentation which event suits it. Keep the command narrow: format only changed files, in this repo, with no network access and no deleting.
Who benefits: a developer with one deterministic formatter and a diff they review anyway. The limitation: the hook runs your own command with your permissions, so a sloppy glob or a script copied from somewhere else can rewrite files you never meant to touch. Reformatting can also muddy a diff if your formatter config differs from the repo's.
Where a hook is the wrong choice
Skip hooks for anything that needs judgment. "Prefer small functions" or "explain trade-offs before refactoring" can't be expressed as a command with a pass or fail result, so those belong in AGENTS.md. Hooks are also a poor fit for irreversible actions like auto-committing, pushing or deleting, where you want a human decision rather than an automatic one. And a slow full test suite on every event will make Codex feel broken.
Testing a hook without regretting it
Start with a hook that only appends a line to a log file. Try it in a throwaway repo with no secrets in the environment. Once it fires when you expect, swap in the real command, and keep it idempotent so running it twice does no harm.
Treat hook config like any script. If hooks can be defined at the project level (confirm this), read a cloned repo's config before running Codex there. Writing a hook gives Codex a way to execute your commands, so scope it as tightly as you would a cron job.
A short .codex audit before you add anything
The codex-assistant tool is optional and in beta, installed with npm install -g @nathanzane/codex-assistant@beta. It is a community project, not an OpenAI product, and it was not run for this article. The author asks for feedback, and the discussion had no replies at last check. Read what it offers to change, and back up your folder first.
The tool mentions quarantine, restore and trash options for rollouts, and disabling or re-enabling for skills and AGENTS files. You can do the same checks by hand:
- Back up your .codex folder before deleting anything.
- List your skills and remove or disable any you can't remember using.
- Open each AGENTS.md and delete rules that refer to tools or paths that no longer exist.
- Look for oversized rollout files from old sessions and archive them.
- Re-read what is left. If a rule says "always", ask whether it should be a hook.
Who should choose what
Use AGENTS.md for rules the model should weigh, such as conventions, preferences and facts about the repo, and keep it short. Use a skill for a repeatable workflow you actually invoke, and remove it once you stop. Use a hook only when an action must happen every time, a command can express it, and you can scope it narrowly.
If you do one thing this week, audit your .codex folder first, then try a single logging-only hook before you automate anything real.



