memex
CLAUDE.md142 starsChanged 3 months agoMITView on GitHub
Detailed architecture reference: docs/ARCHITECTURE.md Zettelkasten memory for AI agents. Markdown cards in ~/.memex/cards/ with [[wikilinks]]. npm package @touchskyer/memex. Distributed as CLI + MCP server + Claude Code plugin + VS Code extension + Pi extension. Build has a known TS error (node-llama-cpp optional dep). Ignore it — it compiles fine for distribution. The rule: MCP tools and CLI are thin wrappers. All logic lives in src/commands/. All data access in src/lib/store.ts. Don't put logic in the wrong layer. If you…
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-prompts-warmupSkill
- memex-agentic-memorySkill
- memex-best-practicesSkill
- memex-organizeSkill
- memex-recallSkill
- memex-retroSkill
- memex-syncSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
28 rules. About 0 are common, 7 are distinctive, and 21 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
21
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 45
Keep commands pure: return {output, exitCode} or {success, content/error}.
- Very specific: line 46
Use .js extensions in all imports (Node16 ESM resolution).
- Very specific: line 47
Test both nestedSlugs: false (default) and nestedSlugs: true when touching store.ts.
- Very specific: line 48
Run npm test before declaring anything done.
- Very specific: line 49
Add new MCP tools in operations.ts if they need hooks, in server.ts if they don't.
- Very specific: line 50
Use zod for MCP tool input schemas (already imported in both MCP files).
- Very specific: line 54
Don't replace the custom YAML stringifier in parser.ts with js-yaml — it produces block scalars (>-) that break downstream parsers.
- Very specific: line 55
Don't put business logic in cli.ts — it's orchestration only.
- Very specific: line 56
Don't make hooks throw. HookRegistry.run() swallows errors by design.
- Very specific: line 57
Don't use gray-matter for stringification — only for parsing.
- Very specific: line 58
Don't add heavy dependencies.
- Very specific: line 59
Don't forget to call store.invalidateCache() after any write/delete path that bypasses writeCard()/archiveCard().
- Distinctive: line 63
If you add a new MCP tool:
- Very specific: line 64
Add in server.ts (no hooks) or operations.ts (with hooks)
- Distinctive: line 68
If you add a new CLI command:
- Distinctive: line 73
If you change card format / frontmatter:
- Very specific: line 74
Update parser.ts (parse + stringify)
- Very specific: line 75
Check store.ts (slug validation)
- Distinctive: line 76
Ensure backward compat — old cards must still parse
- Very specific: line 77
Update docs/ARCHITECTURE.md § Data Model
- Distinctive: line 79
If you add an embedding provider:
- Very specific: line 81
Add to EmbeddingProviderType union + createEmbeddingProvider() factory
- Very specific: line 82
Add config fields in config.ts
- Distinctive: line 83
Update auto-detection fallback chain (current order: OpenAI → Azure OpenAI → Local → error.
- Distinctive: line 85
If you change sync behavior:
- Very specific: line 86
All in src/lib/sync.ts (GitAdapter)
- Very specific: line 104
All imported cards get source: flomo in frontmatter.
- Very specific: line 105
Use flomoImportCommand for bulk parsing, or flomo_import_parse MCP tool to preview memos before curating.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Memex — Agent Working Instructions
Detailed architecture reference: docs/ARCHITECTURE.md
What Is This
Zettelkasten memory for AI agents. Markdown cards in ~/.memex/cards/ with [[wikilinks]]. npm package @touchskyer/memex. Distributed as CLI + MCP server + Claude Code plugin + VS Code extension + Pi extension.
Before You Touch Anything
npm test # must pass. vitest, 70% coverage threshold.Build has a known TS error (node-llama-cpp optional dep). Ignore it — it compiles fine for distribution.
How The Code Is Layered
MCP tools (src/mcp/) → Commands (src/commands/) → Lib (src/lib/) → Filesystem (~/.memex/)
↑ client-facing ↑ business logic ↑ data accessThe rule: MCP tools and CLI are thin wrappers. All logic lives in src/commands/. All data access in src/lib/store.ts. Don't put logic in the wrong layer.
Files You'll Actually Need
| When you're changing... | Read these first |
| Card read/write/slug behavior | src/lib/store.ts (164 lines — read all of it) |
| MCP tool behavior | src/mcp/operations.ts (high-level), src/mcp/server.ts (low-level) |
| Search (keyword or semantic) | src/commands/search.ts (most complex file, ~390 lines) |
| Sync / git operations | src/lib/sync.ts (GitAdapter, autoSync, autoFetch) |
| Embeddings | src/lib/embeddings.ts (3 providers + cache) |
| Card parsing / frontmatter | src/lib/parser.ts (47 lines — tiny but critical) |
| Organize / graph analysis | src/commands/organize.ts |
| Claude Code plugin hooks | hooks/hooks.json |
| VS Code extension | vscode-extension/src/extension.ts |
| Pi extension | pi-extension/index.ts |
Do / Don't
DO
- Keep commands pure: return
{output, exitCode}or{success, content/error}. Let CLI/MCP handle I/O. - Use
.jsextensions in all imports (Node16 ESM resolution). - Test both
nestedSlugs: false(default) andnestedSlugs: truewhen touchingstore.ts. - Run
npm testbefore declaring anything done. - Add new MCP tools in
operations.tsif they need hooks, inserver.tsif they don't. - Use
zodfor MCP tool input schemas (already imported in both MCP files).
DON'T
- Don't replace the custom YAML stringifier in
parser.tswithjs-yaml— it produces block scalars (>-) that break downstream parsers. - Don't put business logic in
cli.ts— it's orchestration only. - Don't make hooks throw.
HookRegistry.run()swallows errors by design. Hooks are infrastructure. - Don't use
gray-matterfor stringification — only for parsing. The customstringifyFrontmatterexists for a reason. - Don't add heavy dependencies. This is a 4-dep project (
commander,gray-matter,zod,@modelcontextprotocol/sdk). Keep it that way. - Don't forget to call
store.invalidateCache()after any write/delete path that bypasseswriteCard()/archiveCard().
Mutation Checklist
If you add a new MCP tool:
- Add in
server.ts(no hooks) oroperations.ts(with hooks) - Schema with
zod, return{ content: [{ type: "text", text }] } - Add tests
If you add a new CLI command:
- Create
src/commands/<name>.ts - Register in
src/cli.ts - Add tests
If you change card format / frontmatter:
- Update
parser.ts(parse + stringify) - Check
store.ts(slug validation) - Ensure backward compat — old cards must still parse
- Update
docs/ARCHITECTURE.md§ Data Model
If you add an embedding provider:
- Implement
EmbeddingProviderinterface inembeddings.ts - Add to
EmbeddingProviderTypeunion +createEmbeddingProvider()factory - Add config fields in
config.ts - Update auto-detection fallback chain (current order: OpenAI → Azure OpenAI → Local → error; Ollama is explicit-only)
If you change sync behavior:
- All in
src/lib/sync.ts(GitAdapter) autoSync()/autoFetch()are called by hooks — test offline tolerance
Key Design Decisions (Don't Undo These)
- Atomic writes:
writeCard()→.tmp→rename(). Prevents corruption. - Path safety:
validateSlug()+assertSafePath()= no directory traversal. Ever. - Client source tagging: MCP server captures
clientInfo.nameat init, injects intosourcefrontmatter. This is how we track which client wrote each card. - Hooks fail silently: They're git sync calls, not user-facing logic. If git is offline, don't crash.
- Embedding cache invalidation: SHA-256 content hash per card. Stale entries cleaned on
embedCards(). Don't switch to timestamp-based — content hash is correct.
Flomo Integration (Bidirectional Sync)
Memex has bidirectional sync with flomo. Two hard rules:
Flomo → Memex (Import)
- Digest, never mechanical import. Flomo memos are fleeting notes, NOT Zettelkasten cards. The agent must read, curate, and rewrite into atomic insights.
- All imported cards get
source: flomoin frontmatter. - Use
flomoImportCommandfor bulk parsing, orflomo_import_parseMCP tool to preview memos before curating. - Quality bar: skip garbage (<150 bytes), merge related memos, extract only non-obvious insights.
Memex → Flomo (Push)
- Anti-loopback: NEVER push
source: flomocards back to flomo. This is enforced in code (pushSingleCard+ batch filter inflomoPushCommand). Don't remove it. - Push via webhook (
flomoPushCommand). Webhook URL validated at both read and write time (defense in depth).
Code Locations
| What | Where |
| All flomo logic | src/commands/flomo.ts |
| MCP tools | src/mcp/operations.ts (flomo_push, flomo_import_parse) |
| Anti-loopback guard | pushSingleCard() line ~135, batch filter line ~410 |
| Webhook validation | isValidFlomoWebhookUrl() — HTTPS + flomoapp.com + /iwh/ prefix |
| Tests | tests/commands/flomo.test.ts, tests/commands/flomo-import.test.ts |
Platform Integration Files
Claude Code: hooks/hooks.json, skills/*, .claude-plugin/*
VS Code: vscode-extension/
Pi: pi-extension/index.tsThese are separate integration surfaces. Changing core code doesn't require updating them unless you change tool signatures or card format.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

