Skip to content

Instantly share code, notes, and snippets.

@ry
Forked from karpathy/llm-wiki.md
Last active August 26, 2026 03:29
Show Gist options
  • Select an option

  • Save ry/c56dfa7b1b90eeff2d8d0127e45ae3bb to your computer and use it in GitHub Desktop.

Select an option

Save ry/c56dfa7b1b90eeff2d8d0127e45ae3bb to your computer and use it in GitHub Desktop.
llm-wiki

LLM Wiki

A pattern for building personal knowledge bases using LLMs.

This is an idea file, it is designed to be copy pasted to your own LLM Agent (e.g. OpenAI Codex, Claude Code, OpenCode / Pi, or etc.). Its goal is to communicate the high level idea, but your agent will build out the specifics in collaboration with you.

The core idea

Most people's experience with LLMs and documents looks like RAG: you upload a collection of files, the LLM retrieves relevant chunks at query time, and generates an answer. This works, but the LLM is rediscovering knowledge from scratch on every question. There's no accumulation. Ask a subtle question that requires synthesizing five documents, and the LLM has to find and piece together the relevant fragments every time. Nothing is built up. NotebookLM, ChatGPT file uploads, and most RAG systems work this way.

The idea here is different. Instead of just retrieving from raw documents at query time, the LLM incrementally builds and maintains a persistent wiki — a structured, interlinked collection of markdown files that sits between you and the raw sources. When you add a new source, the LLM doesn't just index it for later retrieval. It reads it, extracts the key information, and integrates it into the existing wiki — updating entity pages, revising topic summaries, noting where new data contradicts old claims, strengthening or challenging the evolving synthesis. The knowledge is compiled once and then kept current, not re-derived on every query.

This is the key difference: the wiki is a persistent, compounding artifact. The cross-references are already there. The contradictions have already been flagged. The synthesis already reflects everything you've read. The wiki keeps getting richer with every source you add and every question you ask.

You never (or rarely) write the wiki yourself — the LLM writes and maintains all of it. You're in charge of sourcing, exploration, and asking the right questions. The LLM does all the grunt work — the summarizing, cross-referencing, filing, and bookkeeping that makes a knowledge base actually useful over time. In practice, I have the LLM agent open on one side and the wiki open on the other — in an editor, or rendered on GitHub. The LLM makes edits based on our conversation, and I browse the results in real time — following links, reading the updated pages. The LLM is the programmer; the wiki is the codebase.

This can apply to a lot of different contexts. A few examples:

  • Personal: tracking your own goals, health, psychology, self-improvement — filing journal entries, articles, podcast notes, and building up a structured picture of yourself over time.
  • Research: going deep on a topic over weeks or months — reading papers, articles, reports, and incrementally building a comprehensive wiki with an evolving thesis.
  • Reading a book: filing each chapter as you go, building out pages for characters, themes, plot threads, and how they connect. By the end you have a rich companion wiki. Think of fan wikis like Tolkien Gateway — thousands of interlinked pages covering characters, places, events, languages, built by a community of volunteers over years. You could build something like that personally as you read, with the LLM doing all the cross-referencing and maintenance.
  • Business/team: an internal wiki maintained by LLMs, fed by Slack threads, meeting transcripts, project documents, customer calls. Possibly with humans in the loop reviewing updates. The wiki stays current because the LLM does the maintenance that no one on the team wants to do.
  • Competitive analysis, due diligence, trip planning, course notes, hobby deep-dives — anything where you're accumulating knowledge over time and want it organized rather than scattered.

Architecture

There are three layers:

Raw sources — your curated collection of source documents. Articles, papers, images, data files. These are immutable — the LLM reads from them but never modifies them. This is your source of truth. Keep the collection in a raw/ subdirectory inside the wiki directory: sources and the pages that cite them then travel as one tree — one clone, one commit history — and relative links from wiki pages into raw/ always resolve.

The wiki — a directory of LLM-generated markdown files. Summaries, entity pages, concept pages, comparisons, an overview, a synthesis. The LLM owns this layer entirely. It creates pages, updates them when new sources arrive, maintains cross-references, and keeps everything consistent. You read it; the LLM writes it.

The schema — a document (e.g. CLAUDE.md for Claude Code or AGENTS.md for Codex) that tells the LLM how the wiki is structured, what the conventions are, and what workflows to follow when ingesting sources, answering questions, or maintaining the wiki. This is the key configuration file — it's what makes the LLM a disciplined wiki maintainer rather than a generic chatbot. You and the LLM co-evolve this over time as you figure out what works for your domain.

One structural requirement: the wiki lives in a git repository. This is not an optional nicety — the pattern depends on it. The commit history is the wiki's chronological log (see below), and version control is what makes aggressive maintenance — rewriting, merging, deleting pages — safe to do.

Operations

Ingest. You drop a new source into the raw collection and tell the LLM to process it. An example flow: the LLM reads the source, discusses key takeaways with you, writes a summary page in the wiki, updates the index, updates relevant entity and concept pages across the wiki, and commits the whole change with a message that records what was ingested and what it touched. A single source might touch 10-15 wiki pages. Personally I prefer to ingest sources one at a time and stay involved — I read the summaries, check the updates, and guide the LLM on what to emphasize. But you could also batch-ingest many sources at once with less supervision. It's up to you to develop the workflow that fits your style and document it in the schema for future sessions.

Query. You ask questions against the wiki. The LLM searches for relevant pages, reads them, and synthesizes an answer with citations. Answers can take different forms depending on the question — a markdown page, a comparison table, a slide deck (Marp), a chart (matplotlib), a canvas. The important insight: good answers can be filed back into the wiki as new pages. A comparison you asked for, an analysis, a connection you discovered — these are valuable and shouldn't disappear into chat history. This way your explorations compound in the knowledge base just like ingested sources do.

