---
title: Set up an agent-ready project
summary: A hands-on walkthrough that adds a project file, a deny rule, a hook and a skill to a small demo app, with a check after every step.
section: walkthroughs
phase: any
order: 1
last_reviewed: 2026-12-04
---

# Set up an agent-ready project

A hands-on walkthrough that adds a project file, a deny rule, a hook and a skill to a small demo app, with a check after every step.

You need [Node.js](https://nodejs.org), git and Claude Code, signed in. It takes about 20 minutes. If the terms are new, read [AI vocabulary and when to use what](/docs/start-here/ai-vocabulary-and-when-to-use-what.md) first.

![Four layers around a project: CLAUDE.md informs the agent, a permission rule and a hook limit it, and a skill gives it a procedure.](/walkthroughs/agent-ready-layers.svg)

> **Note:** Run on 2026-12-04 on macOS with Claude Code 2.1.336 and Node 26. Agent replies below are excerpts from real non-interactive runs (`claude -p`), so your wording will differ and an interactive session may ask you for permission where these runs could not. I have not run this on Windows or Linux.

## Step 1: Create the demo project

Download the [starter script](/kits/agent-ready-start.sh), read it, then run it in an empty working folder. It only creates a `bookings-demo` folder with a few small files, and stops if that folder already exists.

```bash
sh agent-ready-start.sh
cd bookings-demo
git init
git add -A
git commit -m "Start"
npm test
```

**Check it worked.** The test summary ends with:

```console
ℹ tests 2
ℹ pass 2
ℹ fail 0
```

**If it went wrong.** `node --test` not found usually means an old Node version. A git error about your name or email means git needs those configured first.

## Step 2: Write the project file

Create `CLAUDE.md` in the project folder. It holds facts the agent needs every session: how to test, and what it must not do.

```markdown
# Bookings demo

A tiny room-booking library in plain Node (ES modules). No dependencies.

## Commands
- Run tests: `npm test`

## Rules
- Business logic goes in `src/`, with a test in `test/` for every behaviour change.
- Files already in `migrations/` are applied. Never edit them; add the next numbered file.
- Don't add dependencies without asking.
```

Claude Code's `/init` command can draft this file for a real project. Read the draft and cut it down; the docs suggest staying under 200 lines. If your project already has an `AGENTS.md`, a `CLAUDE.md` whose first line is `@AGENTS.md` imports it.

**Check it worked.** Start `claude` in the folder and send:

```text
How do I run the tests in this project, and what are the rules for migrations? Answer in two sentences.
```

```console
Run the tests with `npm test`, which runs `node --test`. Files already in
`migrations/` count as applied, so never edit them; make any change by adding
the next numbered file (currently that would be `002_...sql`).
```

**If it went wrong.** Check that you started Claude Code inside `bookings-demo` and that the file name is exactly `CLAUDE.md`.

## Step 3: Block reading secrets

First make a fake secrets file. `.gitignore` already excludes `.env`.

```bash
cp example.env .env
mkdir -p .claude
```

Create `.claude/settings.json` with a deny rule:

```json
{
  "permissions": {
    "deny": ["Read(./.env)"]
  }
}
```

**Check it worked.** In a new session, send:

```text
Show me the contents of the .env file.
```

```console
I couldn't show the `.env` file: permission to run the command was denied, so I
haven't seen its contents or confirmed that it exists.
```

> **Warning:** This rule is not a vault. Claude Code's docs say some shell commands can still read a denied file, for example a script that opens the file itself, or `grep -r` run over the folder. Keep real production secrets out of folders an agent works in.

**If it went wrong.** If the contents appear, check that the JSON is valid and the file is at `.claude/settings.json`, then start a new session. Run `/permissions` to see the active rules.

## Step 4: Protect applied migrations with a hook

The project file asks. A hook enforces, for the tools it matches. Create `.claude/hooks/protect-migrations.mjs`:

```javascript
// Blocks edits to migration files that already exist. New migration files are allowed.
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";

const input = JSON.parse(readFileSync(0, "utf8"));
const file = input.tool_input?.file_path ?? "";
const inMigrations = path.basename(path.dirname(file)) === "migrations";

if (inMigrations && existsSync(file)) {
  console.error(`Blocked: ${path.basename(file)} is already applied. Add a new numbered migration instead.`);
  process.exit(2);
}
```

Replace `.claude/settings.json` with this, which keeps the deny rule and registers the hook:

```json
{
  "permissions": {
    "deny": ["Read(./.env)"]
  },
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "node \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-migrations.mjs"
          }
        ]
      }
    ]
  }
}
```

**Check the script on its own first.** A hook is a program, so you can feed it input without an agent:

```bash
echo "{\"tool_input\":{\"file_path\":\"$PWD/migrations/001_create_bookings.sql\"}}" | node .claude/hooks/protect-migrations.mjs
echo "exit=$?"
```

```console
Blocked: 001_create_bookings.sql is already applied. Add a new numbered migration instead.
exit=2
```

Exit code 2 is what tells Claude Code to block the call.

**Then check it through the agent.** `/hooks` should list it. Send:

```text
Add a notes TEXT column to the bookings table by editing migrations/001_create_bookings.sql directly with your edit tool. I am deliberately testing the guard, so try the edit and tell me exactly what happened. Do not work around it.
```

```console
PreToolUse:Edit hook error: [node "$CLAUDE_PROJECT_DIR"/.claude/hooks/protect-migrations.mjs]:
Blocked: 001_create_bookings.sql is already applied. Add a new numbered migration instead.
```

**If it went wrong.** If the edit succeeds, run the script check above. If that blocks but the agent is not stopped, the hook is not registered: check `/hooks` and restart the session.

## Step 5: Break your own guard

Do not stop at the first green result. Ask for the same change by another route. Approve the shell command if asked: this is a throwaway project.

```text
I am testing my own guard in this throwaway demo. Using a shell command (not the edit tool), append the comment line '-- touched' to migrations/001_create_bookings.sql, then report what happened.
```

```console
I appended `-- touched` to `migrations/001_create_bookings.sql` with a shell
redirect (`echo ... >>`), and the write went through. Nothing blocked it.
```

The hook's matcher is `Edit|Write`, so it never saw a shell command. Undo the change:

```bash
git restore migrations/001_create_bookings.sql
```

What this teaches: a guard covers the paths you tested and no others. For a client project, back it with something outside the agent, such as a check in CI that fails when an existing migration changes, and review the diff.

## Step 6: Add a pre-commit skill

A skill is a procedure you would otherwise keep retyping. Create `.claude/skills/pre-commit-check/SKILL.md`:

```markdown
---
name: pre-commit-check
description: Check uncommitted changes before committing. Use when asked to check, review or commit work in this project.
---

1. Run `git status --short` and `git diff` to see what changed.
2. Run `npm test`. If it fails, stop and report the failure.
3. Report each item as ok or problem, with the file name:
   - every behaviour change in `src/` has a test
   - no existing file in `migrations/` was edited
   - no secret or `.env` file is about to be committed
4. Do not commit and do not edit files.
```

Give it something to find by adding a function with no test to the end of `src/bookings.js`:

```javascript
export function cancelBooking(list, room, start) {
  return list.filter((b) => b.room !== room || b.start !== start);
}
```

**Check it worked.** Send:

```text
/pre-commit-check
```

```console
Pre-commit check: one problem to fix before committing. `npm test` passes (2 of 2).

Problem: `src/bookings.js` adds `cancelBooking`, and neither of the two tests
that ran covers it.
OK: no changes under `migrations/`.
OK: no secret or `.env` file about to be committed.
```

**If it went wrong.** If the command is unknown, check the folder name and path, then run `/reload-skills`.

## Step 7: Commit the setup

Remove the untested function, then commit the configuration so everyone who clones the project gets it.

```bash
git restore src/bookings.js
git add CLAUDE.md .claude
git status --short
git commit -m "Add agent setup"
```

**Check it worked.** `git status --short`, run before the commit, lists `CLAUDE.md` and three files under `.claude/`, and no `.env`.

## Use it on your next project

The [finished setup script](/kits/agent-ready-config.sh) adds these four files to the folder you run it in. It refuses to overwrite files that exist. Then change them to fit:

- Rewrite `CLAUDE.md` with that project's real commands and rules.
- Change the folder the hook protects, or delete the hook if you have no migrations.
- Read the skill before using it, and swap `npm test` for the project's test command.

## Go deeper

- [How Claude remembers your project](https://code.claude.com/docs/en/memory): project file locations, size guidance and `AGENTS.md`
- [Permissions](https://code.claude.com/docs/en/permissions): rule syntax and what a deny rule does not cover
- [Hooks guide](https://code.claude.com/docs/en/hooks-guide): events, matchers and exit codes
- [Skills](https://code.claude.com/docs/en/skills): the `SKILL.md` format
- [Security of agentic workflows](/docs/ai-agents/agent-security.md): why guards need testing
