Skip to main content

Your AI coding agent never forgets — progressive session recall for GitHub Copilot CLI

Project description

claude-auto-mem

Your AI coding agent has amnesia. Here's the fix.

~1,900 lines of Python. Zero dependencies. Saves you an hour a day.

Built by Desi Villanueva

PyPI CI License: MIT Python 3.10+ Zero Dependencies Tests

Zero-dependency CLI that gives your AI coding agent instant session recall — no MCP server, read-only, schema-checked. ~50 tokens per prompt.

Works with: GitHub Copilot CLI · Claude Code
Coming soon: Cursor · Codex


Quickstart

Copilot CLI (existing):

pip install claude-auto-mem        # or: git clone + ./install.sh
session-recall health          # verify it works

Now give your agent a memory. Point it at deploy/install.md and let it cook. 🍳

Claude Code (new):

pip install claude-auto-mem
session-recall cc-index        # build the local session index
session-recall install-mode --setup   # wire SessionStart hook into ~/.claude/settings.json

That's it. Every new Claude Code conversation gets the last ~50 tokens of session context injected automatically.


The Problem

Every AI coding agent ships with a big number on the box. 200K tokens. Sounds massive. Here's what actually happens:

200,000  tokens — context window (theoretical max)
120,000  tokens — effective limit before context rot kicks in (~60%)
 -65,000  tokens — MCP tools
 -10,000  tokens — instruction files
=========
 ~45,000  tokens — what you ACTUALLY have before quality degrades

LLMs don't degrade gracefully — once you cross roughly 60% of the context window, the model starts losing coherence. The industry calls it "lost in the middle": attention goes to the beginning (instructions) and the end (recent turns), but your actual working context in the middle gets progressively fuzzier.

I timed it over a week: 68 minutes per day lost to re-orientation after compactions and new sessions.

It's a death spiral of diminishing context — each compaction leaves the agent slightly dumber, which burns more tokens explaining things, which triggers the next compaction sooner.

The Compaction Tax

Every 20–30 turns, the context warning hits and you get two bad choices: ignore it and watch the agent hallucinate, or run /compact and watch it lobotomize itself into a tidy two-paragraph summary of a 30-minute investigation. Either way you lose five minutes re-narrating your own project back to the agent like it's a new hire. That's not a workflow — that's a hamster wheel.

The 200x ROI

Here's the cost comparison that made me build this:

Operation Tokens What you get
grep -r "auth" src/ ~5,000-10,000 500 results, mostly irrelevant
find . -name "*.py" ~2,000 Every Python file, no context
Agent re-orientation ~2,000 You re-explaining yesterday
claude-auto-mem files --json --limit 10 ~50 Exactly the 10 files you touched yesterday

50 tokens vs 10,000 — a 200x improvement.

Before & After

Before claude-auto-mem — new session on a project:

You: Fix the failing test in the auth module

Agent: Let me explore the project structure...
       $ find . -name "*.py" | head -50           ← 2K tokens
       $ grep -r "test.*auth" tests/              ← 5K tokens
       $ cat tests/test_auth.py                    ← 3K tokens
       $ cat src/auth/handler.py                   ← 2K tokens
       I see several test files. Which test is failing?

You: The one we were working on yesterday, the token refresh edge case

Agent: Let me search for that...
       $ grep -r "refresh" tests/                  ← 4K tokens
       ...

Total: ~16K tokens burned, 8 minutes elapsed, agent still isn't oriented.

After claude-auto-mem — same scenario:

You: Fix the failing test in the auth module

Agent: [auto-recall: claude-auto-mem files --json --limit 10]
       → src/auth/refresh.py, tests/test_refresh_edge_cases.py,
         src/auth/token_store.py (last touched 14h ago)

       [auto-recall: claude-auto-mem list --json --limit 3]
       → Yesterday: "Fixed token refresh race condition, one edge case
         test still failing on expired token + network timeout combo"

       I can see from your last session that test_refresh_edge_cases.py
       has a failing test for the expired token + network timeout case.
       Let me look at that specific test...
       $ cat tests/test_refresh_edge_cases.py      ← 1K tokens (targeted)

Total: ~1.1K tokens, 30 seconds, agent is immediately productive.

How it compares

Approach Dependencies Writes to DB Setup Agent-native
claude-auto-mem None (stdlib) ❌ Read-only pip install ✅ Instruction-file
MCP server Node.js runtime Varies Server config ❌ Protocol layer
Custom hooks Varies Often yes Hook scripts ❌ Event-driven
Manual grep None None ❌ Manual

Mental Model: RAM vs Disk

  • Context window = RAM. Fast, limited, clears on restart.
  • session-store.db = Disk. Persistent, searchable, grows forever.

