Claude Code is Anthropic's official AI coding agent, used by developers at companies from startups to Fortune 500. Learn more →
Claude Code GuideHow to Make Claude Code Follow Your Instructions
Claude Code is powerful, but sometimes it ignores what you tell it. Here's why that happens and exactly how to fix it with CLAUDE.md optimization, better prompt structure, and verification patterns.
To make Claude Code follow your instructions, put rules in a CLAUDE.md file at your project root, use ALL CAPS or bold for critical rules, keep instructions under 500 words, and add verification commands so Claude can self-check. When Claude ignores you, it's almost always a context or formatting issue — not a limitation of the tool.
This guide explains exactly why instructions get lost and gives you concrete techniques — from CLAUDE.md optimization to prompt structure patterns — to ensure Claude does what you want, every time.
Why Claude Sometimes Ignores Instructions
Before we fix the problem, let's understand what causes it. Claude ignores instructions for three main reasons:
1. Context Overflow
Claude has a limited context window. When your CLAUDE.md is 500 lines long, your prompt is detailed, and the conversation has been going for a while, older instructions get pushed out or diluted.
Think of it like a bucket of water. Every message, every file Claude reads, every instruction you give takes up space. When the bucket overflows, the oldest water (your early instructions) spills out.
2. Signal-to-Noise Ratio
Even when your instructions fit in context, they can get lost in noise. If your CLAUDE.md has 50 lines of boilerplate and one critical rule buried in the middle, that rule competes with everything else for Claude's attention.
Claude doesn't weigh all text equally. It processes everything, but important instructions can be overshadowed by nearby text that seems more relevant to the current task.
3. Conflicting Signals
Sometimes your instructions conflict with each other, or with what Claude learned during training. If you say "never use semicolons" but your codebase is full of semicolons, Claude receives mixed signals and has to guess.
Key insight: Claude isn't stubborn. When it ignores an instruction, something in your setup is making that instruction less salient. The fixes below address these root causes.
CLAUDE.md Optimization Techniques
Your CLAUDE.md file is the foundation. Get this right, and most instruction-following problems disappear.
The Golden Rule: Shorter Is Better
For every line in your CLAUDE.md, ask: "Would removing this cause Claude to make mistakes?"
If the answer is no, delete it.
Claude can reliably follow around 150-200 instructions, and the system prompt already uses about 50 of those. Every instruction you add competes for attention. Claude can infer a lot from your codebase -- it can see your folder structure, read your package.json, and understand your patterns from existing code. Don't waste context space telling it things it can figure out.
Bloated CLAUDE.md
# Project Overview
This is a React application for managing
tasks. We use modern JavaScript features
and follow best practices...
## Technology Stack
- React 18.2
- TypeScript 5.0
- Tailwind CSS
- Vite for bundling
- ESLint for linting
- Prettier for formatting
## Architecture
The application follows a component-based
architecture with hooks for state
management...
(continues for 200 more lines)
Focused CLAUDE.md
# Commands
- Build: npm run build
- Test: npm test
- Lint: npm run lint
# Code Style
- 2-space indent
- Single quotes
- No semicolons
- ALWAYS use TypeScript strict mode
# Rules
IMPORTANT: Run tests before committing
NEVER modify files in /config directly
Put Critical Rules First
Position matters. Claude pays more attention to text it encounters early. If you have rules that must never be broken, put them at the top of your CLAUDE.md.
# CRITICAL RULES (READ FIRST)
- NEVER push to main directly
- ALWAYS run tests before committing
- DO NOT modify the database schema without review
# Commands
- Build: npm run build
- Test: npm test
# Style Preferences
...
Use Sections for Scannability
Group related instructions under clear headings. This helps Claude quickly find relevant rules when working on specific tasks.
# Git Workflow
- Branch from main
- Use conventional commits
- Squash before merge
# Testing
- Write tests for new features
- Keep coverage above 80%
- Use Jest for unit tests
# API Guidelines
- Validate all inputs
- Return consistent error formats
- Document new endpoints
Prompt Structure That Works
Even with a perfect CLAUDE.md, how you phrase your prompts affects instruction-following. Here's what works.
Front-Load Important Constraints
Put your most important constraints at the beginning of your prompt, not buried at the end.
Constraints at end
Create a function that fetches user data
from the API, parses the response, handles
errors gracefully, and returns a formatted
object. Oh and don't use async/await, use
promises, and make sure to add TypeScript
types.
Constraints upfront
Using promises (not async/await) and
TypeScript types:
Create a function that:
1. Fetches user data from the API
2. Parses the response
3. Handles errors gracefully
4. Returns a formatted object
Be Explicit About What NOT to Do
Sometimes telling Claude what to avoid is more effective than telling it what to do.
I documented the exact instruction patterns that work best in a free guide — worth reading if you want consistent results.
Refactor this component.
DO NOT:
- Change the prop interface
- Modify the CSS class names
- Add new dependencies
DO:
- Extract repeated logic into hooks
- Add TypeScript types
- Improve error handling
Use Numbered Steps for Complex Tasks
When order matters, use explicit numbering. This gives Claude a clear sequence to follow.
Process the CSV file in this order:
1. First, backup the original file
2. Then remove duplicate rows
3. Then standardize the date format
4. Finally, save as processed.csv
IMPORTANT: Complete each step fully before
moving to the next.
Using Emphasis Effectively
Emphasis techniques work. Claude does pay more attention to emphasized text. But use them strategically.
ALL CAPS for Critical Rules
Reserve ALL CAPS for rules that must never be broken.
NEVER delete files without confirmation.
ALWAYS backup before bulk operations.
DO NOT modify production configs directly.
"IMPORTANT:" and "CRITICAL:" Prefixes
These prefixes signal that what follows needs special attention.
IMPORTANT: Run the test suite after any change
to the authentication module.
CRITICAL: The API key must never be logged
or committed to version control.
Don't Over-Emphasize
If everything is IMPORTANT, nothing is. Reserve emphasis for rules that truly matter.
Warning: Using ALL CAPS for every rule is like crying wolf. Claude will start treating emphasized text the same as regular text. Keep it rare and meaningful.
Context Management
Long conversations dilute instructions. Here's how to manage context effectively.
Start Fresh for New Tasks
When switching to a completely different task, use /clear or start a new Claude Code session. This gives you a clean context with your CLAUDE.md freshly loaded.
Use /compact Before Major Work
The /compact command summarizes your conversation history into condensed context, freeing up to 70% more token space. Use it before starting a major new feature within the same session. You can also pass instructions about what to keep:
/compact Keep the implementation approach, summarize exploration
Repeat Critical Constraints
For long sessions, restate important constraints periodically. Claude doesn't mind repetition. Adding a mode-switching line like "switching to Debug mode now" can also help reset expectations mid-conversation.
Now let's work on the payment module.
Reminder: We're using strict TypeScript and
the same error handling patterns as before.
Add a function that...
Use Summary Checkpoints
After complex work, ask Claude to summarize what was done. This reinforces the context.
Before we continue, summarize the changes
we've made so far and the patterns we've
established.
Use Skills for Domain-Specific Rules
If some instructions only apply to certain types of tasks, don't bloat your CLAUDE.md with them. Instead, create skills. Skills are loaded on demand -- Claude reads the description and only loads the full instructions when the task is relevant.
# .claude/skills/api-review/SKILL.md
---
description: Enforce API design standards when creating or modifying endpoints
---
When creating or modifying API endpoints:
- Validate all inputs with Zod schemas
- Return consistent error format: { error: string, code: number }
- Add OpenAPI annotations
- NEVER expose internal IDs in responses
This keeps your CLAUDE.md focused on universal rules while domain-specific standards load only when needed.
Use Hooks to Enforce Rules Automatically
If Claude keeps forgetting to run tests or lint before committing, don't rely on instructions alone -- use hooks. Hooks are automatic actions that fire on specific tool events, acting as quality gates.
For example, you can configure a hook to automatically run npm test after every file edit, or block commits that haven't passed linting. This removes the need for Claude to "remember" the instruction at all.
Verification Patterns
Don't just hope Claude followed instructions. Build verification into your workflow.
The "Show Before Do" Pattern
Ask Claude to explain its plan before executing.
Before making any changes, show me:
1. Which files you'll modify
2. What changes you'll make to each
3. How this follows our style guide
Only proceed after I approve.
The "Confirm Understanding" Pattern
Have Claude restate your requirements in its own words.
Before you start, summarize what you
understand the requirements to be.
I want to make sure we're aligned.
The "Checklist" Pattern
After Claude completes a task, have it verify against a checklist.
After making the changes, verify:
[ ] Tests pass
[ ] No TypeScript errors
[ ] Follows our naming conventions
[ ] No hardcoded values
Show me the checklist with results.
Common Mistakes to Avoid
- CLAUDE.md is too long: If your file is over 50-75 lines, it's probably too long. Trim ruthlessly. Keep only what Claude can't infer from your code.
- Burying important rules: Critical rules at line 150 might as well not exist. Move them to the top.
- Vague instructions: "Use good practices" means nothing. "Use 2-space indentation and single quotes" is actionable.
- Conflicting rules: If your CLAUDE.md says "no semicolons" but half your codebase uses them, Claude gets confused. Be consistent.
- Never checking: If you assume Claude followed instructions without verifying, you'll miss mistakes until they compound.
- Over-emphasizing: When everything is IMPORTANT or in CAPS, emphasis loses its power. Be selective.
- Ignoring context limits: Very long sessions degrade instruction-following. Start fresh when switching major tasks.
Quick Reference: Instruction Hierarchy
Claude prioritizes instructions roughly in this order:
| Priority | Source | Tips |
|---|---|---|
| Highest | Current prompt | Most recent instructions win. Use for task-specific rules. |
| High | Early CLAUDE.md | First lines get more weight. Put critical rules here. |
| Medium | Later CLAUDE.md | Still read, but lower priority. Use for nice-to-haves. |
| Lower | Earlier conversation | Fades as conversation grows. Repeat important constraints. |
| Lowest | Training data | Defaults when nothing else specified. Can be overridden. |
FAQ
Why does Claude follow some instructions but not others?
Instructions compete for attention. If a rule is buried, vague, or conflicts with other signals, it may be deprioritized. Move important rules up, make them specific, and ensure they don't conflict with your codebase.
Should I repeat instructions in every prompt?
For truly critical rules, gentle repetition helps, especially in long sessions. But don't repeat everything—that's what CLAUDE.md is for. Repeat only what's essential for the current task.
My CLAUDE.md is already short. What else can I try?
Use emphasis (CAPS, IMPORTANT:) for critical rules. Try the "Confirm Understanding" pattern before complex tasks. Consider whether your instructions conflict with patterns in your existing code. You can also move domain-specific rules into skills and enforce critical rules with hooks, so Claude doesn't need to "remember" them.
Does the order of rules in CLAUDE.md matter?
Yes. Claude pays more attention to text it encounters early. Put your most critical rules at the top, ideally in a clearly labeled section.
How do I know if my instructions are too vague?
If you could interpret the instruction multiple ways, it's too vague. "Use consistent formatting" is vague. "Use 2-space indentation and single quotes" is specific.
Related Guides
- How to Use CLAUDE.md Files — complete setup guide
- How to Write Better Prompts — prompt engineering techniques
- Claude Code Prompts & Examples — ready-to-use templates
- How to Use Plan Mode — safe exploration before execution
Free: The AI Growth Breakdown
See how one business went from 0 to 600 daily visitors in 14 days using AI. The exact tools and results.
Get the Free Breakdown →