Long-Term Context Retention Patterns
You spent 45 minutes teaching the AI about your project’s deployment pipeline. It now understands that the staging environment uses a different database, that migrations need to run before the API starts, and that the CDN cache must be invalidated after frontend deploys. Tomorrow you open a new session and the AI has forgotten all of it. You explain it again. And again next week.
Memory patterns solve this problem. Every tool provides mechanisms for persisting knowledge across sessions — from files you write and maintain to automatic notes the AI writes for itself. The difference between a team that uses these patterns and one that does not is the difference between an AI that learns over time and one that starts from scratch every morning.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- A complete map of memory mechanisms across all three tools
- Strategies for deciding what the AI should remember vs. what should stay ephemeral
- Prompts for teaching the AI and verifying what it has retained
- Patterns for team-shared memory that benefits every developer
The Memory Hierarchy
Section titled “The Memory Hierarchy”Each tool implements memory at multiple levels. Understanding the hierarchy helps you put the right information at the right level.
Cursor’s memory system has four tiers:
| Level | Location | Scope | Who Manages |
|---|---|---|---|
| Team Rules | Cursor Dashboard | All team members, all projects | Team admin |
| Project Rules | .cursor/rules/*.md | All team members, this project | Team via git |
| User Rules | Cursor Settings > Rules | You, all projects | You |
| AGENTS.md | AGENTS.md in project | All team members, this project | Team via git |
Project Rules are the most important tier. They are version-controlled, scoped to your codebase, and can be glob-filtered to apply only to relevant files.
Cursor also supports Agent Skills — an open standard for extending AI agents with specialized capabilities that can be imported and automatically applied as context.
Claude Code has the richest memory system with six tiers:
| Level | Location | Scope | Who Manages |
|---|---|---|---|
| Managed policy | System-level CLAUDE.md | All users in org | IT/DevOps |
| Project memory | ./CLAUDE.md or ./.claude/CLAUDE.md | Team via git | Team |
| Project rules | .claude/rules/*.md | Team via git | Team |
| User memory | ~/.claude/CLAUDE.md | You, all projects | You |
| Local memory | ./CLAUDE.local.md | You, this project | You |
| Auto memory | ~/.claude/projects/<project>/memory/ | You, this project | Claude |
Auto memory is the standout feature. Claude automatically saves useful context — project patterns, debugging insights, architecture notes, and your preferences — without you asking. The first 200 lines of MEMORY.md load into every session. Detailed notes go into topic-specific files that Claude reads on demand.
Codex uses a layered AGENTS.md system:
| Level | Location | Scope | Who Manages |
|---|---|---|---|
| Global | ~/.codex/AGENTS.md | You, all projects | You |
| Global override | ~/.codex/AGENTS.override.md | You, all projects (temporary) | You |
| Project root | ./AGENTS.md | Team via git | Team |
| Nested | ./services/payments/AGENTS.md | Team, specific service | Team |
| Nested override | ./services/payments/AGENTS.override.md | Temporary overrides | You or team |
Codex concatenates files from root to current directory, with later files overriding earlier ones. The system supports fallback filenames (configurable) and a size limit of 32 KiB by default.
Teaching the AI to Remember
Section titled “Teaching the AI to Remember”The most powerful memory pattern is explicit: when you discover something important, tell the AI to remember it.
Create or update a project rule directly:
We just discovered that the search service requires a warm-upcall before it returns accurate results. Create a new rule in.cursor/rules/search-service.md documenting this behavior andnoting that tests should include a warm-up step.You can also create rules from chat by asking Cursor: “Create a cursor rule for this.”
Tell Claude directly what to remember:
Remember: the search service requires a warm-up call before itreturns accurate results. Always include a warm-up step whenwriting tests for search functionality.Claude saves this to its auto memory at ~/.claude/projects/<project>/memory/. You can also be more specific:
Save to memory that integration tests for the search servicemust call /search/warm-up before running assertions.To review what Claude has stored, use the /memory command to open the file selector.
Update your AGENTS.md with the new knowledge:
Add to our AGENTS.md: "The search service requires a warm-upcall before returning accurate results. Tests must includea warm-up step."Since Codex reads AGENTS.md at the start of every session, this knowledge is automatically available in all future work.
Deciding What to Remember
Section titled “Deciding What to Remember”Not everything should be persisted. Memory that grows too large gets ignored — the same way a 500-line CLAUDE.md file causes Claude to miss critical rules.
Always Persist
Section titled “Always Persist”- Build, test, and deployment commands
- Non-obvious constraints (environment requirements, service dependencies)
- Architectural decisions and their rationale
- Error patterns that took significant time to diagnose
- Team conventions that differ from language defaults
Never Persist
Section titled “Never Persist”- Temporary workarounds that will be removed soon
- Task-specific context (the current bug you are debugging)
- Information already in the codebase (README content, package.json scripts)
- Obvious conventions the AI already follows
Team-Shared Memory
Section titled “Team-Shared Memory”The most valuable memory is shared. When one developer discovers that the notification service has a race condition under load, that knowledge should benefit every developer on the team — not just the one who found it.
Check .cursor/rules/ into git. Team members get the rules automatically. For organization-wide rules, use Team Rules from the Cursor Dashboard (available on Team and Enterprise plans).
Team Rules take precedence over project and user rules, ensuring critical organizational standards are maintained.
Check CLAUDE.md and .claude/rules/ into git. Personal preferences go in CLAUDE.local.md (automatically gitignored).
For organizations, deploy a managed policy CLAUDE.md at the system level (macOS: /Library/Application Support/ClaudeCode/CLAUDE.md). This ensures company-wide standards apply to all developers.
Check AGENTS.md into git. Personal overrides use AGENTS.override.md (which is typically gitignored or scoped to individual developers).
For teams, standardize on a root-level AGENTS.md with shared conventions and allow service teams to add nested overrides.
Cross-Session Workflows
Section titled “Cross-Session Workflows”Memory patterns enable workflows that span multiple sessions without losing context.
- Session 1: Plan. Create the implementation plan and save it as
docs/feature-plan.md. Add a note to memory: “Current work: implementing feature X. Plan is in docs/feature-plan.md.” - Session 2: Implement tasks 1-3. Reference the plan file. After completing each task, update the todo list on disk. Tell the AI to remember where you stopped.
- Session 3: Continue. The AI loads its memory, sees the note about current work, and reads the plan and todo list. You pick up exactly where you left off.
In Claude Code, use claude --continue to resume the most recent session directly. Use --resume to pick from a list of recent sessions. Rename sessions with /rename for easy retrieval (e.g., “oauth-migration”).
When This Breaks
Section titled “When This Breaks”Auto-memory saves irrelevant things. Claude Code’s auto memory is useful but not perfect. Review it periodically with /memory. Remove notes about one-off debugging sessions or temporary workarounds that are no longer relevant.
Memory conflicts between team members. When two developers add contradictory rules (one says “use tabs” and another says “use spaces”), the AI gets confused. Establish a review process for shared instruction files, just like code review.
The AI ignores memory. If your instruction file is too long, rules at the bottom get less attention than rules at the top. Put the most important rules first. Keep the total under 50 lines for the main file.
Memory from one project leaks to another. User-level rules (~/.claude/CLAUDE.md, Cursor User Rules, ~/.codex/AGENTS.md) apply to all projects. Keep them genuinely universal (personal style preferences, global tool shortcuts). Project-specific knowledge belongs in project-level files.