{"slug": "5-claude-md-patterns-that-make-ai-actually-follow-your-rules", "title": "5 CLAUDE.md Patterns That Make AI Actually Follow Your Rules", "summary": "A developer has identified five patterns for making AI coding assistants follow CLAUDE.md rules, based on managing production setups across a dozen project starters. The key insight is that CLAUDE.md files should be treated as system prompt prefixes with a working memory budget of under 800 tokens, not as documentation. The developer recommends using scoped CLAUDE.md files for different project areas, splitting compound rules into atomic statements, reframing positive rules as negative prohibitions, and ensuring the codebase already follows its own rules through well-configured project starters.", "body_md": "Have you ever set up a CLAUDE.md file, dropped in 200 lines of rules, and then watched the AI completely ignore half of them anyway?\n\nYou are not alone. The irony of writing instructions for AI coding assistants is that the same productivity trap applies to you: more rules ≠ better results.\n\nHere are five patterns that actually work, learned from managing production CLAUDE.md setups across a dozen project starters.\n\nThe biggest CLAUDE.md mistake is treating it like documentation. It is not documentation. It is a **system prompt prefix** — and system prompts have a working memory budget.\n\nA rough heuristic: keep your primary CLAUDE.md under 800 tokens (~600 words). Beyond that, context compression pushes older rules out when long files are open.\n\n**What to cut:**\n\nThe rule goes in CLAUDE.md. The rationale goes in a comment in the relevant file, or nowhere.\n\nClaude Code supports scoped CLAUDE.md files — rules in `src/api/CLAUDE.md`\n\napply only when files under `src/api/`\n\nare open. Use this.\n\nA frontend rule about \"never use inline styles\" has no business loading when the AI is working in your Express routes. A backend rule about \"always use parameterized queries\" does not need to be in context when fixing a CSS animation.\n\n**Practical layout:**\n\n```\nCLAUDE.md              # project-wide: stack, deploy process, critical invariants\nsrc/api/CLAUDE.md      # API-specific: auth patterns, error formats, rate limiting\nsrc/web/CLAUDE.md      # Frontend-specific: component conventions, state patterns\nscripts/CLAUDE.md      # Automation: env var handling, idempotency requirements\n```\n\nEach file stays under 300 tokens. Total loaded at any time: ~600 tokens. Still under budget.\n\nCompound rules fail silently. When you write:\n\n\"Functions should be small, pure, and well-named, with explicit return types and no side effects unless they are in service files.\"\n\n...the AI picks the parts it agrees with and ignores the rest. This is not a model quality problem — it is a parsing problem. Compound sentences create ambiguity about which clause is the constraint and which is the suggestion.\n\nSplit every compound rule into atomic statements:\n\n```\n## Functions\n- Max 30 lines. Extract helpers if exceeded.\n- Explicit return types on all exported functions.\n- No side effects except in `*Service.ts` and `*Repository.ts` files.\n```\n\nThree lines, three enforceable constraints, zero ambiguity.\n\n\"Use Zod for all schema validation\" is a positive rule. It tells the AI what to do, but not how strongly you mean it.\n\n\"Never use `any`\n\ntypes. Never use untyped `JSON.parse()`\n\nwithout a Zod schema.\" — these are negative rules. They draw a hard line.\n\nIn practice, AI assistants weight prohibitions more heavily than recommendations. This is because prohibitions reduce the valid solution space (easier to enforce) while recommendations just add a preference (easier to deprioritize under other pressures).\n\n**Reframe your positive rules as negative rules where you can:**\n\n| Positive | Negative |\n|---|---|\n| Use environment variables for all config | Never hardcode URLs or credentials |\n| Write tests for all public functions | Never ship a new exported function without a test file |\n| Use the existing logger | Never call `console.log` directly in production code |\n\nThe negative framing also makes violations easy to grep for.\n\nThe best CLAUDE.md is one that describes a codebase that already follows its own rules. When the starter project has ESLint configured, TypeScript strict mode on, and the folder structure already in place — the CLAUDE.md rules are reinforced by the code itself.\n\nThis is why project starters are worth spending time on. If your starter has `any`\n\ntypes everywhere and no linting, your CLAUDE.md rule against `any`\n\nis fighting the existing codebase instead of aligning with it.\n\nWe built the [Vibe Coder Kit](https://blncraft.gumroad.com/l/vibe-coder-kit) specifically for this: 12 production-configured starters (Next.js SaaS, Express + JWT, Node CLI, Chrome Extension, Discord Bot, FastAPI, and more) where the CLAUDE.md rules match what the code already does. Zero setup, immediate AI alignment.\n\nCLAUDE.md files fail the same way most documentation fails: they get long, stale, and comprehensive when they should be short, current, and opinionated.\n\nShort. Scoped. Atomic. Negative where possible. Backed by a codebase that already follows the rules.\n\nThat is the setup that makes vibe coding actually work.\n\n*BLN Craft builds developer tools for AI-native workflows. Follow us at blncraft.com for more.*", "url": "https://wpnews.pro/news/5-claude-md-patterns-that-make-ai-actually-follow-your-rules", "canonical_source": "https://dev.to/blncraft/5-claudemd-patterns-that-make-ai-actually-follow-your-rules-3kj1", "published_at": "2026-05-29 22:58:36+00:00", "updated_at": "2026-05-29 23:12:34.488446+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-agents"], "entities": ["Claude Code", "CLAUDE.md"], "alternates": {"html": "https://wpnews.pro/news/5-claude-md-patterns-that-make-ai-actually-follow-your-rules", "markdown": "https://wpnews.pro/news/5-claude-md-patterns-that-make-ai-actually-follow-your-rules.md", "text": "https://wpnews.pro/news/5-claude-md-patterns-that-make-ai-actually-follow-your-rules.txt", "jsonld": "https://wpnews.pro/news/5-claude-md-patterns-that-make-ai-actually-follow-your-rules.jsonld"}}