Train your AI teammate
Your CLAUDE.md file is how you teach Claude your team's conventions. A well-crafted CLAUDE.md means AI-generated code that looks like your team wrote it - passing the blind review test.
Review the existing CLAUDE.md and prepare for customization
cd my-full-app
cat CLAUDE.md
# Review the current project guidelines
You should see the existing project guidelines with @Rule annotations
Customize CLAUDE.md so that AI-generated code is indistinguishable from human-written code. Your partner will review code without knowing which is AI-generated.
# Project Guidelines
## Tech Stack
- Java 25, Spring Boot 3.5
- PostgreSQL 17, Kafka 7.9
- JUnit 5 + AssertJ + Testcontainers
## Code Style
@Rule Use record types for DTOs
@Rule Prefer constructor injection over field injection
@Rule Log with structured fields: log.info("msg", kv("key", value))
## Error Handling
@Rule Custom exceptions extend ServiceException
@Rule Always include error code and message
DO:
```java
throw new MerchantNotFoundException(
ErrorCode.MERCHANT_NOT_FOUND,
"Merchant not found",
kv("merchantId", id)
);
```
DO NOT:
```java
throw new RuntimeException("Not found"); // No error code, no context
```
## Testing
@Rule Unit tests: *Test.java with @Nested classes
@Rule Integration tests: *IT.java with @Testcontainers
@Rule Use AssertJ for all assertions
## Modular Rules
@.claude/rules/error-handling.md
@.claude/rules/testing-patterns.md
## DO NOT
- Do not use Lombok @Data (prefer records)
- Do not catch generic Exception
- Do not use System.out.println (use structured logging)
## Also see
- .claude/rules/*.md for modular rule files (supports paths: frontmatter)
- CLAUDE.local.md for personal project-specific overrides
- Settings: set includeGitInstructions: false to reduce context usage
Memory Priority (highest to lowest):
================================
1. Managed Policy - Enterprise rules (macOS plist / Windows Registry)
2. Project Memory - CLAUDE.md in repo root
3. Project Rules - .claude/rules/*.md files (supports paths: frontmatter)
4. User Memory - ~/.claude/CLAUDE.md
5. User Rules - ~/.claude/rules/*.md (global rules, like project rules but user-wide)
6. Local Project - CLAUDE.local.md (gitignored)
7. Auto Memory - ~/.claude/projects/<project>/memory/ (project-scoped)
8. Session Context - Current conversation
Commands:
/memory Opens memory in editor
/init Bootstrap starter CLAUDE.md
/clear Full session reset (clears skills, MCP tools, caches)
/output-style Switch output modes (Default, Explanatory, Learning, or custom)
Settings:
includeGitInstructions: false
Removes built-in git/commit/PR instructions from system prompt
(also: CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1)
claudeMdExcludes: ["packages/legacy/**"]
Exclude certain CLAUDE.md files from loading (useful for monorepos)
Features:
@path.md Include modular rule files
.claude/rules/ Directory for modular rules
- Supports paths: frontmatter for conditional loading
- Supports symlinks (e.g., symlink shared rules across projects)
~/.claude/rules/ User-level global rules (same format as project rules)
CLAUDE.local.md Personal overrides (gitignored)
Auto Memory Claude automatically saves useful context per-project
- MEMORY.md is the index file; topic-specific files alongside it
- 200-line limit on MEMORY.md
- All worktrees share one memory directory
- Location: ~/.claude/projects/<project>/memory/
CLI Flags:
--add-dir <path> Add additional directories to Claude's scope
Env: CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD
Load CLAUDE.md from additional directories
Hooks:
InstructionsLoaded Fires when CLAUDE.md or .claude/rules/*.md are loaded