███╗   ███╗███████╗██╗  ██╗
████╗ ████║██╔════╝╚██╗██╔╝
██╔████╔██║█████╗   ╚███╔╝
██║╚██╔╝██║██╔══╝   ██╔██╗
██║ ╚═╝ ██║███████╗██╔╝ ██╗
╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝
Open source · MIT license

AI agents forget everything
between sessions.
mex fixes that.

Persistent, navigable project memory via a structured markdown scaffold. A CLI that detects when docs drift from reality — and fixes them.

Star on GitHub
mex mascot — pixel-art hermit crab with glasses carrying a map

The problem is amnesia

Your AI agent is brilliant — for exactly one session. Then it forgets everything and you start over.

Cold starts

Every session starts cold. The agent has no idea what it built yesterday, what conventions you agreed on, or what broke last week.

Context flooding

Developers compensate by stuffing everything into CLAUDE.md — flooding the context window, burning tokens, and degrading attention.

Doc drift

The project changes and nobody updates the docs. The agent's understanding drifts from reality. Silently.

mex is a structured markdown scaffold with a CLI that keeps it honest. The scaffold gives agents persistent project knowledge through navigable files — architecture, conventions, decisions, patterns. The CLI detects when those files drift from the actual codebase, and targets AI to fix only what's broken.

How it works

Navigate, don't dump. The agent loads only the context it needs for the current task.

1

Session starts

Agent wakes up with zero context.

2

Agent loads CLAUDE.md

Auto-loaded by the tool. ~120 tokens. Points to .mex/

3

CLAUDE.md → ROUTER.md

Routing table that maps task types to the right context file.

4

ROUTER.md → context file

Architecture, stack, conventions, decisions, setup — only what's relevant.

5

Context → pattern file

Task-specific guides with gotchas, steps, and verify checklists.

6

Agent executes

Full project context. Minimal token cost. No hallucination.

Drift detection

Seven checkers validate your scaffold against the real codebase. Zero tokens. Zero AI.

Scoring: starts at 100. Deducts −10 per error, −3 per warning, −1 per info.

pathReferenced file paths that don't exist on disk
edgesYAML frontmatter edge targets pointing to missing files
index-syncpatterns/INDEX.md out of sync with actual pattern files
stalenessScaffold files not updated in 30+ days or 50+ commits
commandnpm run X / make X referencing scripts that don't exist
dependencyClaimed dependencies missing from package.json
cross-fileSame dependency with different versions across files

Scaffold structure

CLI commands

mex checkRun all 7 checkers, output drift score and issues
mex check --quietOne-liner: mex: drift score 92/100 (1 warning)
mex initPre-scan codebase, build structured brief for AI
mex syncDetect drift → build per-file prompts → AI fixes → verify
mex sync --dry-runPreview targeted prompts without executing
mex watchInstall post-commit hook for automatic drift score

Before & after

Real output from running mex init on a production Python/Flask project with Twilio, multi-provider AI pipeline.

BeforeScaffold after git clone
## Current Project State
<!-- What is working. What is not yet built.
     Known issues.
     Update this section whenever significant
     work is completed. -->
AfterScaffold after mex init
## Current Project State

**Working:**
- Voice call pipeline (Twilio → STT → LLM → TTS → response)
- Multi-provider STT (ElevenLabs, Deepgram)
- RAG system with Supabase pgvector
- Streaming pipeline with barge-in support

**Not yet built:**
- Admin dashboard for call monitoring
- Automated test suite
- Multi-turn conversation memory across calls

**Known issues:**
- Sarvam AI STT bypass active — routing to
  ElevenLabs as fallback

Patterns directory generated automatically:

patterns/
├── add-api-client.md
├── add-language-support.md
├── debug-pipeline.md
└── add-rag-documents.md

Get started in
5 minutes

1

Clone mex into .mex

Clone the repo as a hidden directory in your project root.

2

Run setup.sh

Auto-builds the CLI, pre-scans your codebase, and populates the scaffold.

3

Start building

Your AI agent now has persistent project memory. Every session.

Works with any codebase. JavaScript, Python, Go, Rust — if it has files, mex can scaffold it.

Cloning into '.mex'...
◌ Building CLI...
✔ CLI built
◌ Scanning codebase...
✔ Detected: Next.js, TypeScript, Tailwind
◌ Populating scaffold...
✔ context/architecture.md populated
✔ context/stack.md populated
✔ context/conventions.md populated
✔ patterns/INDEX.md created
✔ ROUTER.md configured
mex: drift score 100/100

Works with your tools

All config files contain identical content. setup.sh asks which tool you use.

Claude

Claude Code

CLAUDE.md

Cursor

Cursor

.cursorrules

Windsurf

.windsurfrules

GitHub Copilot

GitHub Copilot

copilot-instructions.md