Course contents

Claude Code CLAUDE.md, rules and skills: setup guide

beginner4 min readUpdated
  • Claude Code
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; with paths frontmatter 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

ScopeLocationShared with
Project./CLAUDE.md or ./.claude/CLAUDE.mdYour team, via git
Local./CLAUDE.local.md (add to .gitignore)Only you, this project
User~/.claude/CLAUDE.mdOnly you, all projects
ManagedAn OS-level path set by IT, such as /etc/claude-code/CLAUDE.md on LinuxEveryone 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:

CLAUDE.md
@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 hasClaude reads
AGENTS.md, no CLAUDE.md or CLAUDE.local.mdAGENTS.md
AGENTS.md and a CLAUDE.md or CLAUDE.local.mdCLAUDE.md only
A CLAUDE.md that imports @AGENTS.mdBoth, 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.

.claude/rules/api.md
---
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/

LocationLoads in
.claude/skills/<name>/SKILL.mdThis project; commit it to share
~/.claude/skills/<name>/SKILL.mdAll your projects on this machine
<subfolder>/.claude/skills/...Sessions started there, or once Claude works on files there
A plugin's skills/ folderWherever the plugin is enabled, as /plugin-name:skill-name

A minimal skill:

.claude/skills/db-migration/SKILL.md
---
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:

FieldUse
when_to_useExtra trigger phrases, appended to the description
disable-model-invocation: trueOnly you can run it (good for deploys and commits)
user-invocable: falseOnly Claude can run it (background knowledge)
allowed-toolsTools Claude can use without asking during that turn
pathsOnly activate for matching files
context: forkRun 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 claude
created .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

  • /memory lists the CLAUDE.md files in play and lets you edit them.
  • /context shows a breakdown of what's using the context window.
  • /skills lists skills; you can also ask "What skills are available?"
  • /doctor runs a setup checkup, including duplicated or bloated CLAUDE.md content.

Common mistakes

  • A CLAUDE.local.md that silently hides AGENTS.md. It counts as a CLAUDE.md, so the default stops reading AGENTS.md. Import @AGENTS.md or 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/skills to 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.md is always on; keep it under about 200 lines.
  • .claude/rules/*.md with paths load only for matching files.
  • Skills live in .claude/skills/; description drives automatic use.
  • Bridge to AGENTS.md with @AGENTS.md or the Project instructions setting.

Next step

Windsurf / Devin Desktop setup, or learn to write skills that trigger.