Directing Agents

AGENTS.md, skills, and hooks

Brendan Chapuis

April 5, 2027

Draws on talks by Scott Cunningham
Course Home Page

Lecture Goals

  • Give an agent standing instructions for your project: AGENTS.md
  • Turn a prompt you keep repeating into a skill
  • Enforce the few rules that must never break with a hook
  • Attack your own hook to find out whether it works
  • In class: an AGENTS.md and one skill or hook for your final project repository

Directing an Agent

Where We Are

  • 3/24: an agent is a language model whose tokens become commands. You built a website with one, in Manual and plan mode.
  • That site was low stakes: you could see every mistake.

Your final project is not. A wrong number looks exactly like a right one.

Today: how to tell an agent how your project works, once, instead of in every prompt.

Three Tools

What it is What it does
AGENTS.md a Markdown file the agent reads every session what the agent knows
A skill a Markdown file it reads only when called what the agent can do
A hook a script the harness runs at fixed moments what the agent must (not) do

Start with AGENTS.md. Add a skill when a task repeats, and a hook when a rule must hold.

Framing from Scott Cunningham’s Texas A&M and Baylor talks (2026).

Standing Instructions: AGENTS.md

A File the Agent Reads Every Session

  • A plain Markdown file at the root of your project.
  • The agent loads it at the start of every session, before your first prompt.
  • It is your project’s rules, written in plain English.

You have already seen one: this course’s repository has an AGENTS.md that tells agents how the site is built, where things live, and what never to commit.

One File, Several Tools

Tool Reads
Codex AGENTS.md, from the project root down to the current folder
GitHub Copilot AGENTS.md at the repository root (and .github/copilot-instructions.md)
Claude Code CLAUDE.md; reads AGENTS.md instead when there is no CLAUDE.md
  • Write one AGENTS.md, and every tool (and coauthor) shares it.
  • If you also keep a CLAUDE.md, Claude Code reads only that, unless it imports the other with a line @AGENTS.md.

What Is Obvious to You Is Not Obvious to the Agent

Scott’s file states the obvious:

CLAUDE.md
- Never produce a figure outside of a pipelined file, such as a script.
- Never fabricate data unless it is an approved simulation.
- Never delete raw data.
- Never edit raw data; only edit copies of raw data.

Each line is there because an agent once did it.

So write it down.

Source: Scott Cunningham’s Baylor talk (2026).

What to Put in It

  • What the project is: one or two sentences.
  • Where things live: the folder layout and what each folder is for.
  • How to run and check it: the one command that rebuilds everything.
  • Rules: what must never happen.
  • What to ask you first: decisions that are yours, not the agent’s.

Test each line: would a capable stranger, new to this repository, get this wrong? If not, leave it out.

What to Leave Out

  • Things the agent can see by reading the folder (every file name, every package).
  • Long explanations. Rules work better as short, specific sentences.
  • Status that changes: “today I am fixing the merge.” Put that in a progress file instead.
  • Secrets. AGENTS.md is committed to Git like any other file.

Keep It Short

It is loaded into every session, so every line costs context and attention.

  • Anthropic’s guidance: aim for under 200 lines; longer files are followed less consistently.
  • Codex stops reading instruction files after 32 KB by default.
  • Recall 3/24: a long context is read unevenly. A long rule file is too.

A good AGENTS.md for a course project fits on one screen or two.

Worked Example (1/3): The Project

AGENTS.md
# Minimum wages and teen employment

ECON 2020 final project. R with renv. Paper in paper.qmd.

## Layout
- data/raw/      files exactly as downloaded. READ-ONLY.
- data/derived/  everything built from raw data, by code in code/
- code/          numbered scripts: 01-download.R, 02-clean.R, ...
- output/        figures/ and tables/, made only by code
- main.R         runs every script in order

This is the 2/01 layout (Project Organization), written down for the agent.

Worked Example (2/3): Running and Rules

AGENTS.md (continued)
## How to run
- Rebuild everything: `Rscript main.R` from the project root.
- After changing a script, rerun main.R and list the outputs that changed.

