Skip to content

Optimize CLAUDE.md as Routing Layer for Memory System #358

@jeremyeder

Description

@jeremyeder

Overview

Optimize CLAUDE.md to work as a "routing layer" that points to the memory system files rather than containing all context inline. This reduces the file from ~2000+ lines to ~1200-1500 lines while making deep context available on-demand.

Prerequisite: Memory system implementation complete (issue #357)

Problem

Current CLAUDE.md is monolithic:

  • ❌ ~2000+ lines loaded every session
  • ❌ Detailed examples inline (100+ line code blocks)
  • ❌ Historical decision context mixed with rules
  • ❌ Difficult to find critical rules among examples

Solution

Transform CLAUDE.md into a routing layer:

  • ✅ ~1200-1500 lines focused on essentials
  • ✅ Memory System Guide (what to load when)
  • ✅ Universal rules inline (always apply)
  • ✅ Deep patterns in memory files (load on-demand)

Coldstartable Implementation Prompt

File: docs/implementation-plans/claude-md-optimization.md

Execute with:

Claude, optimize CLAUDE.md using the coldstartable plan in:
docs/implementation-plans/claude-md-optimization.md

This plan transforms CLAUDE.md from a monolithic context file into a 
routing layer that points to memory system files (.claude/context/, 
.claude/patterns/, docs/adr/). Follow the plan exactly:

1. Add Memory System Guide section (complete content provided)
2. Slim down Backend/Frontend sections with links to context files
3. Update security/testing sections with memory file references
4. Remove detailed examples now in memory files
5. Validate with checklist

Goal: Reduce CLAUDE.md to ~1200-1500 lines while keeping all critical 
rules and adding navigation to deep context.

What Changes

Stays in CLAUDE.md

  • ✅ Universal rules (NEVER violate, ALWAYS apply)
  • ✅ Build/deploy commands
  • ✅ Project structure overview
  • ✅ Critical backend/frontend rules (5-10 per component)
  • ✅ Memory System Guide (NEW)

Moves to Memory Files

  • ❌ Detailed code examples (>20 lines) → context/pattern files
  • ❌ "How to" step-by-step guides → context files
  • ❌ Historical decision context → ADRs
  • ❌ Anti-patterns with explanations → pattern files
  • ❌ Component-specific deep patterns → context files

Example Transformation

Before (Current)

### Kubernetes Client Patterns

**User-Scoped Clients** (for API operations):

[100+ lines of detailed examples, anti-patterns, decision trees...]

After (Optimized)

### Kubernetes Client Patterns

**CRITICAL RULE:** Always use user-scoped clients for API operations.

**For detailed patterns:** Load `.claude/patterns/k8s-client-usage.md`

**Quick reference:**
- User-scoped: All user operations
- Service account: ONLY privileged ops after validation

**See also:** ADR-0002 (User Token Authentication)

Changes by Section

Section Action New Reference
Memory System Guide ➕ Add new section Links to all memory files
Backend Standards ⚠️ Slim down .claude/context/backend-development.md
Frontend Standards ⚠️ Slim down .claude/context/frontend-development.md
K8s Client Patterns ⚠️ Slim down .claude/patterns/k8s-client-usage.md
Error Handling ⚠️ Slim down .claude/patterns/error-handling.md
React Query ⚠️ Slim down .claude/patterns/react-query-usage.md
Security Patterns ⚠️ Slim down .claude/context/security-standards.md
Architecture Decisions ❌ Remove docs/adr/*.md

Success Criteria

  • Memory System Guide section added after Table of Contents
  • Backend section reduced with links to .claude/context/backend-development.md
  • Frontend section reduced with links to .claude/context/frontend-development.md
  • All detailed examples (>20 lines) moved to memory files
  • File size reduced by 30-40% (2000+ → 1200-1500 lines)
  • All critical rules still present and easy to find
  • Table of Contents updated
  • Test with Claude: "Claude, load backend-development context and help me add an endpoint"

Implementation Steps

Full step-by-step instructions: docs/implementation-plans/claude-md-optimization.md

  1. Add Memory System Guide section (complete content in plan)
  2. Update Backend Development Standards section
  3. Update Frontend Development Standards section
  4. Add quick links to other sections (security, testing)
  5. Update Table of Contents
  6. Validate changes with checklist

Validation

After implementation:

# Verify memory system section exists
grep -A 50 "## Memory System Guide" CLAUDE.md

# Verify context file links present
grep "\.claude/context/" CLAUDE.md

# Verify file size reduced
wc -l CLAUDE.md
# Target: 1200-1500 lines (down from 2000+)

# Test with Claude
# "Claude, load the backend-development context file and help me 
#  understand K8s client usage patterns"

Dependencies

Blocked by: Issue #357 (Memory System Implementation)

  • Must complete memory system first (context files, patterns, ADRs)
  • This issue optimizes CLAUDE.md to reference those files

Rollback Plan

If optimization causes issues:

git checkout HEAD -- CLAUDE.md

Memory files are additive, so they don't need rollback.

Benefits

  1. Faster context loading: Claude loads ~1200 lines instead of 2000+
  2. Better discoverability: Clear signposts to deep context
  3. Easier maintenance: Update patterns in one place (memory files)
  4. On-demand depth: Load deep context only when needed
  5. Clearer rules: Critical rules stand out without noise

Related


Ready to execute once issue #357 is complete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions