If you write code with Claude Code, you have had this moment: every bug fix starts with retyping “run the tests first, change as little as possible, don't touch the migrations folder”; every pull request starts with “check for type errors, run lint, write the message in our format”. By the third time you type the same paragraph, it belongs in a file. Claude Code gives you two tools for that: CLAUDE.md, for things every session needs to know; and custom slash commands, for procedures you run over and over. They look alike, and putting something in the wrong one makes both worse — people who stuff a whole workflow into CLAUDE.md pay for hundreds of lines of context in every session, and people who learned only the old .claude/commands format from a 2025 tutorial miss that the official recommendation has moved to skills. Checked against Anthropic's official Claude Code docs on 5 December 2026 (Singapore time), this guide starts by telling the three pieces apart, then walks through writing a CLAUDE.md and a custom command, and ends with 7 pitfalls. Built-in slash commands (/init, /model, /usage and the rest) are not repeated here — the site already has a dedicated guide, see Related reading.

Fact check: The facts in this article were checked against Anthropic's official Claude Code documentation (code.claude.com/docs/en/commands, /skills, /memory) on 2026-12-05 (Singapore time). Details follow what the official docs show on the day.

Tell the three pieces apart: CLAUDE.md, custom commands, and built-in commands

Most people trip over the same thing when they first set up Claude Code: three pieces that look alike but solve different problems. Put something in the wrong one and the result is very different:

Piece What it is When it loads What goes in it
CLAUDE.md Project instruction file read at the start of every session Loaded automatically at the start of every session Facts every session needs: build commands, code conventions, directory structure, “always do X”
Custom commands (skills / .claude/commands) A prompt template you write, invoked with /name Body loads only when you call it; almost no context when unused Procedures you repeat: reviewing code, fixing issues, generating tests, pre-release checks
Built-in commands (/init, /model, /usage, and more) Built-in CLI feature commands Triggered when used Fixed operations: switching models, clearing context, checking usage, managing permissions

The one-line version: CLAUDE.md is “background knowledge”, a custom command is “a shortcut”, and a built-in command is “a button on the remote”. The official docs put it plainly: if a section of CLAUDE.md has grown into a multi-step procedure rather than a fact, move it into a skill; and long reference material that only matters sometimes should not sit in CLAUDE.md either — a skill's body loads only when it is used, so it costs almost nothing until you need it.

One more common confusion: custom commands now come in two forms. The old format is a Markdown file in .claude/commands/, where the filename without .md becomes the command name; the new form is a skill (.claude/skills/<name>/SKILL.md), invoked the same way with /name. The official docs are explicit: the old format still works, but skills are recommended for new work because a skill can also carry supporting files. Both forms are covered step by step in section 3.

Claude Code terminal welcome screen

Caption: The Claude Code terminal welcome screen: “Welcome back!” and the current model at the top, with the input prompt below — custom and built-in commands are both typed here starting with `/`. Screenshot of v2.0.1 (September 2025); the layout is essentially the same in current versions. Image source: a dzombak.com blog post, see https://www.dzombak.com/blog/2025/09/teaser-for-upcoming-claude-code-posts/

Writing CLAUDE.md: where it goes, how to write it, and how to confirm it loaded

Step 1: put it in the right place. CLAUDE.md can live in several places, loaded from broadest scope to most specific, so the instruction closest to where you launched ends up read last:

Location Scope What goes in it
Managed policy file Everyone in the company Company coding standards, security and compliance requirements
~/.claude/CLAUDE.md All projects on your machine Personal preferences: default package manager, usual testing habits
./CLAUDE.md or ./.claude/CLAUDE.md Everyone on this project, shared through the repo Project architecture, build commands, team conventions
./CLAUDE.local.md Only you, in this project Sandbox URLs, your usual test data — remember to add it to .gitignore

Two loading rules are the ones people miss most: CLAUDE.md files in parent directories load too — launching in foo/bar/ reads both foo/CLAUDE.md and foo/bar/CLAUDE.md; but a CLAUDE.md in a subdirectory loads on demand, only once Claude reads, writes, or edits a file in that subdirectory. Anyone counting on a subdirectory rule being active from launch will be disappointed the first time.

Step 2: write it the way the official docs describe. The test the docs give is practical: write instructions concrete enough to verify. Write “Run `npm test` before committing”, not “Test your changes”; write “API handlers live in `src/api/handlers/`”, not “Keep files organized”. Keep each file to a target of under 200 lines — longer files cost more context and get followed less reliably; instructions that only matter for part of the codebase belong in .claude/rules/, scoped with paths to specific file types or directories so they load only when relevant.

Step 3: confirm it actually loaded. Don't trust the feeling — run /context all in a session and look at the Memory files list for your file. If it is not there, check three things: whether the file is in one of the locations in the table above; whether it is sitting in a subdirectory waiting to load on demand; and whether the filename is spelled right (CLAUDE.md, all capitals). For a new project, run /init and let Claude draft a starter file from the codebase, then refine it with /memory; to audit the whole set for outdated or conflicting instructions, run /doctor prompt-audit (requires v2.1.283 or later) — it reports findings and proposes edits, and nothing in your files changes until you ask it to apply them.

CLAUDE.md can import other files with @path, for example @README.md or @docs/workflow.md, up to four levels deep. Two details matter: an @README written inside backticks is not imported (it stays literal text), and a path containing spaces needs a backslash before each space — without it, the path ends at the first space, and a path wrapped in quotes is not imported at all.