claude-auto-mem is the page fault handler — it pulls exact facts from disk in ~50 tokens when the agent needs them.

It's not unlimited context. It's unlimited context recall. In practice, same thing.

Design

Copilot CLI backend:

┌─────────────────────────────────────────────────┐
│  copilot-instructions.md                        │
│  "Run claude-auto-mem FIRST on every prompt"         │
└──────────────────┬──────────────────────────────┘
                   │ agent reads instruction
                   ▼
┌─────────────────────────────────────────────────┐
│  claude-auto-mem CLI                                │
│  (pure Python, zero deps, read-only)            │
└──────────────────┬──────────────────────────────┘
                   │ SELECT ... FROM sessions
                   ▼
┌─────────────────────────────────────────────────┐
│  ~/.copilot/session-store.db                    │
│  (SQLite + FTS5, owned by Copilot CLI binary)   │
└─────────────────────────────────────────────────┘

Claude Code backend:

┌─────────────────────────────────────────────────┐
│  ~/.claude/settings.json                        │
│  SessionStart hook → injects ~50-token context  │
└──────────────────┬──────────────────────────────┘
                   │ hook fires on every new session
                   ▼
┌─────────────────────────────────────────────────┐
│  claude-auto-mem CLI                                │
│  (pure Python, zero deps)                       │
└──────────────────┬──────────────────────────────┘
                   │ SELECT ... FROM FTS5 index
                   ▼
┌─────────────────────────────────────────────────┐
│  ~/.claude/.sr-index.db                         │
│  (SQLite FTS5, built by claude-auto-mem from        │
│   ~/.claude/projects/ JSONL session files)      │
└─────────────────────────────────────────────────┘
  • Zero dependencies — stdlib only (sqlite3, json, argparse)
  • Read-only on source data — never writes to ~/.copilot/session-store.db or Claude Code's JSONL files
  • WAL-safe — exponential backoff retry on SQLITE_BUSY (50→150→450ms)
  • Schema-aware — validates expected schema on every call, fails fast on drift
  • Telemetry — ring buffer of last 100 invocations for concurrency monitoring
  • Backend auto-detection — uses Copilot DB if present, falls back to ~/.claude/projects/ automatically

Usage

Try these prompts with your agent

Once wired into your agent's instruction file, session-recall runs on every prompt — giving the agent your recent files and sessions as context before it does anything else.

"Search recent sessions about fixing the db connection bug"
"Check past 5 days sessions for latest plans?"
"Pick up where we left off on the API refactor"
"search recent sessions for last 10 files we modified"
"search sessions for the db migration bug"

No special syntax. The agent reads your session history and gets oriented in seconds instead of minutes.

How it works under the hood

Progressive disclosure — most prompts never get past Tier 1.

Tier 1 — Cheap scan (~50 tokens). Usually enough.

session-recall files --json --limit 10
session-recall list --json --limit 5

Tier 2 — Focused recall (~200 tokens). When Tier 1 isn't enough.

session-recall search "specific term" --json

Tier 3 — Full session detail (~500 tokens). Only when investigating something specific.

session-recall show <session-id> --json

Operational commands:

session-recall health          # 9-dimension health dashboard
session-recall schema-check    # validate DB schema after Copilot CLI upgrades

Claude Code Backend

claude-auto-mem now includes a first-class Claude Code backend that reads ~/.claude/projects/ JSONL session files and builds a local SQLite FTS5 index at ~/.claude/.sr-index.db.

Quick setup (2 steps)

# 1. Build the local session index from ~/.claude/projects/ JSONL files
session-recall cc-index

# 2. Wire a SessionStart hook into ~/.claude/settings.json
session-recall install-mode --setup

After step 2, every new Claude Code conversation automatically receives ~50 tokens of recent session context — no copilot-instructions.md needed.

Index commands

session-recall cc-index                 # build / update the index (incremental)
session-recall cc-index --rebuild       # force a full rebuild from scratch
session-recall cc-index --status        # show index freshness and session count

The index lives at ~/.claude/.sr-index.db. It is owned and written exclusively by claude-auto-mem — Claude Code's JSONL files are never modified.

Hook installation

session-recall install-mode             # detect Claude Code surfaces (CLI, VS Code, JetBrains, Desktop)
session-recall install-mode --setup     # wire SessionStart hook automatically
session-recall install-mode --dry-run   # preview changes before applying

--setup adds a SessionStart hook entry to ~/.claude/settings.json. The hook runs session-recall list --json --limit 3 at the start of each conversation and injects the result as context (~50 tokens). No instruction file changes are required.

Using the Claude Code backend on query commands

