Claude Code 與 Obsidian:如何從 ChatGPT 對話記錄建立 Karpathy 的 LLM Wiki
Claude Code + Obsidian: Build Karpathy's LLM Wiki From Your ChatGPT History
作者示範如何以 Claude Code 和普通 Obsidian vault 建立 Karpathy 的 LLM Wiki,並用一個 80 行 Node 腳本把 ChatGPT 匯出資料轉成每個對話一則 Markdown 筆記。
In April 2026, Andrej Karpathy published a short idea file called "LLM Wiki". The pitch: stop asking an LLM to re-read your documents every time. Let it maintain a wiki instead, one Markdown page per topic, kept up to date as you add sources. His one-line summary:
"Obsidian is the IDE; the LLM is the programmer; the wiki is the codebase."
The usual examples feed that wiki with web clips, papers and PDFs. But for a lot of us, the richest source of our own thinking is somewhere else: years of ChatGPT and Claude conversations. Decisions, half-finished plans, the reasons we picked one library over another. All of it sits in a chat sidebar where no agent can read it.
This post builds the whole thing with Claude Code and a plain Obsidian vault, then gets your ChatGPT history into it with an 80-line Node script. No plugins are required.
TL;DR
- A vault with
raw/(sources Claude reads but never edits),wiki/(pages Claude writes) and aCLAUDE.mdwith the rules. - Run
claudein the vault. Claude Code reads and writes the Markdown files directly. You don't need MCP or a plugin for this. - Export your ChatGPT data, convert
conversations.jsoninto one note per chat with the script below, and drop them intoraw/chatgpt/. - Ask Claude to ingest, query and lint. Review the changes with
git diff.
What is Karpathy's LLM wiki?
The gist describes three layers:
- Raw sources: "your curated collection of source documents". The LLM reads them and never changes them.
-
The wiki: Markdown pages the LLM writes and owns, plus two special files:
index.md(a catalog, one line per page) andlog.md(an append-only record of what was done). -
The schema: a file like
CLAUDE.mdorAGENTS.mdthat sets the structure and workflows. Karpathy calls it "what makes the LLM a disciplined wiki maintainer rather than a generic chatbot."
And three operations:
| Operation | What the LLM does |
|---|---|
| Ingest | Reads a new source, updates the related topic pages, index.md and log.md
|
| Query | Reads index.md first, then only the pages it needs; good answers get filed back as new pages |
| Lint | Looks for contradictions, stale claims, orphan pages and missing cross-links |
The difference from plain RAG is that the work compounds. Every ingest leaves the wiki better organized, so the next question is cheaper to answer.
Why your AI chats belong in raw/
Web clips tell the wiki what other people think. Your chats tell it what you asked, decided and rejected, with dates. A year of ChatGPT is usually the best record you have of:
- why a project went one way and not another,
- what you already tried and dropped,
- the preferences you keep re-explaining to every new chat.
That's exactly the context a wiki maintainer needs. The problem is getting it out.
Step 1: Set up the vault
Any Obsidian vault works. Inside it:
vault/
├── CLAUDE.md
├── raw/
│ ├── chatgpt/
│ ├── claude/
│ └── clips/
└── wiki/
├── index.md
└── log.md
Then make it a git repo. This is your safety net: every ingest becomes a diff you can read and revert.
cd ~/vault
git init
printf ".obsidian/workspace*\n.trash/\n" > .gitignore
git add -A && git commit -m "Vault before the LLM wiki"
Obsidian picks up files written by other programs. Its help page says it "automatically refreshes your vault to keep up with any external changes" (Obsidian). One rule: don't type in a note while Claude is rewriting it.
Step 2: Write the schema (CLAUDE.md)
Claude Code loads CLAUDE.md from the folder you start it in, every session (Claude Code docs). Running /init drafts one for you, but for a wiki you want explicit rules. This is the one I'd start with:
# This vault is an LLM wiki
You maintain `wiki/`. Everything in `raw/` is source material.
## Layout
- `raw/` holds sources. Read them. Never edit, move or delete them.
- `raw/chatgpt/` and `raw/claude/`: my AI chats, one note per chat.
The frontmatter has `created` and `url`. `## You` is me.
- `wiki/` holds pages you write. One topic, project, decision or person per page.
- `wiki/index.md`: one line per page, `[[Page name]]: what it covers`.
- `wiki/log.md`: append only. One line per ingest, query or lint:
date, what you did, which files.
## Ingest
When I say "ingest <path>":
1. Skip sources already listed in log.md.
2. For each topic, decision or project in a source, update its wiki page or create one.
3. Every claim links its source with a wikilink: [[2025-10-09 Pricing page copy]].
4. If a newer chat contradicts a page, keep both with dates, newest first.
5. Update index.md, then add a line to log.md.
## Query
Read index.md first, then only the pages you need. Answer with links.
If the answer is worth keeping, offer to save it as a wiki page.
## Lint
Report contradictions, pages with no links in or out, claims older than
6 months with no newer source, and topics mentioned on 3+ pages that have
no page of their own. Report first. Fix only what I approve.
## Style
Plain Markdown and Obsidian wikilinks. Pages under about 500 words; split longer ones.
Rule 3 is the one that pays off in Obsidian. Because every wiki claim links the chat it came from, each chat note shows its wiki pages in backlinks, and the graph view becomes a map of where your ideas came from.
Step 3: Get your ChatGPT history out
In ChatGPT, open Settings → Data controls → Export data and confirm. OpenAI says the export can take up to 7 days, and the emailed link works for 24 hours (OpenAI). If the email never shows up, here's what to check.
Unzip it. Your chats are in conversations.json. Big exports split it into conversations-000.json, conversations-001.json and so on. Newer exports sometimes put those inside a second ZIP, so unzip that one too.
The trap: a chat is a tree, not a list
Open the JSON and you'll see each conversation has a mapping object, not an array of messages. That's because ChatGPT keeps every version: each time you edit a message or hit regenerate, it starts a new branch. The mapping holds all branches, and current_node points at the last message of the one you actually saw.
{
"title": "Pricing page copy",
"current_node": "a4",
"mapping": {
"u1": { "parent": "sys", "children": ["a1"], "message": { "author": { "role": "user" }, "...": "..." } },
"a1": { "parent": "u1", "children": [], "message": { "...": "the answer you threw away" } },
"u1b": { "parent": "sys", "children": ["th"], "message": { "...": "your edited question" } }
}
}
If you loop over Object.values(mapping), you get the abandoned answers, the hidden system prompt, tool calls and their raw output, all mixed together. The fix is to start at current_node and walk up the parent links.
The script
chatgpt-to-md.mjs. Node 20+, no dependencies:
// chatgpt-to-md.mjs: ChatGPT data export -> one Markdown note per chat.
// Usage: node chatgpt-to-md.mjs <unzipped-export-folder> <vault>/raw/chatgpt
// Node 20+, no dependencies.
import { readdir, readFile, writeFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
const [src, out] = process.argv.slice(2);
if (!src || !out) throw new Error('usage: node chatgpt-to-md.mjs <export-folder> <output-folder>');
// conversations.json, or conversations-000.json, -001... in big exports,
// sometimes one folder down (newer exports nest a ZIP: unzip that too)
const files = (await readdir(src, { recursive: true }))
.filter((f) => /(^|[\\/])conversations(-\d+)?\.json$/.test(f)).sort();
const chats = [];
for (const f of files) chats.push(...JSON.parse(await readFile(join(src, f), 'utf8')));
// The chat is a tree: every edit or regenerate starts a new branch.
// Walk up from current_node to get only the version you saw last.
function thread(chat) {
const path = [];
for (let id = chat.current_node; id && chat.mapping[id]; id = chat.mapping[id].parent) {
path.unshift(chat.mapping[id].message);
}
return path;
}
function text(msg) {
const c = msg.content ?? {};
if (c.content_type === 'code') return '```
' + (c.language ?? '') + '\n' + c.text + '\n
```';
if (c.content_type !== 'text' && c.content_type !== 'multimodal_text') return ''; // thoughts, tool output...
return (c.parts ?? []).map((p) => (typeof p === 'string' ? p : '*[image]*')).join('\n\n').trim();
}
const visible = (m) =>
m && ['user', 'assistant'].includes(m.author?.role) &&
(m.recipient ?? 'all') === 'all' && // not a call to a tool
!m.metadata?.is_visually_hidden_from_conversation; // not hidden context
const day = (t) => new Date(t * 1000).toISOString().slice(0, 10);
const iso = (t) => new Date(t * 1000).toISOString().slice(0, 19);
const safe = (s) => s.replace(/[\\/:*?"<>|#^[\]]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 80) || 'Untitled';
await mkdir(out, { recursive: true });
const used = new Set();
let written = 0;
for (const chat of chats) {
const turns = [];
for (const m of thread(chat).filter(visible)) {
const body = text(m);
if (!body) continue;
const who = m.author.role === 'user' ? 'You' : 'ChatGPT';
if (turns.at(-1)?.who === who) turns.at(-1).body += '\n\n' + body; // merge split replies
else turns.push({ who, body });
}
if (!turns.length) continue;
const title = chat.title || 'Untitled';
const start = chat.create_time ?? chat.update_time ?? Date.now() / 1000;
let name = `${day(start)} ${safe(title)}`;
for (let i = 2; used.has(name.toLowerCase()); i++) name = `${day(start)} ${safe(title)} ${i}`;
used.add(name.toLowerCase());
const note = [
'---',
`title: ${JSON.stringify(title)}`,
'source: ChatGPT',
`url: https://chatgpt.com/c/${chat.conversation_id ?? chat.id}`,
`created: ${iso(start)}`,
`updated: ${iso(chat.update_time ?? start)}`,
'tags: [ai-chat, chatgpt]',
'---',
'',
...turns.map((t) => `## ${t.who}\n\n${t.body}\n`),
].join('\n');
await writeFile(join(out, `${name}.md`), note);
written++;
}
console.log(`${written} chats from ${files.join(', ')} -> ${out}`);
Run it:
node chatgpt-to-md.mjs ~/Downloads/chatgpt-export ~/vault/raw/chatgpt
What it handles, and what I tested it against:
- Edited and regenerated messages: only the branch you saw is kept.
- Hidden context, tool calls, tool output and "thinking": skipped. Code the assistant wrote is kept as a fenced block.
-
Split exports (
conversations-000.json…) and the nested-ZIP layout. -
File names:
2025-10-09 Pricing page copy.md. Characters that break Obsidian links (/ : # ^ [ ] |) are removed, and duplicate titles get2,3. -
Frontmatter that Obsidian shows as properties. The names (
source,created,tags: ai-chat) match the Dataview and Bases queries in this guide, so you get a sortable table of every chat for free.
I checked its output against the export parser in Chat to Markdown, the extension I build (more on it below). On a test export with an edited message, a tool call, hidden context, an image, a code reply and split files, both produced the same messages.
What it doesn't do: images become *[image]* (they are in the export as separate files), and times are UTC.
Step 4: Run the wiki
cd ~/vault
claude
Then talk to it:
> ingest raw/chatgpt, starting with the 25 newest chats
> what did I decide about pricing, and when did that change?
> lint the wiki
A few things I'd do from the start:
-
Ingest in batches. A few hundred chats in one go fills the context and gets shallow. 20 to 50 per run, newest first, gives better pages.
log.mdremembers where you stopped. -
Read the diff.
git diff wiki/after each ingest takes a minute and catches the occasional made-up "decision". Commit what you keep. - Skip what shouldn't be there. Delete chats you'd never want summarized before you ingest. Everything Claude Code reads is sent to Anthropic's API to be processed, the same as when you paste it into a chat.
Do you need the Obsidian CLI, MCP or a plugin?
For this workflow, no. A vault is a folder of Markdown files, and Claude Code reads and edits files natively. The other options add Obsidian-specific powers on top:
| Option | What it adds | Setup |
|---|---|---|
Nothing (just claude in the vault) |
Read, write, search files | None |
| Obsidian CLI (official, since 1.12.4, February 2026) | Obsidian's own search, daily notes, properties, tags, from the terminal: obsidian search query="pricing", obsidian daily:append content="...", obsidian property:set .... Claude Code can call it through Bash |
Settings → General → Command line interface. The Obsidian app must be running |
| MCP via Local REST API | The plugin now has a built-in MCP endpoint at https://127.0.0.1:27124/mcp/. Alternatives: mcp-obsidian, obsidian-mcp-server
|
Install the plugin, copy its API key, then claude mcp add --transport http obsidian https://127.0.0.1:27124/mcp/ with the auth header from its README |
| Claudian plugin | Claude Code (and other agents) in an Obsidian sidebar, with the vault as the working folder | Community plugins, desktop only |
| Claude Code IDE plugin | Shares the note you have open with Claude Code via /ide. Read-only |
Community plugins |
As of November 2026, Obsidian has no official MCP server. My rule of thumb: start with nothing, add the CLI when you want daily-note or property operations, and use MCP when the client isn't Claude Code (Claude Desktop, for example).
What about Claude.ai chats, and keeping it current?
Claude's own export (Settings → Privacy → Export data) has a different shape: chat_messages instead of a tree, and newer exports arrive in parts listed by a manifest file. You can point Claude Code at the script above and ask it to write the Claude version. It's a good first job for it.
The bigger issue is that an export is a snapshot. Next month you'll have another hundred chats, and you'll be exporting and converting again.
That's the part I ended up automating. I built Chat to Markdown, a Chrome extension that saves ChatGPT, Claude, Gemini and other chats as Markdown notes in a folder you choose, such as vault/raw/, and keeps each note updated when the chat continues. It writes the same kind of frontmatter as the script, with the chat's model and project too, and it can import the ChatGPT export ZIP directly. It's free for 10 chats. With it, raw/ stays current and the wiki only ever needs "ingest what's new since the last log entry". If you're moving from ChatGPT to Claude at the same time, this also keeps both histories in one folder.
But the script is enough to start, and the wiki pattern doesn't care how the files got there.
Quick answers
Does Claude Code need an MCP server to work with Obsidian?
No. An Obsidian vault is plain Markdown files on disk, and Claude Code reads and writes files directly. MCP or the Obsidian CLI only add Obsidian-specific operations such as its search index, daily notes and properties.
Is it safe to let Claude Code edit my vault while Obsidian is open?
Yes. Obsidian refreshes when files change on disk. Avoid typing in the same note Claude is editing, and keep the vault in git so every change can be reviewed and reverted.
Where are my chats in the ChatGPT export?
In conversations.json, or conversations-000.json, -001.json and so on in large exports. Each chat is a tree of messages in mapping. Follow parent links up from current_node to get the version you saw.
How is an LLM wiki different from RAG?
RAG retrieves raw chunks for every question. An LLM wiki has the model write and maintain summary pages once, with links back to the sources, so knowledge accumulates and each answer starts from organized pages.
If you build this, share your CLAUDE.md in the comments. The schema is where most of the tuning happens, and it's the part worth comparing.
來源:DEV Community · dev.to