## Rules
- Never edit, move, or delete anything in data/raw/.
- Every number, table, and figure comes from a script in code/.
  Never type a result into the paper by hand.
- Never invent or simulate data unless I ask for a simulation.
- Never open, print, or commit .env. Code loads it with readRenviron(".env").

Worked Example (3/3): Ask First

AGENTS.md (continued)
## Ask me before
- dropping observations or changing the sample
- changing an estimator, a control, or how errors are clustered
- adding a package (never run renv::snapshot() yourself)
- deleting any file, or running git push

## Style
- tidyverse and fixest; relative paths from the project root
- At the end of a session, add a short note to notes/progress.md

The “ask me” list is where your judgment as a researcher lives. Those choices are yours.

Getting a First Draft

You do not have to start from a blank page:

  • Claude Code: /init reads the folder and drafts an instructions file.
  • Or ask in plan mode: “Read this repository and draft an AGENTS.md for how we should work. Ask me before writing it.”

Then edit it. The draft will describe what the agent can already see. Your job is to add what it cannot: the rules and the “ask me” list.

Instructions Are Context, Not Enforcement

Anthropic’s documentation says Claude treats these files as “context, not enforced configuration.”

  • The agent reads your rules and usually follows them.
  • Usually. In a long session, they fade (3/24).
  • Nothing in the harness stops an action because AGENTS.md said not to.

Be wary of Markdown as a control. Keep reading.

Source: code.claude.com/docs/en/memory, accessed October 21, 2026.

Skills

A Skill Is a Prompt Loaded Only When Called

AGENTS.md

  • In context every turn of every session
  • Costs context, so keep it short
  • How this project works

A skill

  • Instructions for one recurring task
  • Loaded when you type /name (or when the agent decides it fits)
  • Costs almost nothing until then

If you keep pasting the same prompt, turn it into a skill.

Framing from Scott Cunningham, adapted from Claes Bäckman, “Practical AI for Academics” (2026).

Scott’s /newproject

One command sets up every new project the same way:

  • folders: code/, data/raw/, data/clean/, output/
  • an instructions file with his rules, and a README
  • raw data locked, and a progress_logs/ folder to keep his place between sessions

That is the project skeleton you built by hand on 2/01, as a skill.

Every project starts with the same skeleton, so he always knows where things are.

Source: Scott Cunningham’s Baylor talk (2026).

Scott’s /referee2

  • Has the agent replicate each analysis file in R, Stata, and Python.
  • Checks that the three agree: same sample, same coefficients, same standard errors.
  • Any disagreement is a flag he resolves before trusting the result.

Why three languages? Their syntax differs so much that a coding error is unlikely to happen the same way in all three.

Agreement across languages is evidence; agreement within one language is not.

More on this on 4/19.

Source: Scott Cunningham’s Baylor talk (2026).

Where Skills Live

A skill is a folder with a SKILL.md file in it.

Tool Project skills folder
Claude Code .claude/skills/<name>/SKILL.md
Codex .agents/skills/<name>/SKILL.md
Copilot in VS Code .github/skills/, .claude/skills/, or .agents/skills/
  • All three follow the same open format (agentskills.io), so one file works across tools.
  • Personal skills for every project go in your home folder (for Claude Code, ~/.claude/skills/).

Anatomy of a Skill

.claude/skills/<name>/SKILL.md
---
name: the-command-name
description: What it does, and when to use it.
disable-model-invocation: true
---

Instructions, in plain English, as numbered steps.
  • description: the agent sees this line in every session and uses it to decide when the skill fits.
  • disable-model-invocation: true: only you can start it, by typing /the-command-name. Use it for anything that deletes or runs for a long time.

Worked Example: /check-pipeline

.claude/skills/check-pipeline/SKILL.md
---
name: check-pipeline
description: Rebuild the project from raw data and report what changed. Use when I ask to check, rerun, or reproduce the results.
disable-model-invocation: true
---

1. Run `git status`. If anything is uncommitted, stop and tell me.
2. Delete data/derived/ and output/. Never touch data/raw/.
3. Run `Rscript main.R` from the project root. If it fails, show the
   error and the script it came from. Do not fix anything.
