Skip to content

Memory Rules & Patterns

This page provides a comprehensive reference for memory-first development patterns used with the AutoMem MCP server. It documents proven strategies for memory recall, storage patterns, importance scoring, tagging conventions, and relationship management that enable AI assistants to maintain persistent context across sessions.

This page focuses on usage patterns and best practices for the six MCP tools. For tool schemas and API details, see the Memory Operations reference. For platform-specific integration setup, see the Platform Integration Guides.


The memory system implements a trust-based architecture: AI assistants have direct access to MCP memory tools and are guided by instructions to make intelligent decisions about what to store and when to recall. This contrasts with automated capture systems that attempt to guess significance.

Core principle: Trust AI + good instructions > automated hooks that guess significance

This philosophy evolved from early experiments with hook-based automation (Claude Code) toward instruction-based patterns (Cursor, Codex). The instruction-based approach proved more reliable because the AI can contextualize significance better than automated event capture.


The recall_memory tool supports five fundamental recall strategies, often used in parallel:

StrategyUse CaseParametersWhen to Use
SemanticNatural language searchquery, queriesTopic-based recall, context gathering
Tag-basedPrecise filteringtags, tag_mode, tag_matchProject isolation, stable categories (preference, bugfix)
TemporalTime-bound searchtime_query, start, endRecent work, time-specific events
Graph expansionMulti-hop reasoningexpand_entities, expand_relationsComplex questions, relationship traversal
Context-awareLanguage/style hintslanguage, context_typesCoding tasks, style preferences

Two-Phase Recall is the recommended approach from Claude Code templates:

Phase 1 — Preferences (tag-only, no semantic search):

recall_memory({
tags: ["preference"],
limit: 20,
sort: "updated_desc"
})

Phase 2 — Task context (semantic + temporal):

recall_memory({
query: "<proper nouns, specific tools, exact topics from the user's message>",
tags: ["<project-name>"],
limit: 30,
time_query: "last 90 days"
})

Gate Phase 2 on the project slug only when it is unambiguous. If the slug collides with a common topic word (api, app, test, video), drop tags and rely on the semantic query alone.

Multi-Hop Reasoning via Entity Expansion

Enable graph traversal to follow relationships from seed results:

{
"query": "why did we switch database backends",
"expand_entities": true,
"expand_relations": true,
"expand_min_importance": 0.5,
"expand_min_strength": 0.3,
"expansion_limit": 25,
"relation_limit": 5
}

API parameters exposed in src/mcp-surface.ts L373–L418:

  • expand_entities: true — Enable multi-hop entity expansion
  • expand_relations: true — Follow graph relationships from seed results
  • expand_min_importance: 0.5 — Filter expanded results by importance threshold
  • expand_min_strength: 0.3 — Only follow associations above strength threshold
  • expansion_limit: 25 — Max expanded memories to include
  • relation_limit: 5 — Max relationships to follow per seed result

Context-Aware Coding Recall

Context hints boost relevant memories for coding tasks:

{
"query": "authentication patterns",
"language": "typescript",
"context_types": ["Pattern", "Decision"],
"tags": ["my-project"]
}

language and context_types are rankers: they boost matching memories without excluding the rest. active_path (the current file path) is used for language auto-detection. tags works differently: it is a hard gate that filters before scoring, so use it for the project slug or a stable category, and put topic words in query.

Parallel Recall for Comprehensive Context

Execute multiple recall strategies simultaneously (both can be issued to the MCP server in a single message):

// Strategy 1: Recent project work
{"query": "current sprint tasks", "tags": ["my-project"], "time_query": "last 7 days"}
// Strategy 2: Preferences and style
{"tags": ["preference"], "tag_mode": "any", "limit": 20}

The service deduplicates the results within each call.

ParameterBehaviorUse Case
tag_mode: "any" (default)OR logic — match any tagBroad recall, multiple categories
tag_mode: "all"AND logic — require all tagsStrict filtering, intersection queries

Prefix Matching

tag_match: "prefix" matches a tag and every tag below it. The service splits tags on : and /, so this query returns memories tagged entity:people:alice, entity:people:bob, and any other entity:people:* tag:

{
"tags": ["entity:people"],
"tag_match": "prefix"
}

The service adds entity:<category>:<slug> tags during enrichment. Agents write bare tags (see Tagging Conventions), so don’t build your own namespaces for this. Older memories may still carry project/<slug> tags, which is one reason a project tag gate can come back sparse. When it does, retry without the gate and rely on the semantic query.


