| name | moai-cc-memory |
| description | Managing Claude Code Session Memory & Context. Understand session context limits, use just-in-time retrieval, cache insights, manage memory files. Use when optimizing context usage, handling large projects, or implementing efficient workflows. |
| allowed-tools | Read, Write, Glob, Bash |
Skill Metadata
| Field | Value |
|---|
| Version | 1.0.0 |
| Tier | Ops |
| Auto-load | When optimizing context usage |
What It Does
Session memory ๋ฐ context ๊ด๋ฆฌ ์ ๋ต์ ์ ๊ณตํฉ๋๋ค. Just-in-time retrieval, insight caching, memory file ๊ด๋ฆฌ๋ฅผ ํตํด context window๋ฅผ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ค๋ฃน๋๋ค.
When to Use
- Context limit์ ๋๋ฌํ ์ํ์ด ์์ ๋
- ๋๊ท๋ชจ ํ๋ก์ ํธ์์ ํจ์จ์ ์ธ context ๊ด๋ฆฌ๊ฐ ํ์ํ ๋
- Session handoff๋ฅผ ์ค๋นํ ๋
- Memory file ๊ตฌ์กฐ๋ฅผ ์ค๊ณํ๊ฑฐ๋ ์ ๋ฆฌํ ๋
Managing Claude Code Session Memory & Context
Claude Code operates within context windows (~100K-200K tokens). Effective memory management ensures productive sessions without hitting limits.
Context Budget Overview
Total Context Budget
โโโ System Prompt (~2K)
โโโ Tools & Instructions (~5K)
โโโ Session History (~30K)
โโโ Project Context (~40K)
โโโ Available for Response (~23K)
Just-in-Time (JIT) Retrieval Strategy
High-Freedom: Core Principles
Principle 1: Pull Only What You Need
- Don't load entire codebase upfront
- Load files relevant to immediate task
- Use Glob/Grep for targeted searches
- Cache results for reuse
Principle 2: Prefer Explore Over Manual Hunting
rg "authenticate" src/ | head -20
@agent-Explore "Find authentication implementation, analyze"
Principle 3: Layered Context Summaries
1. High-level brief (purpose, success criteria)
โ
2. Technical core (entry points, domain models)
โ
3. Edge cases (known bugs, constraints)
Example: Feature Implementation
Task: "Add email verification to signup"
JIT Retrieval:
โโโ Read: User model (src/domain/user.ts)
โโโ Read: Signup endpoint (src/api/auth.ts)
โโโ Grep: "email" in tests (understand patterns)
โโโ Glob: Find email service (src/infra/email.*)
โโโ Cache: Signup flow diagram in memory
Medium-Freedom: Memory File Patterns
Pattern 1: Session Summary Cache
File: .moai/memory/session-summary.md
# Session Summary
## Current Task
- Feature: User email verification
- SPEC: AUTH-015
- Status: In RED phase (writing tests)
## Key Files
- Test: tests/auth/email_verify.test.ts
- Impl: src/domain/email_service.ts
- Config: src/config/email.ts
## Important Context
- Email service uses SendGrid API
- Verification tokens expire in 24h
- Already have similar flow for password reset (AUTH-012)
## Assumptions Made
- Assuming transactional emails only
- Async email sending OK
- No SMS verification needed
Pattern 2: Architecture Reference
File: .moai/memory/architecture.md
# Architecture Reference
## Data Flow for Email Verification
User(Browser)
โ [POST /auth/signup]
Server
โ [Create user + token]
DB
โ [sendEmail async]
Queue
โ [Process job]
Email Service (SendGrid)
โ
User receives email with link
User clicks link
โ [GET /auth/verify?token=...]
Server validates token
โ [Mark user verified]
DB
โ
User logged in
## Module Boundaries
- `domain/`: Business logic (no framework)
- `api/`: HTTP endpoints only
- `infra/`: External services (SendGrid, DB)
Pattern 3: Known Gotchas Cache
File: .moai/memory/gotchas.md
# Common Pitfalls in This Project
## Email Service
- SendGrid has rate limit: 100 emails/sec per account
- Test mode uses fake email (won't actually send)
- Async job failures don't alert (check logs)
## Database
- Migrations must be reviewed before prod deploy
- Test DB is reset after each suite
- Foreign key constraints enforced (plan deletions)
## Authentication
- JWT tokens stored in httpOnly cookies (XSRF protected)
- Refresh token rotation required (not automatic)
- Session timeout: 7 days (hardcoded, not configurable yet)
Low-Freedom: Memory Management Practices
Practice 1: Caching Key Insights
After reading code:
1. Note file locations (~5 min read)
2. Summarize key logic (~2 min)
3. Write to memory file (~1 min)
4. Reference in next session
Example memory entry:
# USER-002: Email verification flow
## Key Code Locations
- Token generation: src/domain/user.ts:generateVerificationToken()
- Email sending: src/infra/email_service.ts:sendVerificationEmail()
- Token validation: src/api/auth.ts:POST /verify
## Logic Summary
1. User submits email โ server generates token (16 chars, base64)
2. Token stored in DB with 24h expiry
3. Email sent async via SendGrid
4. User clicks link โ token validated โ user marked verified
5. Token deleted after use (can't reuse)
## Related TESTs
- tests/auth/email_verify.test.ts (GREEN phase - needs implementation)
- Similar flow: password reset (PASSWORD-001)
Practice 2: Session Boundary Management
Before switching between tasks:
# Session Handoff Note
## Completed
โ RED phase: 3 test cases for email verification
โ GREEN phase: Minimal implementation passing tests
โ REFACTOR: Added input validation
## Status
- Current: Ready for /alfred:3-sync
- Next action: Run full test suite, then sync docs
## Context for Next Session
- SPEC: .moai/specs/SPEC-AUTH-015/spec.md
- Tests: tests/auth/email_verify.test.ts (all passing)
- Code: src/domain/email_service.py
- Database migration: pending (see migrations/ directory)
## Assumptions
- SendGrid API key set in .env
- Test mode uses mock email service
- Database schema includes email_verified_at column
Practice 3: Cleanup Before Session End
rm .moai/memory/temp-*.md
mv .moai/memory/feature-x-* .moai/memory/archive/
ls -la .moai/memory/
Memory File Organization
.moai/
โโโ memory/
โ โโโ session-summary.md # Current session state
โ โโโ architecture.md # System design reference
โ โโโ gotchas.md # Common pitfalls
โ โโโ spec-index.md # List of all SPECs + status
โ โโโ api-reference.md # API endpoints quick lookup
โ โโโ archive/ # Completed session notes
โ โโโ feature-auth-*
โ โโโ feature-api-*
โโโ specs/ # Requirement specifications
โโโ SPEC-AUTH-001/
โโโ SPEC-USER-002/
โโโ SPEC-API-003/
Context Optimization Checklist
Best Practices
โ
DO:
- Use Explore for large searches
- Cache results in memory files
- Keep memory files < 500 lines each
- Update session-summary.md before switching tasks
- Reference memory files in handoff notes
โ DON'T:
- Load entire src/ or docs/ directory upfront
- Duplicate context between memory files
- Store memory files outside
.moai/memory/
- Leave stale session notes (archive or delete)
- Cache raw code (summarize logic instead)
Commands for Memory Management
cat .moai/memory/session-summary.md
ls -la .moai/memory/
mv .moai/memory/feature-old-* .moai/memory/archive/
grep -r "email verification" .moai/memory/
wc -w .moai/memory/*.md
Reference: Claude Code Context Management
Version: 1.0.0