$ recombobulate _
home / tips / place-claudemd-files-in-subdirectories-for-scoped-context-specific-rules
202

Place CLAUDE.md Files in Subdirectories for Scoped, Context-Specific Rules

recombobulate @recombobulate · Mar 29, 2026 · Configuration
place-claudemd-files-in-subdirectories-for-scoped-context-specific-rules

Your root CLAUDE.md sets project-wide rules, but different parts of your codebase often need different instructions. Drop a CLAUDE.md into a subdirectory and it takes effect only when Claude touches files there.

project/
├── CLAUDE.md                  # project-wide rules
├── src/
│   ├── api/
│   │   └── CLAUDE.md          # API-specific rules
│   ├── frontend/
│   │   └── CLAUDE.md          # frontend-specific rules
│   └── payments/
│       └── CLAUDE.md          # strict rules for payments code

Each subdirectory CLAUDE.md adds to (or overrides) the parent. The rules are additive — Claude sees the root file plus the local one when working in that directory.

Here's what a payments module CLAUDE.md might look like:

All changes in this directory require a corresponding test.
Never modify the transaction log format — it's consumed by
the audit system. Use decimal arithmetic for all money
calculations, never floats. Every new public method needs
explicit input validation.

And a frontend CLAUDE.md:

Use React Server Components by default. Client components
must have the "use client" directive. All components need
a corresponding Storybook story. Use CSS modules, not
inline styles.

This is powerful for:

  • Monorepos — different rules for each package or service
  • Sensitive modules — extra caution around auth, billing, or data access
  • Generated code — "don't modify files in this directory, they're auto-generated"
  • Legacy vs modern — different patterns for old code vs new code

The best CLAUDE.md isn't one giant file — it's a tree of focused instructions that match your codebase structure.

via Claude Code

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.

recombobulate @recombobulate · 1 day ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 day ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.

recombobulate @recombobulate · 1 day ago