A 29-line example CLAUDE.md

Caption: A 29-line example CLAUDE.md: project and stack first (Stack), then code style (Code Style), folder conventions (Folder Conventions), testing (Testing), and a Do Not section, ending with an HTML comment reminding the author to keep the file under 200 lines. The example comes from a third-party tutorial; its structure matches the official docs' writing advice. Image source: sunray.dev, see https://sunray.dev/coding-with-ai

Writing your first custom command: the new skill form and the old format

Decide first whether the command is for you or for the team, then choose where to save it: ~/.claude/skills/ (or ~/.claude/commands/) is personal and available in all your projects; .claude/skills/ (or .claude/commands/) inside a project is shared with the team through version control. The most common symptom of saving it in the wrong place is “it works on my machine but my teammate doesn't have it” — check the path before suspecting anything else.

The new form: write a skill. Create .claude/skills/fix-issue/SKILL.md in your project. It has two parts: YAML frontmatter at the top with a one-line description and an argument hint, then the body — what you want Claude to do when the command runs:

---
description: Fix a GitHub issue by number. Use when the user gives an issue number.
argument-hint: "[issue-number]"
---
Fix issue #$ARGUMENTS.
1. Read the failing test or the steps in the issue.
2. Make the smallest change that fixes it.
3. Run `npm test` and report the result.

Save it, then type /fix-issue 42 in a session: $ARGUMENTS is replaced with 42, and Claude receives “Fix GitHub issue 42 following our coding standards…”. The more specific the description, the better Claude knows when to use the skill on its own — “Fix an issue by number, use when given an issue number” beats “Fix issues”.

The old format: a Markdown file in .claude/commands/. The same example saved as .claude/commands/fix-issue.md gives you the same /fix-issue — the filename without .md is the command name. The frontmatter works the same way, except the name and paths fields are not supported. The official docs are clear about the direction: the old format still works, but skills are recommended for new work, because a skill can also carry supporting files (reference docs, scripts) while the old format is a single Markdown file.

Four rules for passing arguments — follow them and it just works:

  1. $ARGUMENTS is all the arguments. In /fix-issue 123 high-priority, $ARGUMENTS is 123 high-priority.
  2. Take arguments by position with $ARGUMENTS[N] or the shorthand $0, $1. /migrate-component SearchBar JavaScript TypeScript replaces $ARGUMENTS[0] with SearchBar, $ARGUMENTS[1] with JavaScript, and $ARGUMENTS[2] with TypeScript; you can also declare named arguments in frontmatter.
  3. Quote multi-word arguments. In /my-skill "hello world" second, $0 is hello world and $1 is second; without the quotes, hello and world become two separate arguments.
  4. If the body has no placeholder at all, the arguments are not lost. Claude Code appends ARGUMENTS: <your input> to the end of the skill content. The other way round, an indexed placeholder with no matching argument (say $2 when you passed only one argument) stays in the content unchanged — if you spot an unexpanded $2 in what Claude received, count how many arguments you actually passed.

You can chain several skills in one message: /write-tests /fix-issue 123 loads both skills and passes 123 as $ARGUMENTS to each. Up to six skills can be chained in one line; anything beyond that does not expand. Before chaining, check the two skills really want the same arguments — if the wrong arguments go in, the caller is at fault, not the skill.

Seven pitfalls people actually hit

  1. Stuffing a whole procedure into CLAUDE.md. CLAUDE.md holds facts every session needs; a multi-step procedure is a skill's job. The test: is this section only used when doing one particular thing? If yes, move it to a skill. Long reference material goes the same way — don't make every session pay for it in context.
  2. Writing CLAUDE.md too long. The official target is under 200 lines per file. Past that, it costs more context and gets followed less. Split it first: things that only apply to part of the repo go into a subdirectory CLAUDE.md or .claude/rules/; things that only apply to one file type get scoped with paths.
  3. Writing two instructions that contradict each other. “Always run the full test suite before committing” and “Small changes can be committed without tests” sitting side by side means Claude picks one arbitrarily — and which one is not your call. Run /doctor prompt-audit regularly to find outdated, duplicated, and conflicting instructions.
  4. Committing CLAUDE.local.md to the repo. That file is for personal preferences: sandbox URLs, your usual test data, private shortcuts. Forget to add it to .gitignore and it ships with the code for the whole team to see.
  5. Assuming a subdirectory CLAUDE.md is active from launch. It loads on demand: only when Claude reads or writes a file in that subdirectory. Put a critical rule only in a subdirectory file and expect it every session, and it will fail you the first time.
  6. Forgetting quotes around arguments, or leaving a $2 with no argument. Multi-word arguments without quotes get split in two; a $2 in the body with only one argument passed stays in the content literally, and Claude receives an unexpanded placeholder.
  7. Writing secrets and passwords into CLAUDE.md. The file is read wholesale into context and committed to the repo. Keys and tokens belong in environment variables; the Do Not section in the example above says it plainly: no hardcoded secrets, never committed.

One last point the official docs repeat: CLAUDE.md and custom commands are only “context”, not “enforced configuration”. Claude will try to follow them, but they cannot block any action — if something must never happen (never delete files in migrations/, never touch production data), that needs a mechanism such as a PreToolUse hook, not one more “never do this” line in CLAUDE.md.

Related reading