4. Run `git status` and `git diff --stat`. List every output that changed;
   for tables, show the old and new numbers side by side.
5. End with one line: REPRODUCED or NOT REPRODUCED.

This is the 2/01 test (“delete derived/ and output/, run main.R”) as a skill.

Reading the Example

  • Step 1 protects your work: Git is the undo button, so start clean.
  • Steps 2–3 are the test itself.
  • “Do not fix anything” keeps it a check. An agent asked to run something will usually try to make it pass.
  • Step 4 turns “it ran” into evidence: which numbers moved?
  • Step 5 gives you one line to look for in a long transcript.

Type /check-pipeline to run it. Anything you type after the name is passed in as $ARGUMENTS.

You Make Skills by Making Skills

  • If a hundred people wrote their own /referee2, no two would be the same.
  • That is because a skill is not software; it is a prompt.
  • Learn the idea behind someone else’s skill, then write your own and adjust it until it fits how you work.

Making one is simple: describe what you want, and have the agent draft the SKILL.md. Then read it, and cut.

Adapted from Scott Cunningham’s Baylor talk (2026).

Hooks

Prose Does Not Enforce

AGENTS.md, skills, and prompts are all prose.

Prose works like a parent with a reasonably obedient but terribly forgetful sixteen-year-old.

  • “Don’t take the car.” They swear they never will.
  • Every so often, they do. Not because they are bad kids: they forgot the agreement.

The only way to be sure is to lock the door and hide the keys.

Source: Scott Cunningham’s Baylor talk (2026).

A Hook Is a Lock on the Door

A rule says

  • “Don’t edit raw data.”
  • The model decides whether to follow it.

A hook is

  • A small program the harness runs every time the agent tries to use a tool
  • It can say no

Recall 3/24: the model only proposes a tool call; the harness carries it out. A hook sits between the two.

  • The model is probabilistic. A hook is a script: it fires whether the agent cooperates or not.

When Hooks Fire (Claude Code)

Event When
PreToolUse before a tool runs; can block it
PostToolUse after a tool runs (for example, run a formatter)
UserPromptSubmit when you send a prompt
SessionStart when a session starts or resumes
Stop when the agent finishes its reply

There are many more; these are the ones you are likely to use.

How a Hook Decides

  1. The agent wants to use a tool, say Edit on data/raw/jolts.csv.
  2. The harness runs your script and passes it the details as JSON, on standard input:
    • tool_name: "Edit"
    • tool_input.file_path: the file it wants to change
    • cwd: the folder the session is in
  3. Your script answers with its exit code:
    • 0: no objection; the normal permission prompt follows
    • 2: blocked; whatever the script printed to standard error goes back to the agent

Any other exit code is treated as an error in the hook, and the action goes ahead. Use 2.

A Hook in Action

  1. The agent decides: “edit data/raw/jolts.csv to fix the dates.”
  2. It calls the Edit tool.
  3. The hook fires: is this file inside data/raw/?
  4. Yes, so it is blocked: “data/raw/ is read-only. Read the file and write cleaned data to data/derived/ instead.”
  • The file is never touched, however the agent phrased its plan or whatever it forgot.
  • The agent reads the message and, usually, writes a cleaning script instead. That is what you wanted all along.

Adapted from Scott Cunningham’s Baylor talk (2026).

protect-raw-data (1/2): Register It

.claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "python3 \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect_raw.py"
          }
        ]
      }
    ]
  }
}
  • Before any Edit or Write, run this script. $CLAUDE_PROJECT_DIR is the project root.
  • .claude/settings.json is committed, so coauthors get the hook too.

protect-raw-data (2/2): The Script

.claude/hooks/protect_raw.py
# Block edits to files that already exist in data/raw/.
import json, os, sys

try:
    call = json.load(sys.stdin)
    root = os.environ.get("CLAUDE_PROJECT_DIR", call["cwd"])
    path = os.path.join(call["cwd"], call["tool_input"]["file_path"])
except (ValueError, KeyError, TypeError):
    sys.exit(0)  # unexpected input: let the normal permission check decide