The MCP server enforces a three-tier size policy to prevent embedding quality degradation:

TierLimitBehavior
Target150–300 charactersOptimal for vector embeddings
Soft limit500 charactersPasses with warning; backend may summarize
Hard limit2000 charactersRejected immediately

Rationale: Vector embeddings lose quality with overly long text. The 500-character soft limit signals to the backend that summarization may be beneficial, while the 2000-character hard limit prevents storage of entire code files or documentation.

Content Structure Template

Format: "Brief title. Context and reasoning. Outcome or impact."

Good examples:

  • "Chose PostgreSQL over MongoDB for ACID compliance. Evaluated both for 3 weeks. Decision affects all write-heavy services."
  • "User prefers 2-space indentation with single quotes. Correction applied to generated code. Affects all TypeScript output."

Anti-patterns to avoid:

  • Storing entire function bodies or file contents
  • Vague entries without context: "Fixed auth bug"
  • Redundant entries for trivial changes: "Updated comment in utils.ts"

The system supports seven memory types with distinct semantic meanings:

TypeUsageImportance RangeExample
DecisionStrategic/technical decisions0.85–0.95”Chose PostgreSQL over MongoDB for ACID compliance”
PatternRecurring approaches0.70–0.85”Using early returns for validation reduces nesting”
InsightKey learnings, resolutions0.75–0.85”Auth timeout caused by missing retry logic”
PreferenceUser/team preferences0.9”User prefers 2-space indents with single quotes”
StyleCode style, formatting0.60–0.80”Always wrap database calls with timeout logging”
HabitRegular behaviors0.50–0.70”Deploy to staging before production”
ContextGeneral information0.50–0.70”Added JWT authentication system”

Type vs Importance: The type field enables semantic filtering (e.g., recall only Decision memories), while importance controls relevance ranking and decay. Corrections to AI outputs should always use importance: 0.9 as they represent strong style signals.

Set an explicit type on every store; the Claude Code memory rules template requires it. confidence is a separate dial from importance: 0.95 for something the user stated, 0.8 for an observed pattern, 0.6 for a tentative inference. It defaults to 0.9 when you provide a type. Don’t set 0.95 on everything, because that flattens the signal.


graph LR
    subgraph "Importance Tiers"
        Critical["0.9-1.0\nCritical"]
        Important["0.7-0.89\nImportant"]
        Moderate["0.5-0.69\nModerate"]
        Minor["0.3-0.49\nMinor"]
        Decay["< 0.3\nNatural decay"]
    end

    subgraph "Storage Triggers"
        Corrections["User corrections\nto AI output"]
        MajorDecisions["Architecture\ndecisions"]
        Patterns["Discovered\npatterns"]
        BugFixes["Bug fixes with\nroot cause"]
        MinorChanges["Config changes\nminor features"]
        TrivialEdits["Typos, comments,\nformatting"]
    end

    Corrections --> Critical
    MajorDecisions --> Critical
    Patterns --> Important
    BugFixes --> Important
    MinorChanges --> Moderate
    TrivialEdits --> Decay

Importance Scoring Matrix

Memory TypeTypical RangeExamplesRationale
User Corrections0.9Style fixes, preference statementsStrongest signal for personalization
Decisions0.85–0.95Architecture choices, library selectionsReferenced months later
Patterns0.75–0.85Best practices, reusable approachesUseful across projects
Insights0.7–0.8Bug fixes, key learningsImportant but time-sensitive
Features0.7–0.8Implementation detailsProject-specific context
Preferences0.9Tool choices, style preferencesStored at the same weight as corrections
Context0.5–0.7General informationBackground knowledge

Philosophy: High importance scores (0.9+) are reserved for memories that should persist indefinitely and rank highly in recall. Medium scores (0.7–0.8) indicate useful patterns that should survive for months. Low scores (< 0.3) signal the memory system to let them naturally decay.

Anti-Patterns:

  • Assigning 0.9 to every memory (dilutes recall ranking)
  • Assigning 0.5 to user corrections (they won’t surface prominently enough)
  • Using 1.0 except for truly irreplaceable preferences

graph TB
    subgraph "Tag Strategy"
        Memory["Memory to store"]

        Decision{"Is this\nproject-specific?"}

        ProjectTags["Project-specific:\n1. category (decision/bugfix/...)\n2. project-slug\n3. language"]

        GeneralTags["Not project-specific:\n1. category (preference/...)\n(no project slug)"]

        Store["store_memory()"]
    end

    Memory --> Decision
    Decision -->|Yes: code, architecture| ProjectTags
    Decision -->|No: preferences, lifestyle| GeneralTags

    ProjectTags --> Store
    GeneralTags --> Store

