Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 13: Configuring a coding agent

Objectives: LO-13.1, LO-13.2, LO-13.3
Prerequisites: the Module 13 reading
Time: about 2.5 hours

In this lab you write the configuration of a coding agent for the course’s starter repository: a CLAUDE.md, a rule scoped to paths, a review skill, permission and hook settings, and a deny-only hook. Then you check each one in Python, including the hook, which you test by piping sample events into it.

No cell starts a coding agent or calls a model. The events are sample data in the shape the reading describes, and nothing you write here is installed into a real Claude Code setup.

Each exercise ends with a check cell that prints passed or fails with a message that says what is wrong. Run the cells in order, from the top, in a fresh kernel. The checks fail until you finish the exercise above them.

Setup

Inspect an event

Here are two sample PreToolUse events for the Bash tool, in the shape a hook reads on standard input: tool_name names the tool, and tool_input holds its arguments. The first proposes the project’s test command, and the second an unfamiliar command. Predict what a deny-only hook should print for each, then run the cell.

Exercise L13.1 (LO-13.1, ★★, about 25 minutes)

Write two instruction files. Write instructions(). Return a dictionary that maps the paths "CLAUDE.md" and ".claude/rules/fixtures.md" to each file’s text. The project instructions must name the integer cents convention, with the words “integer cents”, and the test command, python -m unittest discover -v. Give the rule front matter, between --- lines, whose only key is paths, set to a list containing "data/**", and add guidance that applies only to fixtures.

Exercise L13.2 (LO-13.1, ★★, about 25 minutes)

Resolve a small set of path scopes. Write matches(path, pattern). Return True when pattern is the same relative path as path, or when pattern is a folder followed by /** and path lies somewhere inside that folder. Compare whole path components, the names between slashes, using PurePosixPath, so database/ doesn’t count as data/. A /** pattern needs a file inside the folder: the folder’s own path doesn’t match. This checker handles only these two forms; Claude Code’s matching has more.

Exercise L13.3 (LO-13.2, ★★, about 25 minutes)

Describe a review skill. Write skill(). Return the complete text of a SKILL.md file. Its YAML front matter, between --- lines, sets name to review-labels and gives a description. Its body lists steps that use the words “diff”, “regression”, and “evidence”: inspect the diff, run the regression tests, and summarize the evidence. In your notes, write down one bounded task you would delegate to a subagent, and one you would keep.

Exercise L13.4 (LO-13.3, ★★, about 25 minutes)

Set a permission rule. Write settings(). Return a settings dictionary, shaped like .claude/settings.json, whose permissions allow list holds only the exact test command, in Bash(...) syntax. Under hooks, add one PreToolUse entry whose matcher is Bash, with a command hook that runs the project script .claude/hooks/review_command.py with Python. In your notes, explain what this hook does, and what changes if you remove it.

Exercise L13.5 (LO-13.3, ★★, about 25 minutes)

Test a deny-only hook. Write hook_source(). Return the full source of a Python script that reads one JSON event from standard input. For the exact PreToolUse Bash event that proposes the test command, it prints nothing. For any other event, and for input it can’t read as an event, it prints one JSON object whose hookSpecificOutput holds hookEventName "PreToolUse", permissionDecision "deny", and a permissionDecisionReason. It exits with status 0 either way. The check pipes events into the script in a Python subprocess. The script examines the command string and never runs it.

Summary

  • CLAUDE.md holds what every task needs, and a rule with paths adds guidance only when Claude works on matching files.

  • A skill packages a repeated review, with a description that says when it applies.

  • Permission rules and hook settings are data that Claude Code enforces, not text the model weighs.

  • A deny-only hook stays silent for the one command it lets through, denies everything else, malformed input included, and is tested by piping sample events into it.