How to add a Codex hook and skill for a repeat job

Day 6, 30 minutes · beginner

Goal of this lessonAdd a skill that adds a kite the same way every time and a hook that tells Codex your uncommitted changes when a session starts.

Why it matters

By now you have handed Codex single tasks, a cloud job and an unattended check. The last step is making a job you repeat come out the same way every time, without retyping the instructions. Codex has two tools for that, and they do different things.

A skill is a written procedure Codex follows when the job comes up: "to add a kite, do these five things in this order". A hook is a command that runs by itself at a fixed moment, such as the start of every session, whether or not anyone remembers it. The skill shapes what Codex does; the hook makes sure something always happens.

Today you give Puffinreach Kites one of each: an add-kite skill so a new kite always lands in the price file, the price list and the size guide, and a hook that tells Codex which files have uncommitted changes as soon as a session starts. At the end both are committed and every new session on the repository uses them.

Skills in Codex

From the Codex docs on building skills:

  • A skill is a folder with a SKILL.md file. The file starts with a name and a description, followed by the instructions. Scripts and reference files are optional.
  • For one repository, skills live in .agents/skills/<skill-name>/ in the repository. Personal skills that fit every project go in .agents/skills in your home folder.
  • Codex first sees only each skill's name and description, and loads the full instructions when it uses the skill. So the description decides when the skill is picked: say what it is for, and what it is not for.
  • You can call a skill yourself with $ and its name, or pick it from /skills. Codex can also choose it by itself when a request matches the description.

Codex also has a built-in helper, $skill-creator, that interviews you and drafts a skill. Writing this first one by hand shows you what a skill really is.

Hooks in Codex

From the Codex docs on hooks:

  • Hooks are set in a hooks.json file. For one repository it is .codex/hooks.json, and it only loads when you trust the project. Personal hooks go in hooks.json in your Codex home folder.
  • Each hook belongs to a moment, such as SessionStart, PreToolUse (before Codex uses a tool) or Stop (when a turn ends).
  • For SessionStart, plain text that the command prints is added to what Codex knows. So git status --short at the start of a session tells Codex which files are new or changed, before you type anything.
  • Codex runs no hook you have not trusted. New or changed hooks are skipped until you review and trust them in /hooks. That protects you from a hook someone else added to a repository.

The steps

  1. Get the latest version of the repository, with the size guide from lesson 4.
  2. Write the skill as a short numbered procedure with a clear end line, and use it once to add a new kite.
  3. Write the hook that prints the git status at session start.
  4. Trust the hook in /hooks.
  5. Test it in a fresh session by asking which files had uncommitted changes when the session started.
  6. Commit the skill, the hook and the new kite, so they travel with the repository.

Follow the guide for Codex below for the exact file contents. The Codex sandbox keeps .agents and .codex read-only for Codex, so you create these two files yourself in your editor. When to pick a skill, a hook or a subagent in general is covered in Ship AI at the client.

Example: Benthe's new kite

Benthe typed $add-kite Night Owl, 59.00 euros, wingspan 150 cm, light wind. Codex followed the five steps: prices.json first, then the price list, then a new row in the size guide, a price comparison, and "Prices checked." at the end. When she later typed only $add-kite Sea Breeze, Codex asked for the price and the wingspan before changing anything, because step 1 of the skill says so.

In the next session, Codex already knew that .agents/ and .codex/ were new and that three files had changed, without running git itself.

Common mistakes

  • A vague description. "Kite stuff" will not be picked at the right time. Say when to use it and when not to.
  • Forgetting to trust the hook. An untrusted hook is skipped without running. Look for the warning at startup.
  • Hooks that need a specific shell. The hooks docs do not say which shell runs a hook command on Windows, and their examples use python3 and Bash syntax. A plain command such as git status --short has no shell-specific parts.
  • Too much in one skill. Keep each skill to one job.

Today's actions

Ticks are not saved without an account

Do it in OpenAI Codex

OpenAI Codex

  1. In the terminal, go into puffinreach-kites and get the merged size guide from lesson 4. (If you did lesson 4 in the terminal without GitHub, you already have it: skip both lines.)
    git switch main
    git pull
  2. In your editor, inside puffinreach-kites, create the folders .agents, then skills, then add-kite, and in add-kite a file called SKILL.md with this text. Save it.
    ---
    name: add-kite
    description: Add a new kite to the Puffinreach Kites shop. Use when asked to add or launch a new kite. Not for changing the price of an existing kite.
    ---
    
    1. If the kite name, the price in euros or the wingspan is missing, ask for it before you change anything.
    2. Add the kite to prices.json first, with a price with two decimals.
    3. Add it to the price list in index.html and to the table in size-guide.html.
    4. Compare every price in index.html with prices.json.
    5. End with the list of changed files and the line: Prices checked.
  3. Start codex in puffinreach-kites, type /skills and check that add-kite is in the list. Then use it with a $ mention.
    $add-kite Night Owl, 59.00 euros, wingspan 150 cm, light wind
  4. Check the result with /diff and type /exit. Then, in your editor, create the folder .codex in the repository with a file hooks.json containing this text. Save it.
    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "startup|resume",
            "hooks": [
              {
                "type": "command",
                "command": "git status --short",
                "statusMessage": "Checking uncommitted changes"
              }
            ]
          }
        ]
      }
    }
  5. Start codex again. Codex warns that a hook needs review: type /hooks, review the new hook and trust it. Then type /exit.
  6. Start codex once more and ask this. The answer should name your new files without Codex running git itself.
    Which files had uncommitted changes when this session started? Answer from the session start information only.
  7. Type /exit and commit the skill, the hook and the new kite. The report file from lesson 5 stays out.
    git add .agents .codex prices.json index.html size-guide.html
    git commit -m "Add add-kite skill, session start hook and Night Owl kite"

Note: Codex cannot write in .agents or .codex itself in the default sandbox, which is why you create these files by hand. A new or changed hook is skipped until you trust it again in /hooks. Project hooks load only in a trusted project. If a skill does not show up, restart Codex. The skill format and folders come from the Codex docs page Build skills.

Paid planSame as lesson 1: the Codex CLI with ChatGPT Plus, Pro, Business, Edu or Enterprise, or with an OpenAI API key.

Checked on 4 December 2026 · Source: Codex docs: Hooks (opens in a new tab)

Create a free account to save your progress. Sign in or sign up