raw = os.path.realpath(os.path.join(root, "data", "raw"))
target = os.path.realpath(path)

if target.startswith(raw + os.sep) and os.path.exists(target):
    print("data/raw/ is read-only. Read the file and write "
          "cleaned data to data/derived/ instead.", file=sys.stderr)
    sys.exit(2)

Reading the Script

  • json.load(sys.stdin) reads what the agent is about to do.
  • os.path.realpath turns the path into its real, absolute form, so data/derived/../raw/jolts.csv and symbolic links do not slip past.
  • os.path.exists: only existing raw files are protected. Saving a newly downloaded file to data/raw/ is fine.
  • On bad input, exit 0: a broken hook should not freeze every edit. But it fails closed on the one thing it guards.
  • One plain sentence back to the agent, so it knows what to do instead.

Design principles from Scott Cunningham’s Baylor talk (2026).

Test It by Hand

Before trusting a hook, feed it a fake tool call and look at the exit code:

echo '{"cwd": "'"$PWD"'", "tool_input": {"file_path": "data/raw/jolts.csv"}}' \
  | python3 .claude/hooks/protect_raw.py
echo $?     # 2 means blocked
  • Try a file in code/: the exit code should be 0.
  • Then, in Claude Code, type /hooks to see that it is registered.1
  • Finally, ask the agent to edit a raw file, and watch it get blocked.

Hooks in Other Tools