Lint. Periodically, ask the LLM to health-check the wiki. Look for: contradictions between pages, stale claims that newer sources have superseded, orphan pages with no inbound links, important concepts mentioned but lacking their own page, missing cross-references, data gaps that could be filled with a web search. The LLM is good at suggesting new questions to investigate and new sources to look for. This keeps the wiki healthy as it grows.

Compact. Wikis accumulate debt the way codebases do. Pages grow by accretion until they carry stale claims, near-duplicates of other pages, and detail that no longer earns its place. Periodically have the LLM pay the debt down: rewrite pages that have decayed, merge pages that turned out to be one subject, delete pages that stopped mattering, and promote clusters of related pages into subdirectories (see below). Version control is what makes this safe — nothing is truly lost. Where lint detects, compaction repairs. Importantly, the LLM should suggest compaction when it notices the mess, because you often aren't looking at the wiki at all — it's the LLM's memory more than your reading material.

Indexing, structure, and the log

Three navigation concerns grow with the wiki: finding pages, keeping the directory tree scannable, and knowing what happened recently.

README.md is the index: a catalog of everything in the wiki — each page listed with a link, a one-line summary, and optionally metadata like date or source count. Organized by category (entities, concepts, sources, etc.). The LLM updates it on every ingest. When answering a query, the LLM reads the index first to find relevant pages, then drills into them. This works surprisingly well at moderate scale (~100 sources, ~hundreds of pages) and avoids the need for embedding-based RAG infrastructure. Use README.md rather than index.md for this: GitHub and most other forges render README.md automatically when you browse a directory, so the index doubles as the wiki's landing page.

Links. Use standard markdown links with relative paths — [page-name](page-name.md) — not [[wikilinks]]. Wikilinks only resolve inside specialized note-taking apps; standard links work everywhere markdown renders — GitHub, editors, static site generators — so the wiki stays browsable wherever it lives. The traditional cost of path-based links is that renaming a page breaks every inbound link, but here the LLM does the maintenance: when it moves or renames a page it fixes the references in the same pass.

Subdirectories. Start flat. A flat directory is right for the first several dozen pages, the same way a flat src/ is right for a young codebase. But wikis, like codebases, eventually need modules: when a cluster of pages forms around one topic, move the cluster into a subdirectory and give it its own README.md index. The root README.md then links to the subdirectory's index rather than to every page inside it. This promotion is a compaction move — the LLM should propose it when the root index gets hard to scan.

The log is the commit history. Do not keep a chronological log file. An append-only log.md sounds attractive and fails in practice: concurrent agents fight over merge conflicts at the tail, entries land out of order, and the file grows into an unreadable scroll. Git already maintains an ordered, append-only, conflict-free record, so use it. Every wiki change is one commit, and the commit message is the log entry — a conventional title plus a body that says what happened and why. The entry always rides in the same commit as the change it describes; a separate log-only commit is pollution. git log --oneline -- wiki/ gives the timeline, and git log --follow -p page.md gives the full story of any page.

Optional: CLI tools

At some point you may want to build small tools that help the LLM operate on the wiki more efficiently. A search engine over the wiki pages is the most obvious one — at small scale the index file is enough, but as the wiki grows you want proper search. qmd is a good option: it's a local search engine for markdown files with hybrid BM25/vector search and LLM re-ranking, all on-device. It has both a CLI (so the LLM can shell out to it) and an MCP server (so the LLM can use it as a native tool). You could also build something simpler yourself — the LLM can help you vibe-code a naive search script as the need arises.

Tips and tricks

  • Web clipper. A browser extension that converts web articles to markdown is very useful for quickly getting sources into your raw collection.
  • Download images locally. Have the LLM download the images an article references into a fixed directory (e.g. raw/assets/) and rewrite the article to point at the local copies. This is optional but useful — it lets the LLM view and reference images directly instead of relying on URLs that may break. Note that LLMs can't natively read markdown with inline images in one pass — the workaround is to have the LLM read the text first, then view some or all of the referenced images separately to gain additional context. It's a bit clunky but works well enough.
  • Marp is a markdown-based slide deck format. Useful for generating presentations directly from wiki content.

Why this works

The tedious part of maintaining a knowledge base is not the reading or the thinking — it's the bookkeeping. Updating cross-references, keeping summaries current, noting when new data contradicts old claims, maintaining consistency across dozens of pages. Humans abandon wikis because the maintenance burden grows faster than the value. LLMs don't get bored, don't forget to update a cross-reference, and can touch 15 files in one pass. The wiki stays maintained because the cost of maintenance is near zero.

The human's job is to curate sources, direct the analysis, ask good questions, and think about what it all means. The LLM's job is everything else.

The idea is related in spirit to Vannevar Bush's Memex (1945) — a personal, curated knowledge store with associative trails between documents. Bush's vision was closer to this than to what the web became: private, actively curated, with the connections between documents as valuable as the documents themselves. The part he couldn't solve was who does the maintenance. The LLM handles that.

Note

This document is intentionally abstract. It describes the idea, not a specific implementation. The exact directory structure, the schema conventions, the page formats, the tooling — all of that will depend on your domain, your preferences, and your LLM of choice. Everything mentioned above is optional and modular — pick what's useful, ignore what isn't. For example: your sources might be text-only, so you don't need image handling at all. Your wiki might be small enough that the index file is all you need, no search engine required. You might not care about slide decks and just want markdown pages. You might want a completely different set of output formats. The right way to use this is to share it with your LLM agent and work together to instantiate a version that fits your needs. The document's only job is to communicate the pattern. Your LLM can figure out the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment