memory-lifecycle

memory-lifecycle is an agent for Claude Code from Matt-Dionis/claude-code-configs. It costs 41 tokens per session (5,176 once invoked), scanned A, original, MIT.

A guide to managing the lifetime of memories in AI companion systems. It covers creating memories, finding near-duplicates, combining related memories, assigning importance, and eventually expiring or archiving them.

In plain words
What is it for?
Use it to build memory creation, deduplication, consolidation, importance scoring, expiration, and archival workflows.
Why use it?
It helps prevent repeated, outdated, or unnecessary memories from filling the database and confusing future retrieval.

Agent for Claude Code

Written for Claude Code: installed under .claude/.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import { db } from "../db/client";.

Good fit Use it to build memory creation, deduplication, consolidation, importance scoring, expiration, and archival workflows.

Compare 6 agents from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/Matt-Dionis/claude-code-configs
agentmods
npx agentmods add agents/matt-dionis/claude-code-configs/memory-lifecycle

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for memory-lifecycle

README.md
[![agentmods](https://agentmods.dev/badge/agents/matt-dionis/claude-code-configs/memory-lifecycle/github.svg)](https://agentmods.dev/agents/matt-dionis/claude-code-configs/memory-lifecycle)
Your own site
<a href="https://agentmods.dev/agents/matt-dionis/claude-code-configs/memory-lifecycle"><img src="https://agentmods.dev/badge/agents/matt-dionis/claude-code-configs/memory-lifecycle/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for memory-lifecycle

Your own site · 80×15
<a href="https://agentmods.dev/agents/matt-dionis/claude-code-configs/memory-lifecycle"><img src="https://agentmods.dev/badge/agents/matt-dionis/claude-code-configs/memory-lifecycle.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 41 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 5,176 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00041 $0.05176
Opus 5.5 $0.00016 $0.02070
Sonnet 5.5 $0.00008 $0.01035
Haiku 4.5 $0.00004 $0.00518

Measured 1mo ago against content hash 9869ed5a614f, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

memory-lifecycle scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

configurations/mcp-servers/memory-mcp-server/.claude/agents/memory-lifecycle.md · 725 lines

How it starts

The opening of the file, as written. The whole thing — 725 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an expert in memory lifecycle management, consolidation strategies, and efficient memory storage patterns for AI companion systems.

Memory Lifecycle Stages

Memory Creation and Ingestion

// src/services/memoryLifecycle.ts
import { z } from "zod";
import { db } from "../db/client";
import { memories, memoryRelations } from "../db/schema";
import { EmbeddingService } from "./embeddings";
import { sql, and, eq, lt, gte, desc } from "drizzle-orm";

export class MemoryLifecycleService {
  private embeddingService: EmbeddingService;
  
  constructor() {
    this.embeddingService = new EmbeddingService();
  }

  // Intelligent memory creation with deduplication
  async createMemory(input: {
    companionId: string;
    userId: string;
    content: string;
    type: string;
    context?: any;
  }) {
    // Check for near-duplicates before creation
    const embedding = await this.embeddingService.generateEmbedding(input.content);
    
    const duplicates = await this.findNearDuplicates(
      input.companionId,
      input.userId,
      embedding,
      0.95 // 95% similarity threshold
    );
    
    if (duplicates.length > 0) {
      // Consolidate with existing memory instead
      return await this.consolidateWithExisting(duplicates[0], input);
    }
    
    // Calculate initial importance based on context
    const importance = this.calculateImportance(input);
    
    // Set expiration based on type and importance
    const expiresAt = this.calculateExpiration(input.type, importance);
    
    const memory = await db.insert(memories).values({
      ...input,
      embedding,
      importance,
      expiresAt,
      confidence: 1.0,
      accessCount: 0,
      createdAt: new Date(),
      updatedAt: new Date(),
    }).returning();
    
    // Create relationships with existing memories
    await this.establishRelationships(memory[0]);
    
    return memory[0];
  }

  private calculateImportance(input: any): number {
    let importance = 5.0; // Base importance
    
    // Adjust based on memory type
    const typeWeights: Record<string, number> = {
      instruction: 8.0,
      preference: 7.0,
      fact: 6.0,
      experience: 5.0,
      reflection: 4.0,
    };
    
    importance = typeWeights[input.type] || importance;
    
    // Boost for emotional context
    if (input.context?.emotionalTone) {
      const emotionBoost = {
        joy: 1.5,
        sadness: 1.2,
        anger: 1.3,
        fear: 1.4,
        surprise: 1.1,
      };
      importance += emotionBoost[input.context.emotionalTone] || 0;
    }
    
    // Boost for user-marked important
    if (input.context?.userMarkedImportant) {
      importance += 2.0;
    }
    
    return Math.min(10, Math.max(0, importance));
  }
}

Read the full file on GitHub · 725 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 725 lines · 41 tokens per session scan A 9869ed5a614f

Subscribe to this mod's changes

memory-lifecycle is an agent published in the GitHub repository Matt-Dionis/claude-code-configs (619 stars, last pushed 1y ago), licensed MIT. It adds 41 tokens to every session and 5,176 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.