Project-Specific Memories

{
"tags": ["decision", "my-api-service", "typescript"]
}

Cross-Project Memories

Memories that aren’t tied to one project, such as general preferences, take a category tag and leave out the project slug:

{
"tags": ["preference"]
}

Use one category tag when one applies: preference, decision, pattern, bugfix, solution, milestone, deployment, build, or test. Add the project slug only for project-specific memories, and omit it when the slug collides with a common topic word (api, app, test, video).

Don’t put dates in tags; the Codex, Cursor, Grok, and Claude Desktop rules, the Claude Code plugin, and the OpenClaw plugin policy rule out date-stamped tags. Every memory already carries a timestamp (the store time unless you pass one), and time_query (or explicit start / end) filters on it:

{
"tags": ["my-project"],
"time_query": "last 30 days"
}

Facts with a shelf life: set t_valid and t_invalid on store_memory (single-memory mode only) instead of encoding a date in the tags. The service persists both fields and serves them from GET /memory/<id>; they don’t always appear in /recall responses.


graph TB
    subgraph "Association Creation Patterns"
        Store["store_memory()"]

        CorrectionCheck{"Is this a\nuser correction?"}
        BugFixCheck{"Is this a\nbug fix?"}
        DecisionCheck{"Is this a\ndecision?"}

        SearchRelated["recall_memory()\nfind related"]

        InvalidatedBy["associate_memories()\ntype: INVALIDATED_BY\nstrength: 0.9"]

        DerivedFrom["associate_memories()\ntype: DERIVED_FROM\nstrength: 0.8"]

        PrefersOver["associate_memories()\ntype: PREFERS_OVER\nstrength: 0.85"]
    end

    Store --> CorrectionCheck
    CorrectionCheck -->|Yes| SearchRelated
    CorrectionCheck -->|No| BugFixCheck

    BugFixCheck -->|Yes| SearchRelated
    BugFixCheck -->|No| DecisionCheck

    DecisionCheck -->|Yes| SearchRelated

    SearchRelated --> InvalidatedBy
    SearchRelated --> DerivedFrom
    SearchRelated --> PrefersOver

Relationship Type Reference

TypeUse CaseStrength RangeExample
LEADS_TOCausal relationship (A caused B)0.8–0.95Bug → Solution, Problem → Fix
DERIVED_FROMImplementation based on decision0.7–0.9Feature → Architecture decision
EXEMPLIFIESConcrete example of pattern0.7–0.85Code → Pattern memory
EVOLVED_INTOUpdated version of concept0.8–0.95Old approach → New approach
INVALIDATED_BYSuperseded by another memory0.85–0.95Old info → Current approach
CONTRADICTSConflicts with another memory0.7–0.9Alternative A → Alternative B
REINFORCESStrengthens another memory’s validity0.6–0.85Supporting evidence
RELATES_TOGeneral connection (default)0.5–0.8Any related concept
PART_OFComponent of larger effort0.7–0.9Task → Epic
PREFERS_OVERChosen alternative0.8–0.95Chosen option → Rejected option
OCCURRED_BEFORETemporal ordering0.6–0.8Earlier work → Later work

When to Create Associations

Create associations after storing a new memory when:

  1. The memory corrects or supersedes existing information
  2. The memory is the solution to a previously stored problem
  3. The memory is a decision that explicitly prefers one option over another
  4. The memory is a concrete implementation of a stored pattern

Association Pattern: User Corrections

User corrections are the strongest signal for personalization. Always search and link:

// 1. Find the old preference before storing
recall_memory({ query: "variable naming style preference", limit: 5 })
// 2. Store the correction
store_memory({ content: "User prefers camelCase for variable names", type: "Preference", tags: ["correction", "<project>"], importance: 0.9, confidence: 0.95 })
// 3. Verify it landed by recalling a distinctive phrase
recall_memory({ query: "camelCase for variable names", limit: 3 })
// 4. Mark the old memory as invalidated by the new one
associate_memories({ memory1_id: "<old_id>", memory2_id: "<new_id>", type: "INVALIDATED_BY", strength: 0.9 })

Association Pattern: Bug Fixes

Link original bug discoveries to their fixes to build problem-solution chains:

// After storing the fix
associate_memories({ memory1_id: "<bug_id>", memory2_id: "<fix_id>", type: "LEADS_TO", strength: 0.85 })

