Practical Guides · knowledge base from X

Context engineering, "LLM OS" and system prompt learning — why a second brain is the right context for AI

The theory behind second brains for AI. Karpathy (with Tobi Lütke) prefers "context engineering" to "prompt engineering": filling the context window with just the right information for the next step. He links it to the vision of the LLM as the kernel of a new operating system (2023) and to "system prompt learning" (2025): the LLM writing a book for itself on how to solve problems. With Anthropic's guidance on compaction, structured notes and sub-agents.

✍️ Andrej Karpathy · @karpathy
🔗 Read the original on X · X Thread · published 25 Jun 2025
📊 14,322 likes · 9,197 bookmarks · 2.4M views
Summary and adaptation in English; content and results belong to the author.

Part of the manual Second Brain — the complete manual (from the PARA method to the wiki the AI writes for you)

Claimed result

  • 25 June 2025, Karpathy: "+1 for context engineering over prompt engineering" — 14,322 likes, 9,197 bookmarks, 2.4M views. He reposts Tobi Lütke (Shopify's CEO): the term "describes the core skill better: the art of providing all the context for the task to be plausibly solvable by the LLM" (8,566 likes, 2,389 bookmarks, 2.1M views, post).
  • LLM OS (28 September and 11 November 2023): the LLM not as a chatbot but as the kernel process of a new operating system that orchestrates multimodal input/output, a code interpreter, a browser and an embeddings database for files and internal memory (9,089 likes, post); in the "LLM OS" diagram RAM is the context window (128K tokens at the time) and the file system is embedding memory (10,121 likes, 2.5M views, post). In 2026 he sums it up: "LLM = CPU; agent = operating system kernel" (reply).
  • System prompt learning (11 May 2025): a missing paradigm for LLM learning (10,297 likes, 7,669 bookmarks, 1.5M views, post).

Proof: framework. Concepts and definitions, not results. They are, however, the vocabulary every other source in this theme uses.

The key idea

A second brain for AI is context engineering for your life or your company: a place the agent pulls "just the right information" from at every step.

Karpathy: in industrial-strength LLM apps, context engineering is "the delicate art and science of filling the context window with just the right information for the next step". Science because it involves task descriptions and explanations, few-shot examples, RAG, related (possibly multimodal) data, tools, state and history, compacting. Too little or of the wrong form and the LLM does not have the right context for optimal performance; too much or too irrelevant and costs go up while performance comes down. Art because it takes intuition about the "psychology" of models.

And system prompt learning: "Pretraining is for knowledge. Finetuning (SL/RL) is for habitual behavior," but a lot of human learning feels more like a change in system prompt: you hit a problem, figure something out and "remember" it in explicit terms for next time. LLMs "are quite literally like the guy in Memento, except we haven't given them their scratchpad yet". Claude's system prompt at the time was around 17,000 words, full of hand-written problem-solving strategies; Karpathy argues they should come from a process where the LLM writes a book for itself on how to solve problems. That is exactly what skills, MEMORY.md files and agent-curated wikis do today.

Step-by-step playbook

1. What goes into the context (Karpathy's list)

  1. Task description and explanations.
  2. Examples (few-shot).
  3. Retrieved documents (RAG or file reads).
  4. Related data, including images.
  5. Available tools.
  6. State and history.
  7. Compaction of what no longer needs to be there in full.

Beyond context, an LLM app has to: break problems into the right control flows, pack context windows just right, dispatch calls to models of the right kind and capability, handle generation-verification flows, plus guardrails, security, evals, parallelism, prefetching. "The term 'ChatGPT wrapper' is tired and really, really wrong."

2. Anthropic's practical rules (September 2025)

From Anthropic's engineering post "Effective context engineering for AI agents" (source): - "Context rot": the more tokens in the window, the less precisely the model recalls. Context is a finite resource with diminishing returns, an "attention budget". - Guiding principle: the smallest possible set of high-signal tokens that maximises the desired outcome. - System prompts "at the right altitude": neither brittle hand-coded if-else logic nor vague guidance that assumes shared context; distinct sections (XML or markdown headers). - "Just in time" retrieval: keep lightweight identifiers (file paths, stored queries, links) and load data at runtime with tools, instead of loading everything upfront. - For long tasks: compaction (summarise the conversation near the limit), structured notes outside the context (the agent writes notes it re-reads after a reset: Anthropic released a file-based memory tool in beta with Sonnet 4.5), sub-agents that explore with tens of thousands of tokens and return a 1,000–2,000-token summary.

3. Translating it into a second brain

  • index.md and one-line summaries = lightweight identifiers for just-in-time retrieval.
  • Compiled wiki pages = high-signal context instead of raw documents.
  • Rule files (MEMORY.md, skills) = system prompt learning, done by hand or by the agent.
  • Periodic lint = fighting the knowledge base's own context rot.

Tools and costs

Tool-independent concepts. Implementations mentioned: Claude's (file-based) memory tool, sub-agents, the automatic compaction in terminal agents.

Limitations

  • These are definitions and principles; they do not say which folder structure to use.
  • The 2023 "LLM OS" vision cited an embeddings database as memory: 2026 sources (Karpathy included) show that at small scale files and indexes are enough.
  • Automatic system prompt learning remains an open idea: "how do the edits work? can/should you learn the edit system?" are questions Karpathy leaves open.
← More guides in “Second Brain — knowledge bases that AIs can read too”