How to Build a Portable AI Second Brain That Works Across Claude, Codex, and Hermes A developer has created a portable AI second brain system using plain markdown files and folders that works across Claude, Codex, and Hermes, allowing users to avoid vendor lock-in and maintain context when switching AI tools. The system includes a flat folder structure with an index file, three memory types (episodic, semantic, procedural), and routing rules tailored to each agent's context injection method. How to Build a Portable AI Second Brain That Works Across Claude, Codex, and Hermes Build your AI second brain as markdown files and folders so any agent harness can read it. Learn the routing rules, folder structure, and memory patterns. Why Your AI Context Shouldn’t Be Trapped in One Tool Every time you switch between Claude, OpenAI’s Codex, and a local model like Hermes, you start from zero. You re-explain your project. You re-paste your preferences. You remind the agent what you already decided last week. That’s not a second brain — that’s a leaky notebook. The concept of a portable AI second brain flips this. Instead of storing context inside a specific tool or a proprietary memory system, you keep everything as plain markdown files in a structured folder. Any agent harness — Claude’s Projects, OpenAI Codex, a local Ollama instance running Hermes — can read those files directly. Your context travels with you. This guide covers exactly how to build that system: the folder layout, the memory patterns, the routing rules that tell each agent where to look, and how to keep it from turning into a mess. What Makes a Second Brain “Portable” The word “portable” does real work here. Most AI memory systems fail portability in one of two ways: - Vendor lock-in : Your memory lives inside a proprietary system — ChatGPT’s memory, Notion AI’s context, a RAG database tied to one platform. When you switch tools, the memory doesn’t come. - Format lock-in : Your notes live in a format only one tool can parse — a custom JSON schema, a database, a binary blob. Plain text is universally readable. Everyone else built a construction worker. We built the contractor. One file at a time. UI, API, database, deploy. A portable second brain uses plain markdown files as the storage layer. Markdown is human-readable, version-controllable with Git, and ingestible by virtually every AI system. You’re not building for one agent — you’re building an interface that any agent can consume. The three agents this guide focuses on — Claude via Anthropic’s API or Projects , Codex OpenAI’s code-oriented model , and Hermes NousResearch’s instruction-tuned model, typically run locally via Ollama or LM Studio — all handle context injection differently. The routing rules below account for those differences. The Core Folder Structure Keep the structure shallow and explicit. Deep nesting creates routing confusion. Here’s a working layout: /second-brain/ ├── index.md ├── /memory/ │ ├── episodic.md │ ├── semantic.md │ └── procedural.md ├── /projects/ │ ├── project-a.md │ └── project-b.md ├── /context/ │ ├── preferences.md │ ├── constraints.md │ └── glossary.md ├── /routing/ │ ├── claude-rules.md │ ├── codex-rules.md │ └── hermes-rules.md └── /log/ └── YYYY-MM-DD.md index.md — The Entry Point This is the file every agent reads first. It’s a short document under 300 words that explains the structure and points to relevant files based on task type. Think of it as a table of contents plus a routing guide. Example content: Second Brain Index What this is This is a persistent context system for AI agents. Read this file first, then follow the routing rules for your task type. Quick routing - For coding tasks → read /memory/procedural.md + /routing/codex-rules.md - For writing/analysis → read /memory/semantic.md + /context/preferences.md - For project-specific work → read the relevant file in /projects/ - For any task → read /context/constraints.md Active projects - Project A: project-a.md - Project B: project-b.md Last updated 2025-07-01 Why a Flat-ish Structure Works Better Deeply nested folders require agents to infer paths. A flat structure with explicit links reduces guesswork. When an agent reads index.md , it knows exactly which file to pull next based on the task at hand — no inference required. The Three Memory Types and How to Use Each This is the most important design decision in your second brain. Different information has different update frequencies and different retrieval patterns. Mixing them into one big notes file is what makes memory systems break down over time. Episodic Memory — What Happened episodic.md holds time-stamped records of decisions, conversations, and outcomes. This is the equivalent of a lab notebook. Structure each entry like this: 2025-06-28 Context : Discussing API rate limiting strategy for Project A Decision : Use exponential backoff with max 3 retries Reasoning : Simpler than a queue system; acceptable for current traffic Status : Implemented Episodic memory is append-only. Never edit past entries — only add new ones. This keeps the record honest and gives agents a clear timeline. Semantic Memory — What You Know semantic.md is your knowledge base: concepts, frameworks, mental models, domain-specific facts that apply broadly. Update this when your understanding of something changes. Rate limiting Exponential backoff is preferred for third-party API calls. Token bucket is better for internal services with predictable load. Never use fixed-delay retries in production. My writing style Prefer short paragraphs. Active voice. No em-dashes for sentence connectors. Use bullet points for 3+ items. This file tends to be the most valuable for creative and writing tasks. It’s also the file that ages best — a decision from six months ago might be outdated, but a mental model you’ve refined is still valid. Procedural Memory — How You Work procedural.md holds your repeatable processes: code patterns, deployment checklists, standard operating procedures, templates you use frequently. Code review checklist 1. Does this function do one thing? 2. Are errors handled explicitly? 3. Is the return type predictable? 4. Are there edge cases not covered by tests? Deployment process for Project A 1. Run test suite locally 2. Push to staging branch 3. Confirm CI passes 4. Tag release 5. Merge to main Codex, in particular, benefits from procedural memory. When you’re asking it to write code, having your patterns and conventions injected upfront produces far better results than starting cold. Routing Rules for Each Agent This is where the system actually becomes multi-agent capable. Each routing file tells a specific agent how to interact with the second brain — what to read, what to update, and what to ignore. Claude Routing Rules Claude handles long context well and can synthesize information across multiple files. Your claude-rules.md should tell it to read broadly before responding. Claude Routing Rules On task start 1. Read index.md 2. Identify task type 3. Load relevant memory files episodic + semantic for analysis; procedural for structured tasks 4. Load project file if task is project-specific 5. Load constraints.md always On task end If a significant decision was made: - Append to episodic.md with today's date - Update semantic.md if a mental model changed - Flag any updates needed in procedural.md do not edit directly Context window management If context is getting large, prioritize: constraints.md active project file semantic.md episodic.md recent only Codex Routing Rules Codex is optimized for code generation and works best with precise, structured context. Keep its routing instructions lean and code-focused. Codex Routing Rules On task start 1. Read constraints.md 2. Read procedural.md full 3. Read active project file — code section only 4. Do NOT load episodic.md unless asked Code generation defaults - Follow patterns in procedural.md - Match naming conventions in glossary.md - Flag any deviation from established patterns with a comment On task end - If a new pattern is established, output it formatted for procedural.md - Do not write to memory files directly The “do not write directly” rule matters. Codex is good at code but can produce inconsistent prose. Have it output proposed memory updates in a structured format, then review and paste them yourself — or automate that review step. Hermes Routing Rules Hermes running locally via Ollama or LM Studio typically has a smaller context window than Claude and may run on hardware with memory constraints. Its routing rules should be more conservative about file loading. Hermes Routing Rules On task start 1. Read index.md 2. Load ONLY the single most relevant memory file based on task type 3. Load constraints.md always, it's short 4. Do not attempt to load multiple large files simultaneously Context priority order constraints.md procedural.md semantic.md episodic.md last 30 days only Memory window If total context exceeds 4,000 tokens, truncate episodic.md to most recent 5 entries only. On task end Output proposed updates as a structured list. Do not update files directly. Other agents start typing. Remy starts asking. Scoping, trade-offs, edge cases — the real work. Before a line of code. Local models are getting more capable, but being explicit about their limits prevents silent failures where the model simply ignores files it can’t process. Building the Daily Log Pattern The /log/ folder is optional but genuinely useful. Each day gets a new file named YYYY-MM-DD.md . At the end of a session, you or an automated script summarize what happened, what changed, and what’s pending. A simple template: Session Log — 2025-07-01 What I worked on - Refactored authentication module in Project A - Reviewed rate limiting approach Decisions made - Switched to token bucket for internal auth service - Deferred database migration to next sprint Memory updates needed - Update procedural.md: add token bucket pattern - Update episodic.md: record auth refactor decision Open questions - Should error logs go to Datadog or a custom endpoint? This daily log becomes the input for keeping your other memory files fresh. Without a log, memory files drift — you stop updating them because you forget what changed. How to Inject Context Into Each Agent Having the files is only half the problem. You also need a reliable way to get the right files into each agent’s context at the start of a session. Claude Projects Claude’s Projects feature lets you upload files that persist across conversations. Upload your /context/ folder and the relevant /memory/ files as project knowledge. Add index.md and claude-rules.md as the system prompt or first user message. For project-specific work, add the relevant project file to the session manually. You don’t want all project files loaded at once — only the active one. OpenAI Codex via API or CLI Codex is typically invoked programmatically. Use a simple shell script or Python wrapper that prepends the routing files to every request: php def build codex context task: str, project: str = None - str: context files = "constraints.md", "procedural.md", "routing/codex-rules.md" if project: context files.append f"projects/{project}.md" context = "" for f in context files: with open f"second-brain/{f}" as fp: context += fp.read + "\n\n---\n\n" return context + task This gives you consistent context injection without manual copy-pasting. Local Models Hermes via Ollama With Ollama, you can use the --system flag or build a Modelfile that injects your routing instructions as a persistent system prompt. For dynamic context, use the API directly: curl http://localhost:11434/api/generate -d '{ "model": "hermes3", "system": "