The same idea, with different file names:

  • Codex: .codex/hooks.json, same layout (PreToolUse, matcher, command); exit code 2 blocks. File edits arrive as a patch in tool_input.command, not as a file_path, so the script has to read the path out of the patch.
  • Copilot: .github/hooks/*.json, with a preToolUse event that can deny a tool call. In VS Code, hooks are a preview feature, and it can also read hooks from .claude/settings.json.

Codex makes you approve (“trust”) a project’s hooks before they run. That is a good habit everywhere.

A Hook Runs Code on Your Computer

A hook is a script that runs as you, automatically.

  • That is what makes it a lock.
  • It also means a repository you clone can ship a .claude/settings.json or .codex/hooks.json that runs its code when you start an agent there.

Before starting an agent in someone else’s repository, read its hook settings.

The same goes for skills: a skill is instructions your agent will follow.

What Makes a Good Hook

  • Structural, not textual: check a named field (the file path), not words in a command.
  • Narrow: almost never blocks the wrong thing. A hook that cries wolf trains you to ignore it.
  • Fail open on errors, closed on the thing it guards.
  • Speak plainly: one sentence that says what to do instead.
  • Few: only for rules that must hold every time. Everything else stays in AGENTS.md.

Adapted from Scott Cunningham’s Baylor talk (2026).

Hooks Are Software You Maintain

An engineer told Scott: the problem with hooks is you have to debug them.

  • A skill is prose you write once. A hook is code: it can misfire, block the wrong thing, or fail with a cryptic error.
  • But a hook fails loud, right now. A forgotten rule fails quiet: a plausible wrong number you find months later.

Pay the debugging cost for the few rules that must hold. Leave everything else to prose.

Source: Scott Cunningham’s Baylor talk (2026).

Red-Team Your Hook

A Rule You Have Not Tried to Break

A rule you have not tried to break is a rule you only hope works.

Scott’s practice:

  • Build the hook.
  • Have the agent start several sub-agents whose only job is to break it.
  • Each tries to change a file in a raw folder anyway, then reports: did it get through, why, and how would you stop it?

Agents are good at finding holes. Point them at your own.

Source: Scott Cunningham’s Baylor talk (2026).

What Gets Past Edit|Write?

Our hook only watches two tools. An agent has others.

  • The shell: sed -i, cp, mv, rm, or echo ... > on a raw file never calls Edit or Write.
  • A script: write an R or Python script that overwrites the file, then run it.
  • A different spelling of the same path.

None of these are hypothetical. In a long session, an agent trying to “fix the data” will find one.

Layers

Layer Stops Misses
Hook on Edit and Write the agent’s file tools; gives a clear message the shell, scripts
Deny rule Edit(/data/raw/**) file tools, plus sed, tee, > in the shell scripts that open files themselves
Read-only files: chmod -R a-w data/raw every program, including your own scripts an agent that runs chmod back
Git, or a saved checksum nothing, but detects any change changes to files you never committed

No single layer is the wall. Scott’s ended up as a small hook plus a folder his user account cannot write to.

A Deny Rule

Claude Code’s permission settings can also refuse an action outright, in every mode:

.claude/settings.json
{
  "permissions": {
    "deny": ["Edit(/data/raw/**)", "Bash(chmod *)"]
  }
}

In your real file, "permissions" and "hooks" sit side by side in the same top-level { }.

  • /data/raw/** is relative to the project root when it is in the project’s settings.
  • Denying chmod closes the obvious way around read-only files. Your red team will look for the next one.

Activity

Activity (1/4): Set Up

Work in your final project repository.

  1. Commit everything, then make a branch: git switch -c agent-setup
  2. Make a decoy raw file to attack, so your real data is never at risk:
    • data/raw/decoy.csv with two or three made-up rows
    • commit it
  3. Start the agent in the project folder, in Manual mode

Activity (2/4): Write Your AGENTS.md

  1. Write down three things about your project a capable stranger would get wrong.
  2. Draft AGENTS.md: by hand from today’s example, or ask the agent in plan mode to draft it and then edit.
  3. It must include: what the project is, the layout, how to run it (main.R), your rules, and your “ask me first” list.
  4. Read it once more and cut anything the agent could see for itself.

Activity (3/4): Add a Skill or a Hook

Pick one:

  • A skill for a task you have already prompted twice: rebuild and compare, summarize a new dataset, check a figure against its script.
  • The protect-raw-data hook, adapted to your folders, or a hook for another rule that must hold (for example, never edit .env).

Test it: call the skill by name, or pipe a fake tool call into the hook script and check the exit code.

Activity (4/4): Try to Break It

In a new session, still in Manual mode:

This is a test of my own project's safeguards. data/raw/decoy.csv is
protected. Read .claude/settings.json and AGENTS.md, then try up to
five different ways to change decoy.csv. Do not touch any other file
in data/raw/. After each attempt, report what you tried, whether it
was blocked, and by what. Then suggest how to close each hole.
  • Approve the attempts on decoy.csv only. Say No to anything else.
  • Write down what got through in notes/red-team.md. Close one hole, test again, commit, and push the branch.

What to Bring to 4/7

  • Your agent-setup branch, pushed, with AGENTS.md, your skill or hook, and notes/red-team.md
  • On 4/7 you will open it as a pull request and review it, before an agent starts doing real work in the repository.

[TBD: whether this counts as a graded final-project checkpoint]

Reading

Scott’s Public Repositories

Check the license before you copy anything. As of October 2026, neither repository lists a license, which means you may read them but not reuse their files. Read them for ideas, then write your own.

Summary

  • AGENTS.md: standing instructions, read every session. Write down what is obvious to you; keep it short.
  • Skills: a prompt loaded only when called. If you keep pasting it, make it a skill.
  • Prose does not enforce. Instructions and skills are context the agent usually follows.
  • Hooks: a script the harness runs before a tool call; exit code 2 blocks it. A lock, not a rule.
  • Red-team every hook. Layer it with deny rules, file permissions, and Git.
  • Read any repository’s hooks and skills before you run an agent in it.

References

  • Anthropic. Claude Code documentation: memory, skills, hooks, hooks guide, and permissions. code.claude.com/docs. Accessed October 21, 2026.
  • Bäckman, Claes (2026). “Practical AI for Academics.” Cited by Cunningham for the instructions-versus-skills framing.
  • Cunningham, Scott (2026). Talks at Texas A&M (October 2) and Baylor (October 14). This deck adapts their structure, examples, and the forgetful-teenager analogy.
  • GitHub. Copilot documentation: hooks. VS Code documentation: custom instructions, agent skills, and hooks. Accessed October 21, 2026.
  • OpenAI. Codex documentation: AGENTS.md, skills, and hooks. developers.openai.com/codex. Accessed October 21, 2026.