Lesson Learned: CLAUDE.md Bloat Anti-Pattern
Lesson Learned: CLAUDE.md Bloat Anti-Pattern
ID: LL-017 Impact: Identified through automated analysis
Date: December 12, 2025 Category: Agent Optimization Severity: High (wastes 3-4k tokens every conversation)
The Problem
Our CLAUDE.md grew to ~700 lines / ~14k characters - approximately 7x larger than best practices recommend.
What We Had Wrong
| Anti-Pattern | Example | Impact |
|---|---|---|
| Token bloat | 700 lines vs recommended 100-300 | Wastes ~3-4k tokens before work begins |
| Procedures in CLAUDE.md | GitHub API curl examples inline | Should be in .claude/commands/ |
| Mixed concerns | Memory + Rules + Procedures together | Violates separation of concerns |
| Code snippets | Full curl commands for PR creation | Becomes stale, duplicates scripts |
| Historical rationale | βCEO Directive Dec 9, 2025β¦β | Belongs in docs/decisions/ |
| Verbose chain of command | Multiple paragraphs on CEO/CTO roles | Should be 1-2 lines max |
Best Practices (Per Anthropic Dec 2025)
Recommended Structure
CLAUDE.md (250 lines MAX)
βββ Facts: architecture, tech stack, conventions
βββ 1-line pointers to detailed docs
βββ Critical rules (1 line each)
.claude/rules/MANDATORY_RULES.md
βββ Detailed rule explanations
βββ Context and rationale
βββ Single source of truth
.claude/commands/
βββ create-pr.md (procedure)
βββ verify-trade.md (procedure)
βββ daily-report.md (procedure)
docs/
βββ chain-of-command.md
βββ verification-protocols.md
βββ decisions/ (historical rationale)
Key Metrics
| Metric | Bad | Good |
|---|---|---|
| CLAUDE.md lines | >300 | 100-250 |
| Token consumption | >3000 | <1500 |
| Procedures inline | Any | Zero |
| Code snippets | Any | Zero (use file pointers) |
Why This Matters
-
Token waste: Every conversation starts by loading CLAUDE.md. Bloated = less context for actual work.
-
Instruction decay: LLMs read full conversation each turn. Instructions at the beginning lose effectiveness as conversation grows. Shorter = more durable.
-
Maintenance hell: Procedures in CLAUDE.md get stale. Slash commands are executable and testable.
-
No single source of truth: Same rule in CLAUDE.md + hook + script = divergence over time.
The Fix
Before (Anti-Pattern)
## GitHub PR Creation Protocol
**YOU HAVE FULL AGENTIC CONTROL TO CREATE AND MERGE PRs!**
**Create PR (via GitHub API - PREFERRED):**
\`\`\`bash
curl -X POST \
-H "Authorization: token <PAT>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/IgorGanapolsky/trading/pulls \
-d '{"title": "feat: description"...}'
\`\`\`
[30 more lines of procedures...]
After (Best Practice)
## Git & PRs
- **Rule**: Never merge directly to main (CI bypass caused 0 trades Dec 11)
- **Procedure**: See `.claude/commands/create-pr.md`
- **Automation**: Pre-merge gate in `.claude/hooks/`
Action Items Completed
- Created
.claude/rules/MANDATORY_RULES.md- single source of truth for critical rules - Moved procedures to
.claude/commands/as slash commands - Reduced CLAUDE.md from ~700 to ~250 lines
- Removed all inline code snippets (replaced with file pointers)
- Separated: Memory (CLAUDE.md) / Rules (.claude/rules/) / Procedures (.claude/commands/)
References
- Anthropic: Claude Code Best Practices
- HumanLayer: Writing a Good CLAUDE.md
- Claude.com: Using CLAUDE.MD Files
Key Takeaway
βCLAUDE.md should contain facts (what exists, architecture). Slash commands should contain procedures (how to do things). Rules files should contain constraints (what not to do).β
Token budget rule of thumb: CLAUDE.md should use <2% of your context window (~4k tokens max for 200k window).
Prevention Rules
- Apply lessons learned from this incident
- Add automated checks to prevent recurrence
- Update RAG knowledge base