User Input
Consider user input for:
- - Create new file from scratch
- - Improve existing file
- - Analyze and report on current file quality
- A specific path (e.g., for directory-specific instructions)
Step 1: Determine Target File
If not specified in user input, ask the user which file type to work with:
CLAUDE.md - Project context file loaded at the start of every conversation. Contains:
- Bash commands Claude cannot guess
- Code style rules that differ from defaults
- Testing instructions and preferred test runners
- Repository etiquette (branch naming, PR conventions)
- Architectural decisions specific to the project
- Developer environment quirks (required env vars)
- Common gotchas or non-obvious behaviors
AGENTS.md - Custom subagent definitions file. Contains:
- Specialized assistant definitions
- Tool permissions for each agent
- Model preferences (opus, sonnet, haiku)
- Focused instructions for isolated tasks
CLAUDE.md Guidelines
Based on official Claude Code documentation.
Core Principle
CLAUDE.md is a special file Claude reads at the start of every conversation. Include Bash commands, code style, and workflow rules. This gives Claude persistent context it cannot infer from code alone.
What to Include
| ✅ Include | ❌ Exclude |
|---|
| Bash commands Claude cannot guess | Anything Claude can figure out by reading code |
| Code style rules that differ from defaults | Standard language conventions Claude already knows |
| Testing instructions and preferred test runners | Detailed API documentation (link to docs instead) |
| Repository etiquette (branch naming, PR conventions) | Information that changes frequently |
| Architectural decisions specific to your project | Long explanations or tutorials |
| Developer environment quirks (required env vars) | File-by-file descriptions of the codebase |
| Common gotchas or non-obvious behaviors | Self-evident practices like "write clean code" |
Quality Test
For each line, ask: "Would removing this cause Claude to make mistakes?" If not, cut it.
If Claude keeps ignoring a rule, the file is probably too long and the rule is getting lost. If Claude asks questions answered in CLAUDE.md, the phrasing might be ambiguous.
Example Format
markdown
# Code style
- Use ES modules (import/export) syntax, not CommonJS (require)
- Destructure imports when possible (eg. import { foo } from 'bar')
# Workflow
- Be sure to typecheck when you're done making a series of code changes
- Prefer running single tests, and not the whole test suite, for performance
File Locations
- Home folder (): Applies to all Claude sessions
- Project root (): Check into git to share with your team
- Local only (): Add to for personal overrides
- Parent directories: Useful for monorepos where both and are pulled in automatically
- Child directories: Claude pulls in child CLAUDE.md files on demand
Import Syntax
CLAUDE.md files can import additional files using
syntax:
markdown
See @README.md for project overview and @package.json for available npm commands.
# Additional Instructions
- Git workflow: @docs/git-instructions.md
- Personal overrides: @~/.claude/my-project-instructions.md
Emphasis for Critical Rules
Add emphasis (e.g., "IMPORTANT" or "YOU MUST") to improve adherence for critical rules.
AGENTS.md Guidelines
Custom subagents run in their own context with their own set of allowed tools. Useful for tasks that read many files or need specialized focus.
Agent Definition Format
markdown
---
name: security-reviewer
description: Reviews code for security vulnerabilities
tools: Read, Grep, Glob, Bash
model: opus
---
You are a senior security engineer. Review code for:
- Injection vulnerabilities (SQL, XSS, command injection)
- Authentication and authorization flaws
- Secrets or credentials in code
- Insecure data handling
Provide specific line references and suggested fixes.
Required Fields
- name: Identifier to invoke the agent
- description: What the agent does (helps Claude decide when to use it)
- tools: Comma-separated list of allowed tools (Read, Grep, Glob, Bash, Edit, Write, etc.)
Optional Fields
- model: Preferred model (opus, sonnet, haiku)
Best Practices for Agents
- Keep agent instructions focused on a single domain
- Be specific about what the agent should look for
- Request concrete output formats (line references, specific fixes)
- Limit tool access to what's actually needed
Execution Flow
For or default:
- Ask which file type (CLAUDE.md or AGENTS.md) if not specified
- Analyze the project:
- Check for existing files at standard locations
- Identify technology stack, project type, development tools
- Review README.md, CONTRIBUTING.md, package.json, etc.
- Draft the file following guidelines above
- Present draft for review
- Write to appropriate location after approval
For :
- Read existing file
- Audit against best practices
- Identify:
- Content to remove (redundant, obvious, style rules)
- Content to condense
- Missing essential information
- Present changes for review
- Apply changes after approval
For :
- Read existing file
- Generate a report with:
- Assessment of content quality
- List of anti-patterns found
- Percentage of truly useful vs redundant content
- Specific recommendations for improvement
- Do NOT modify the file, only report
Anti-Patterns to Avoid
DO NOT include:
- Code style guidelines (use linters/formatters)
- Generic best practices Claude already knows
- Long explanations of obvious patterns
- Copy-pasted code examples
- Information that changes frequently
- Instructions for specific one-time tasks
- File-by-file codebase descriptions
Notes
- Run to generate a starter CLAUDE.md based on current project structure
- Treat CLAUDE.md like code: review it when things go wrong, prune it regularly
- Check CLAUDE.md into git so your team can contribute
- The file compounds in value over time as you refine it