Course contents
Claude Code CLAUDE.md, rules and skills: setup guide
On this page
What Claude Code reads
Claude Code has three file-based layers (memory docs, skills docs):
CLAUDE.md: always-on instructions, loaded at session start..claude/rules/*.md: modular rules; withpathsfrontmatter they load only for matching files..claude/skills/<name>/SKILL.md: on-demand procedures.
It also keeps auto memory, notes Claude writes itself from your corrections. That's separate from the files you write.
CLAUDE.md: where it goes
| Scope | Location | Shared with |
|---|---|---|
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, via git |
| Local | ./CLAUDE.local.md (add to .gitignore) | Only you, this project |
| User | ~/.claude/CLAUDE.md | Only you, all projects |
| Managed | An OS-level path set by IT, such as /etc/claude-code/CLAUDE.md on Linux | Everyone in the org |
Claude Code loads CLAUDE.md and CLAUDE.local.md from the directory you start in and every directory above it, and concatenates them. Files in subdirectories load later, when Claude reads or edits a file there.
Anthropic's guidance: aim for under 200 lines per CLAUDE.md. Put build commands, conventions, layout and "always do X" rules in it. Move multi-step procedures to skills and folder-specific guidance to path-scoped rules.
Imports
Pull other files in with @path:
@AGENTS.md
@docs/api-conventions.md
## Claude Code only
- Ask before running database migrations.
Relative paths resolve from the file that contains the import, and imports can nest up to four hops. Imports organize a long file, but they don't reduce its context cost: the imported text loads too.
CLAUDE.md and AGENTS.md together
Claude Code v2.1.277 and later can read AGENTS.md directly, with this default:
| Your repo has | Claude reads |
|---|---|
AGENTS.md, no CLAUDE.md or CLAUDE.local.md | AGENTS.md |
AGENTS.md and a CLAUDE.md or CLAUDE.local.md | CLAUDE.md only |
A CLAUDE.md that imports @AGENTS.md | Both, through the import |
To change this, open /config and set Project instructions to claude-md-and-agents-md. Claude Code never reads AGENTS.local.md, AGENTS.override.md or anything in .agents/.
For teams that use several tools, the simplest setup is a shared AGENTS.md and a one-line CLAUDE.md containing @AGENTS.md. That's what supabase/supabase does.
Path-scoped rules: .claude/rules/
Each .md file in .claude/rules/ covers one topic; subfolders are discovered recursively. Rules without paths load at launch like .claude/CLAUDE.md. Rules with paths load when Claude reads, writes or edits a matching file.
---
paths:
- "src/api/**/*.ts"
- "src/**/*.{ts,tsx}"
---
# API rules
- Validate every request body with the schemas in `src/api/schemas/`.
- Return errors as `{ code, message }`. Never return a stack trace.
paths is the only frontmatter field Claude Code reads from a rule. It accepts a YAML list or a comma-separated string, and brace expansion such as *.{ts,tsx} works. Patterns are relative to the folder that contains .claude.
Personal rules in ~/.claude/rules/ apply to every project on your machine.
Skills: .claude/skills/
| Location | Loads in |
|---|---|
.claude/skills/<name>/SKILL.md | This project; commit it to share |
~/.claude/skills/<name>/SKILL.md | All your projects on this machine |
<subfolder>/.claude/skills/... | Sessions started there, or once Claude works on files there |
A plugin's skills/ folder | Wherever the plugin is enabled, as /plugin-name:skill-name |
A minimal skill:
---
name: db-migration
description: "Create and check a database migration with the project's migration tool. Use when the user asks to add a column, change a table, or write a migration. Not for running migrations against production."
---
1. Read the current schema in `db/schema.sql`.
2. Generate a new migration with `pnpm db:new <name>`. Never edit an applied migration.
3. Run `pnpm db:check` and paste the output.
Every field is optional, but description is the one that matters most: it's what Claude matches against. Useful extras Claude Code supports:
| Field | Use |
|---|---|
when_to_use | Extra trigger phrases, appended to the description |
disable-model-invocation: true | Only you can run it (good for deploys and commits) |
user-invocable: false | Only Claude can run it (background knowledge) |
allowed-tools | Tools Claude can use without asking during that turn |
paths | Only activate for matching files |
context: fork | Run in a forked subagent |
The combined description and when_to_use text is cut at 1,536 characters in the skill listing, so put the key use case first.
Run a skill with /skill-name at the start of a message. Other tools reject Claude-only fields: claude.ai uploads and the Skills API accept only name, description, license, compatibility, metadata and allowed-tools.
Install a preset
npx presets-dev add nextjs --tool claudecreated .claude/rules/nextjs-rules.md
created .claude/skills/nextjs-code-review/SKILL.md
2 file action(s), 0 skipped. https://presets.dev
The rule uses paths for the App Router files, so it loads when Claude touches them and doesn't replace your CLAUDE.md. The skill runs with /nextjs-code-review or when you ask for a Next.js review.
Preview: Next.js rule for Claude Code and Next.js code review skill for Claude Code.
Check that it loaded
/memorylists theCLAUDE.mdfiles in play and lets you edit them./contextshows a breakdown of what's using the context window./skillslists skills; you can also ask "What skills are available?"/doctorruns a setup checkup, including duplicated or bloatedCLAUDE.mdcontent.
Common mistakes
- A
CLAUDE.local.mdthat silently hidesAGENTS.md. It counts as aCLAUDE.md, so the default stops readingAGENTS.md. Import@AGENTS.mdor change the setting. - Broken YAML in a skill. The skill still loads, but with empty metadata, so Claude can't match its description. Run
claude plugin validate .claude/skillsto find parse errors. - Frontmatter not on line one. If
---isn't the first line, the whole file is treated as content. - Skills in
.agents/skills/only. Claude Code doesn't read that folder. Symlink it or keep a copy in.claude/skills/.
Recap
CLAUDE.mdis always on; keep it under about 200 lines..claude/rules/*.mdwithpathsload only for matching files.- Skills live in
.claude/skills/;descriptiondrives automatic use. - Bridge to
AGENTS.mdwith@AGENTS.mdor the Project instructions setting.
Next step
Windsurf / Devin Desktop setup, or learn to write skills that trigger.