Claude Code Ignoring CLAUDE.md? 7 Fixes That Actually Work

Published Oct 26, 2026 · 6 min read

"Claude Code ignores my CLAUDE.md" is one of the most common complaints from people building with it. The short answer: CLAUDE.md is a note, not a lock. Claude reads it when the session starts, but by the time you're two hours and three compactions in, a rule buried in line 140 is competing with thousands of lines of code and chat. The fix is to make CLAUDE.md easier to follow, and to move the rules that must never break into the parts of Claude Code that actually enforce them.

1. Check that it's actually loaded

Run /memory inside Claude Code. It lists the memory files loaded for this session. If your file isn't there, check the usual suspects:

2. Put hard rules at the top, and make them checkable

Rules near the top of a short file get followed far more reliably than rules in the middle of a long one. Keep the file under about 100 lines and write rules Claude can verify, not vibes:

## Rules (read first)
- Run `pnpm test` and `pnpm lint` before saying a task is done.
- Never edit files in src/generated/. Change the schema and run `pnpm codegen`.
- Don't add dependencies without asking first.
- One task at a time. Don't refactor code you weren't asked to touch.

## Commands
- Dev: `pnpm dev` · Test: `pnpm test` · Types: `pnpm typecheck`

"Write clean code" gets ignored because there's nothing to check. "Run pnpm test before saying done" is a rule Claude can actually follow. Our CLAUDE.md template uses this layout.

3. Turn "never" rules into permission deny rules

If a rule starts with "never", it doesn't belong only in CLAUDE.md. Put it in .claude/settings.json, where Claude Code enforces it no matter what the model decides:

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Edit(./migrations/**)",
      "Bash(git push:*)"
    ],
    "ask": [
      "Bash(npm publish:*)"
    ]
  }
}

Denied calls are blocked outright; ask rules make Claude stop and get your approval. Commit this file so the whole team gets the same guardrails.

4. Enforce the rest with a PreToolUse hook

Some rules are too specific for a permission pattern. A hook runs your own script before each tool call. Exit code 2 blocks the call, and whatever you print to stderr is shown to Claude, so it learns why. Save this as .claude/hooks/protect-generated.sh and make it executable:

#!/usr/bin/env bash
# Blocks edits to generated files and tells Claude what to do instead.
f=$(jq -r '.tool_input.file_path // empty')
case "$f" in
  */src/generated/*|*.gen.ts)
    echo "Blocked: $f is generated. Edit the schema and run pnpm codegen." >&2
    exit 2 ;;
esac
exit 0

Then register it in .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-generated.sh" }
        ]
      }
    ]
  }
}

Want this without writing it yourself? Our free safety hooks already block rm -rf, force pushes and edits to .env, lockfiles and .git.

5. Re-inject the key rules in long sessions

The longer a session runs, the less weight your CLAUDE.md gets. A UserPromptSubmit hook's output is added to the context with every prompt you send, so a short reminder stays fresh. A SessionStart hook with the compact matcher re-adds it right after compaction:

{
  "hooks": {
    "UserPromptSubmit": [
      { "hooks": [ { "type": "command",
        "command": "cat \"$CLAUDE_PROJECT_DIR\"/.claude/reminder.md" } ] }
    ],
    "SessionStart": [
      { "matcher": "compact",
        "hooks": [ { "type": "command",
          "command": "cat \"$CLAUDE_PROJECT_DIR\"/.claude/reminder.md" } ] }
    ]
  }
}

Keep reminder.md to three to five lines: your top rules only. Every line here is sent with every prompt, so it also costs usage.

6. Use /clear between tasks

Most "it stopped following my rules" stories are really "the session got too long." When you finish a task, write a quick HANDOFF.md and run /clear. The fresh session reloads CLAUDE.md at full strength. If you're mid-task, /compact keep the rules, plan and file paths is the next best thing.

7. Split rules by folder in a monorepo

One giant root file with frontend, backend and infra rules means most of it is noise for any single task. Put a short CLAUDE.md in each package so rules only load where they apply, and pull shared docs in with imports:

# ./CLAUDE.md (root, keep it tiny)
How to install, run and test. Shared rules only.
@docs/testing.md

# ./apps/web/CLAUDE.md
React + Tailwind rules. Only loads when Claude works in apps/web.

# ./services/api/CLAUDE.md
API and database rules. Only loads when Claude works in services/api.

Same problem in Cursor?

Cursor has its own version of this: project rules must be .mdc files in .cursor/rules/ with frontmatter that says when they load, or they're skipped. Our Cursor rules examples show the format, and the Cursor Rules Pack ($19) has 18 ready-made rules, each scoped to the right files.

Skip the setup

The Claude Code Agent Starter Kit ($39) ships 5 short, rules-first CLAUDE.md templates (Next.js, FastAPI, Node API, game dev, monorepo), 3 safety hooks, 4 subagents and 4 skills, all tested together. Get the Starter Kit

FAQ

Why does Claude Code ignore my CLAUDE.md?

CLAUDE.md is context, not configuration. Claude reads it at the start of a session, but in long sessions it competes with everything else in context, and vague or buried rules get skipped. Rules that must never be broken belong in settings.json permissions or hooks.

Is CLAUDE.md enforced?

No. Claude Code's docs describe CLAUDE.md as memory that guides behaviour. Permission rules in .claude/settings.json and PreToolUse hooks are enforced by Claude Code itself, whatever the model decides.

How do I check that CLAUDE.md is loaded?

Run /memory inside Claude Code. It lists the memory files loaded for the session, such as ~/.claude/CLAUDE.md and ./CLAUDE.md, and lets you open them to edit.

How do I stop Claude Code editing a file or folder?

Add a deny rule such as Edit(./migrations/**) to permissions.deny in .claude/settings.json, or add a PreToolUse hook on Edit|Write that exits with code 2 for that path. Both block the edit; a line in CLAUDE.md only asks.

The VibeKit Dispatch

One tested Claude Code / Cursor workflow every week. No hype, unsubscribe anytime.