A method for giving AI agents durable, cross-session memory through a structured wiki the agent maintains. Adapted from Andrej Karpathy's LLM wiki pattern (An LLM should maintain a wiki, not re-derive knowledge per query). The wiki is the brain. The agent is the programmer. Markdown editor is the IDE.
Why: AI agents lose context between sessions. Memory files help but are shallow (key-value recall). A wiki is deeper, it synthesizes, cross-references, and evolves. The agent reads the wiki at session start, works with compressed context instead of re-deriving state, and writes back what it learns. This addresses When the agent isn't doing what you want, fix the context, not the model: when the agent isn't doing what you want, fix the context.
Three layers
- Raw sources (
raw/). Immutable, append-only. LinkedIn posts, articles, podcasts, screenshots, recruiter emails. One file per artifact. Attribution in frontmatter. Never edited after creation. - Synthesis wiki (everything else). Agent-maintained. Projects, people, companies, concepts, decisions, tools. Each page is live. Stubs are fine. "Unknown" is a legal value.
- Schema (
CLAUDE.mdconstitution). Small, stable, rarely edited. Defines page frontmatter, operations, rules. Every agent reads this first.
- raw/articles/, blog posts, essays, gists
- raw/linkedin-posts/
- raw/podcasts/, transcripts, chapter notes
- raw/assets/, images, screenshots, PDFs
Four operations
- INGEST. Source →
raw/{subdir}/{slug}.mdwith frontmatter → stub a wiki page if warranted → append tolog.md. - QUERY. Read
index.md(catalog) → read 1–3 relevant pages → extract, cite paths. If the answer isn't there, say so. Do not fabricate. - LINT. Walk every page. Check for orphans, contradictions, stale claims, missing pages, naming drift, schema violations, index mismatches. Write findings. Fix high-impact in place. Leave low-impact documented.
- INDEX + LOG.
index.mdis the content catalog (one line per page, under 200 lines).log.mdis the chronological append-only timeline.
Setup
- Directory.
wiki/withCLAUDE.md,system-prompt.md,index.md,log.md,README.md, plusraw/,projects/,concepts/,decisions/,people/,companies/,tools/,lint/. - Schema (
CLAUDE.md). Page frontmatter format, four operations, domain-specific rules (anti-fab, voice, confidentiality), integration points, change protocol. - Agent distillation (
system-prompt.md). Compressed (~50–80 lines). What gets@-imported into your CLAUDE.md so the agent loads it at session start without burning context on the full constitution. - Wire into sessions. Add
@/path/to/wiki/system-prompt.mdand@/path/to/wiki/index.mdto~/CLAUDE.md. These imports expand inline at session start. - Seed initial pages. Start with what you reference most. Stubs are fine. The agent fills in as it works.
- Optional: register as Obsidian vault with attachment folder →
raw/assets/, graph color groups by path, backlinks enabled.
Greppable log format
## YYYY-MM-DD
- [harness] kind | subject — short description
Harness = which agent/tool wrote this. Kind ∈ {ingest, query, lint, decision, ship, correction, upgrade, debrief, observation}. Subject = short noun phrase matching a wiki page name.
Enables: grep "[harness]" log.md, grep "| decision |" log.md.
Page frontmatter
title:
type: person | company | project | concept | decision | tool | raw
status: active | paused | archived | stub
last_updated: YYYY-MM-DD
related: [other-page.md]
domain: <tags>
Anti-fabrication rules
- Every claim traces to
raw/, memory, code, or the operator's own words. - If a claim does not trace, write "unverified" and stop.
- Tag metrics with attribution tier (verified / self-reported / contextual / indirect / direct).
- Don't re-read pages already read this session. Grep before bulk reads.
Common failure modes
- Treating raw/ as editable. Raw is append-only.
- Index.md balloons past 200 lines.
- Lint passes that fix nothing, file findings, fix high-impact, document low-impact.
- "Just in case" bulk reads burning context.
- Agent rewriting page sections it did not mean to touch, read before write.
- Synthesis pages mirroring raw/ verbatim. Synthesis is compression + cross-reference, not transcription.
Integration points
- LLM agents (Claude Code, codex, cursor) load schema + index at session start.
- Personal memory (short, dense) links to wiki, do not duplicate.
- Web/API layer can serve wiki via routes for cross-machine access.
- Any link the agent encounters can be ingested into raw/ and stubbed in synthesis.