# Auto-detection: uses Claude Code backend if ~/.claude/projects/ exists
session-recall list --json --limit 10
session-recall files --days 7
session-recall search "auth refactor"

# Explicit backend flag
session-recall --backend claude list --json --limit 10
session-recall --backend claude files --days 7
session-recall --backend claude search "auth refactor"
session-recall --backend claude show SESSION_ID
session-recall --backend claude health

# Force Copilot backend even if Claude Code is also installed
session-recall --backend copilot list --json --limit 10

Backend auto-detection rules:

Condition Backend selected
~/.copilot/session-store.db exists copilot
~/.claude/projects/ exists (no Copilot DB) claude
Both exist copilot (pass --backend claude to override)
Neither exists Error with setup instructions

Health Check

Dim Name                   Zone     Score  Detail
----------------------------------------------------------------------
 1  DB Freshness           🟢 GREEN   8.0  15.8h old
 2  Schema Integrity       🟢 GREEN  10.0  All tables/columns OK
 3  Query Latency          🟢 GREEN  10.0  1ms
 4  Corpus Size            🟢 GREEN  10.0  399 sessions
 5  Summary Coverage       🟢 GREEN   7.4  92% (367/399)
 6  Repo Coverage          🟢 GREEN  10.0  8 sessions for owner/repo
 7  Concurrency            🟢 GREEN  10.0  busy=0.0%, p95=48ms
 8  E2E Probe              🟢 GREEN  10.0  list→show OK
 9  Progressive Disclosure  ⚪ CALIBRATING  —  Collecting baseline (n=42/200)

Agent Integration

claude-auto-mem works with any agent that supports instruction files — GitHub Copilot CLI, Claude Code, Cursor, Aider, Windsurf, and more. Installation wires session-recall into your agent's instruction file so it runs context recall automatically.

See deploy/install.md for setup and copilot-instructions-template.md for integration patterns.

See UPGRADE-COPILOT-CLI.md for schema validation after Copilot CLI upgrades.

What This Isn't

  • Not a vector database — no embeddings, SQLite FTS5 only.
  • Not cross-machine sync — local only.
  • Not a replacement for project documentation — recalls what you did, not how the system works.

FAQ

Is it safe? Does it modify my session data? No. claude-auto-mem is strictly read-only on your agent's session data. It never writes to ~/.copilot/session-store.db or Claude Code's JSONL files under ~/.claude/projects/. The only file claude-auto-mem writes is its own index at ~/.claude/.sr-index.db.

What happens when Copilot CLI updates its schema? Run session-recall schema-check to validate. The tool fails fast on schema drift rather than returning bad data. See UPGRADE-COPILOT-CLI.md.

Can I use both Copilot CLI and Claude Code at the same time? Yes. Use --backend copilot or --backend claude to query either one explicitly. Without the flag, claude-auto-mem picks whichever DB it finds first (Copilot takes priority if both are present).

Roadmap

See ROADMAP.md.

Contributing

See CONTRIBUTING.md for setup and guidelines. Issues, PRs, and docs improvements are welcome.

If claude-auto-mem saved you time, star the repo — it's the best way to help others find it.

🔗 Share it: "Zero-dependency CLI that gives your AI coding agent session memory. Read-only, schema-checked, ~50 tokens per prompt."github.com/dezgit2025/auto-memory

Disclaimer

This is an independent open-source project. It is not affiliated with, endorsed by, or supported by Microsoft, GitHub, or any other company. There is no official support — use at your own risk. Contributions and issues are welcome on GitHub.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_auto_mem-1.0.1.tar.gz (67.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_auto_mem-1.0.1-py3-none-any.whl (96.0 kB view details)

Uploaded Python 3

File details

Details for the file claude_auto_mem-1.0.1.tar.gz.

File metadata

  • Download URL: claude_auto_mem-1.0.1.tar.gz
  • Upload date:
  • Size: 67.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_auto_mem-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4f2fb472272d3c691ee2f29ef79702bc0c1457ff52ac5da4a879761de5b99393
MD5 b06acfd5c9136312c0cc3ed6c23d02e8
BLAKE2b-256 32cceb7081654ec5f90ed7fc68a1e5adf0ceab81bfcdf1787c7ec01ab4812bb2

See more details on using hashes here.

File details

Details for the file claude_auto_mem-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: claude_auto_mem-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 96.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_auto_mem-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2fbaee78465f7270d64a142c9cc10c3767da2be897f925620a16678cd3e2b5c
MD5 1e70fcbae02f52cdddfae96b0ea2167c
BLAKE2b-256 53cfd28eaf8daaecb176446608019aebd4066e923621183229c5ca0f1d343127

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page