Association Pattern: Decisions

Link decisions to alternatives considered to capture tradeoff reasoning:

// Decision: chose PostgreSQL
associate_memories({ memory1_id: "<postgres_id>", memory2_id: "<mongo_id>", type: "PREFERS_OVER", strength: 0.9 })

Platform templates such as Cursor and Codex use placeholder variables that the installer substitutes:

Common Variables

VariableResolutionExample
{{PROJECT_NAME}}From package.json, git remote, or directory namemy-api-service
{{MCP_TOOL_PREFIX}}Cursor tool prefix, built from the server name as mcp_<server>_mcp_memory_
{{MCP_SERVER_NAME}}Cursor MCP server name from configmemory

Tool Prefix Variations

PlatformMCP Server NameTool PrefixExample
Cursormemorymcp_memory_mcp_memory_recall_memory
Claude Codememorymcp__memory__mcp__memory__store_memory
Claude Code (plugin)plugin_automem_memorymcp__plugin_automem_memory__mcp__plugin_automem_memory__recall_memory
Codexmemorymcp__memory__mcp__memory__recall_memory
Claude Desktopmemorymcp__memory__mcp__memory__recall_memory

Cursor: Rule-Based Integration

Cursor uses .cursor/rules/automem.mdc with alwaysApply: true to ensure memory tools are available in every conversation.

Pattern: Two-phase session-start recall (preferences tag-only, task context semantic+time), an on-demand debug recall with no tag gate, and three mid-conversation storage triggers (user correction, decision stabilized, pattern articulated). The rule says never to store session summaries or progress reports, and it has no end-of-conversation step.

Claude Code: Permissions, Rules, and Hooks Integration

Claude Code uses three mechanisms:

  1. Permissions in ~/.claude/settings.json to allow memory tools without prompting
  2. Rules in ~/.claude/CLAUDE.md to guide usage
  3. A SessionStart hook that prompts the two-phase recall (bundled by the plugin, installed by the CLI installer)

Pattern: Two-phase recall (preferences tag-only, task context semantic+time)

Codex: AGENTS.md Integration

Codex uses AGENTS.md in the project root with memory rules appended via CLI.

Pattern: Two-phase session-start recall and the same three storage triggers as Cursor

Claude Desktop: Personal Preferences

Claude Desktop uses Personal Preferences (Settings → Profile → Personal Preferences) with memory usage patterns.

Pattern: Semantic-first recall at conversation start (preferences plus one semantic task query), adding a tag gate only once the user scopes the task, and the same three storage triggers as Cursor


templates/
├── CLAUDE_MD_MEMORY_RULES.md # Full rules for CLAUDE.md
├── CLAUDE_DESKTOP_INSTRUCTIONS.md # Claude Desktop Personal Preferences template
├── CLAUDE_CODE_INTEGRATION.md # Integration guide
├── cursor/
│ └── automem.mdc.template # Cursor rule file
└── codex/
├── memory-rules.md # Codex AGENTS.md section
└── config.toml # Codex MCP config

  1. Default to recall for project-related questions
  2. Use parallel strategies for comprehensive context
  3. Start simple (project tag only), add complexity if needed
  4. Separate preferences from task context (two-phase recall)
  5. Natural integration — don’t announce memory operations
  6. Fail gracefully — continue without context if recall fails
  1. Keep memories atomic — 150–300 characters target
  2. Tag consistently — bare strings: category, project slug, language
  3. Score appropriately — user corrections highest (0.9)
  4. Include context — explain “why”, not just “what”
  5. Avoid noise — skip trivial changes, routine operations
  6. Use explicit types — set type on every store and use confidence to say how sure you are
  1. Always link corrections — strongest personalization signal
  2. Chain bug fixes — link to original problems
  3. Connect decisions — link to alternatives and rationale
  4. Use appropriate types — INVALIDATED_BY for corrections, DERIVED_FROM for implementations
  5. Score strength accurately — 0.9+ for direct causation, 0.7–0.8 for strong relationships
  1. Format consistently — “Brief title. Context. Impact.”
  2. Avoid type prefixes — use type field instead of [DECISION] in content
  3. Never store secrets — API keys, passwords, tokens
  4. Split long content — use multiple memories with associations
  5. Use metadata — structured data for files, errors, solutions

This page provides the canonical reference for memory patterns used across all platform integrations. The patterns documented here are derived from extensive testing and community feedback, reflecting the evolution from automated capture toward instruction-based memory management.