| name | claudemd-optimization |
| description | Optimize CLAUDE.md following best practices from humanlayer.dev - apply after /init to transform verbose output into focused, high-leverage project context |
| triggers | ["optimize claude.md","ไผๅ claude.md","improve claude.md","refactor claude.md","claude.md ๅคช้ฟไบ","็ฒพ็ฎ claude.md"] |
CLAUDE.md Optimization Skill
Based on best practices from Writing a Good CLAUDE.md
Core Principle: LLMs Are Stateless
The only thing the model knows about your codebase is the tokens you put into it.
CLAUDE.md automatically enters EVERY conversation, making it the highest leverage point in the entire system. A flawed instruction cascades through research, planning, and implementation phases.
The Three Dimensions (WHAT / WHY / HOW)
Every CLAUDE.md should cover exactly these three dimensions:
| Dimension | Content | Example |
|---|
| WHAT | Technology stack, architecture, codebase structure | "React + Bun monorepo with 5 plugins" |
| WHY | Project purpose, what each component does | "Frontend plugin handles UI development" |
| HOW | Build tools, verification, testing, workflow | "Run bun test, use /implement command" |
Optimization Rules
Rule 1: Less Is More
โ BAD: 500+ lines of detailed instructions
โ
GOOD: 60-300 lines of focused context (ideally < 150)
HumanLayer's own CLAUDE.md is < 60 lines!
Research-Backed Data:
| Metric | Value | Implication |
|---|
| Frontier LLM instruction limit | ~150-200 | Beyond this, compliance drops |
| Claude Code system prompt | ~50 instructions | Already consumed! |
| Your remaining budget | ~100-150 | Every line counts |
Critical Insight: As instruction count increases, compliance quality decreases uniformly across ALL instructions - not just the later ones. This means bloated CLAUDE.md degrades even your most important rules.
Model Size Matters:
- Frontier thinking models: Linear decay (graceful degradation)
- Smaller models: Exponential decay (rapid failure)
- โ ๏ธ Avoid smaller models for multi-step tasks or complex plans
Rule 2: Progressive Disclosure
Don't cram everything into CLAUDE.md. Create an agent_docs/ directory for task-specific details:
agent_docs/
โโโ commands-and-agents.md # Detailed command/agent reference
โโโ architecture-guide.md # Deep architectural documentation
โโโ api-patterns.md # API conventions and examples
โโโ testing-strategy.md # Testing approaches
โโโ release-process.md # Release workflow details
Use pointers, not copies:
## Detailed Documentation
| Topic | Reference |
|-------|-----------|
| Commands | [agent_docs/commands-and-agents.md](agent_docs/commands-and-agents.md) |
| Architecture | [agent_docs/architecture-guide.md](agent_docs/architecture-guide.md) |
Rule 3: LLM Attention Distribution
LLMs bias towards instructions at the peripheries:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HIGH ATTENTION โ
โ โโโ System prompt (Claude Code) โ
โ โโโ CLAUDE.md (beginning) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ LOW ATTENTION โ
โ โโโ Middle of context window โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ HIGH ATTENTION โ
โ โโโ Recent user messages (end) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Implication: Put your most critical rules at the TOP of CLAUDE.md, not buried in the middle.
Rule 4: Claude Is NOT a Linter
Never put style rules in CLAUDE.md:
- โ "Use 2-space indentation"
- โ "Always use semicolons"
- โ "Prefer const over let"
Instead:
- Use Biome/ESLint/Prettier for formatting
- Claude learns patterns from existing code (in-context learning!)
- Well-structured code demonstrates conventions
Advanced Technique: Stop Hook
Set up a Stop Hook to run formatter after Claude finishes:
{
"hooks": {
"Stop": [{
"matcher": "*.{ts,tsx,js,jsx}",
"command": "biome check --fix --unsafe"
}]
}
}
This separates implementation from formatting - both improve as a result.
Rule 5: Never Auto-Generate
โ DON'T: Use /init output directly
โ
DO: Use /init as starting point, then manually optimize
Why: Every line has multiplicative impact. Auto-generated content includes noise that pollutes every conversation.
Rule 6: Universal Applicability Only
Only include instructions that apply to EVERY task in this project:
- โ
"This is a TypeScript monorepo"
- โ
"Run tests with
bun test"
- โ "When implementing auth, use JWT" (task-specific โ agent_docs/)
- โ Detailed API patterns (task-specific โ agent_docs/)
Optimization Workflow
When user requests CLAUDE.md optimization, follow this workflow:
Phase 1: Analysis
wc -l CLAUDE.md
grep "^##" CLAUDE.md
Classify each section:
- ๐ข KEEP (core WHAT/WHY/HOW)
- ๐ก MOVE (detailed โ agent_docs/)
- ๐ด DELETE (redundant, outdated, task-specific noise)
Phase 2: Create agent_docs Structure
mkdir -p agent_docs
Move detailed content to appropriate files:
| Content Type | Target File |
|---|
| Command/Agent lists | agent_docs/commands-and-agents.md |
| Architecture details | agent_docs/architecture-guide.md |
| API patterns/examples | agent_docs/api-patterns.md |
| Tool-specific guides | agent_docs/{tool}-guide.md |
| Version history | agent_docs/release-history.md |
| Protocol documentation | agent_docs/{protocol}-protocol.md |
Phase 3: Rewrite CLAUDE.md
Target structure (60-150 lines):
# Project Context for Claude Code
## Project Overview (WHAT)
[2-5 lines: name, purpose, owner]
## What This Repository Contains (WHY)
[Table or bullet list: components and their purposes]
[10-20 lines max]
## Directory Structure
[Simplified tree, 10-15 lines]
## How to Work with This Project (HOW)
[Quick setup, env vars, dependencies]
[15-25 lines]
## Key Architecture Decisions
[3-5 bullet points of universal principles]
## Important Files
[Table: role โ files]
## Detailed Documentation (Progressive Disclosure)
[Table: topic โ agent_docs/ reference]
## Project Rules
[3-5 universal rules that apply to EVERY task]
Phase 4: Verification
wc -l CLAUDE.md
ls -la agent_docs/
grep -r "agent_docs/" CLAUDE.md
Anti-Patterns to Avoid
| Anti-Pattern | Why It's Bad | Fix |
|---|
| 500+ lines | Degrades all instructions | Split to agent_docs/ |
| Code examples inline | May become outdated | Use file:line references |
| Version history in CLAUDE.md | Not universal | Move to agent_docs/release-history.md |
| Detailed protocols | Task-specific | Move to agent_docs/{protocol}.md |
| Style/linting rules | Use proper tools | Remove, use Biome/ESLint |
| Auto-generated content | Contains noise | Manual curation required |
Quick Reference: Section Classification
๐ข KEEP in CLAUDE.md
- Project name, purpose, owner
- High-level directory structure
- Environment variables (list only)
- System dependencies
- Universal commands (
bun test, bun build)
- Design principles (3-5 points)
- Important file references (table)
- Progressive disclosure table
- 3-5 universal project rules
๐ก MOVE to agent_docs/
- Detailed command documentation
- Agent specifications
- API patterns and examples
- Tool-specific guides (claudemem, etc.)
- Protocol documentation
- Version history and changelog details
- Architecture deep-dives
- Testing strategies
๐ด DELETE
- Redundant information
- Outdated content
- Task-specific instructions
- Inline code snippets (use references)
- Style/formatting rules
- Verbose explanations
Example Transformation
Before (982 lines):
## Commands and Agents Available
### Frontend Plugin
**Agents:**
- `typescript-frontend-dev` - TypeScript/React implementation (Sonnet)
- `frontend-architect` - Architecture planning (Sonnet)
[... 100+ lines of agent details ...]
## Claudemem AST Structural Analysis (v0.3.0)
[... 150+ lines of tool documentation ...]
## Parallel Multi-Model Execution Protocol
[... 180+ lines of protocol details ...]
After (154 lines):
## Detailed Documentation (Progressive Disclosure)
| Topic | Documentation |
|-------|---------------|
| Commands & Agents | [agent_docs/commands-and-agents.md](agent_docs/commands-and-agents.md) |
| Claudemem Guide | [agent_docs/claudemem-guide.md](agent_docs/claudemem-guide.md) |
| Parallel Execution | [agent_docs/parallel-execution-protocol.md](agent_docs/parallel-execution-protocol.md) |
Success Metrics
After optimization, verify: