codex-brain
Skill1 starsChanged 4 months agoMITView on GitHub
Manages long-term AI memory, overcomes context-window limits, snapshots chat session decisions, restores context into fresh sessions, supports high-density token-saving modes, and maintains living repository knowledge in codex-drive/brains/.
In this repository24 other files it gives its agents.
- codex-architectureSkill
- ai-codex-c-cppSkill
- ai-codex-csharp-dotnetSkill
- codex-debugSkill
- codex-deepSkill
- codex-elixirSkill
- codex-flutter-dartSkill
- codex-goalSkill
- ai-codex-goSkill
- ai-codex-java-kotlinSkill
- ai-codex-phpSkill
- codex-plansSkill
- ai-codex-pythonSkill
- codex-reviewSkill
- ai-codex-rustSkill
- codex-skillsSkill
- codex-solidity-web3Skill
- codex-sql-databaseSkill
- codex-startSkill
- ai-codex-swiftSkill
- codex-testSkill
- ai-codex-typescript-reactSkill
- ai-codex-ui-ux-designSkill
- codex-zigSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 32
When context window usage is high and important decisions must be saved before starting a new chat.
- Very specific: line 68
Write timestamped checkpoint file to: codex-drive/brains/YYYY-MM-DD-session-<slug>.brain.md
- Very specific: line 78
When dense mode is active (ideal for smaller context models like Claude 3.5 Haiku, Gemini Flash, or local Ollama):
- Very specific: line 84
Read all historical YYYY-MM-DD-session-*.brain.md files in codex-drive/brains/.
- Distinctive: line 98
When generating a session snapshot, follow the High-Density Signal Rule:
- Very specific: line 107
All memory files generated by codex-brain MUST be Markdown (.md) files with exact date-time metadata.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Codex Brain — Persistent AI Memory & Context Management Skill
The external long-term memory engine of AI Codex. Solves context window limits, prevents conversational amnesia, snapshots critical engineering decisions, and enables high-density token compression.
Overview
AI models have finite context windows. In long-running projects, conversation history degrades, tokens run out, and critical decisions made yesterday are forgotten in a new chat today.
codex-brain provides externalized, persistent memory for AI sessions. It captures high-signal decision summaries, tracks uncompleted work, records environment gotchas, and stores compact memory checkpoints inside codex-drive/brains/. Any fresh chat session can read a brain checkpoint in < 1,000 tokens to instantly achieve 100% awareness of past engineering work.
When to Trigger
- User runs
/codex-brainor its subcommands:/codex-brain save [optional-topic]— Snapshot current session memory before closing or when context is getting full./codex-brain load [optional-topic|latest]— Restore memory into a fresh chat session./codex-brain dense [on|off]— Toggle high-density "Caveman" token compression mode (saves up to 70% of tokens)./codex-brain compact— Consolidate multiple session snapshots into the master knowledge base./codex-brain index— Scan repository conventions, architecture rules, and domain glossary.
- Starting a new chat session on an ongoing project (automatic context resumption via
/codex-start). - When context window usage is high and important decisions must be saved before starting a new chat.
Memory Hierarchy
┌────────────────────────────────────────────────────────┐
│ 1. WORKING MEMORY (Active State & Immediate Tasks) │
│ What was just done, what is blocked, what is next. │
├────────────────────────────────────────────────────────┤
│ 2. EPISODIC MEMORY (Session Snapshots & Decisions) │
│ Why architectural option A was chosen over B. │
├────────────────────────────────────────────────────────┤
│ 3. SEMANTIC MEMORY (Consolidated Knowledge Base) │
│ Project conventions, domain glossary, quirks. │
└──────────────────────────┬─────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────┐
│ HIGH-DENSITY TOKEN COMPRESSION ENGINE ("Caveman") │
│ Strips conversational fluff, keeps 100% exact code. │
└────────────────────────────────────────────────────────┘Sub-Commands & Workflows
1. Snapshot Session Memory: /codex-brain save [topic]
- Analyze the current conversation history.
- Extract:
- Core Objectives: What problem was addressed in this session.
- Decisions Made & Alternatives Rejected: Concrete rationale for architectural choices.
- Completed Tasks vs. Next Immediate Tasks: Exact continuation point for the next session.
- Gotchas & Quirks Learned: Discovered edge cases, environment settings, API peculiarities.
- Write timestamped checkpoint file to:
codex-drive/brains/YYYY-MM-DD-session-<slug>.brain.md
2. Restore Memory Context: /codex-brain load [topic|latest]
- Locate the latest or requested
.brain.mdfile incodex-drive/brains/. - Parse the summary, active state, decisions, and remaining tasks.
- Output a concise resumption brief to the user:
"Context Restored from [YYYY-MM-DD-session-
<slug>.brain.md]. Last worked on: [Objective]. Next task on deck: [Next Task]. Ready to proceed."
3. High-Density Token Mode: /codex-brain dense [on|off]
When dense mode is active (ideal for smaller context models like Claude 3.5 Haiku, Gemini Flash, or local Ollama):
- Strip Fluff: Eliminate all polite conversational padding, preambles, and repetitive disclaimers.
- Byte-Exact Code: Preserve exact code blocks, diffs, shell commands, and file paths without modification.
- Telegraphic Precision: Format reasoning as concise bullet points. Reduces token consumption by up to 70%.
4. Consolidate Memory: /codex-brain compact
- Read all historical
YYYY-MM-DD-session-*.brain.mdfiles incodex-drive/brains/. - Extract recurring rules, finalized decisions, and permanent patterns.
- Merge and update
codex-drive/brains/knowledge-base.brain.md. - Archive or prune redundant intermediate session files to prevent memory sprawl.
5. Repository Context Indexing: /codex-brain index
- Scan workspace root, folder topology, package manifests, and configuration files.
- Catalog ubiquitous domain terms, models, schemas, and coding conventions.
- Update
codex-drive/brains/knowledge-base.brain.md.
Context Compression Protocol
When generating a session snapshot, follow the High-Density Signal Rule:
- Discard: Conversational pleasantries, intermediate tool call logs, repetitive code dumps, syntax trial-and-error.
- Preserve: Final decisions, rejected alternatives with reasons, file paths created/modified, failing tests that need fixing, exact continuation instructions.
- Target Density: Compress 40,000+ tokens of verbose conversation into ~600 to 1,000 tokens of structured markdown.
Memory File Specification (codex-drive/brains/)
All memory files generated by codex-brain MUST be Markdown (.md) files with exact date-time metadata.
Filename Formats:
- Session Snapshot:
codex-drive/brains/YYYY-MM-DD-session-<slug>.brain.md - Master Knowledge Base:
codex-drive/brains/knowledge-base.brain.md
Standard Session Memory Template:
# [Session / Feature Name] Memory Checkpoint
> **Created At**: YYYY-MM-DD HH:MM:SS (Local Time)
> **Active Codex Edition**: [`skills/codex/<edition>/`](file:///...)
> **Memory Type**: SESSION_SNAPSHOT
> **Compression Ratio**: [e.g., ~42,000 tokens compressed into ~650 tokens]
> **Status**: READY_FOR_RESUMPTION | ARCHIVED
---
## 1. Session Objective & Scope
[Concise summary of what was tackled in this session]
## 2. Key Decisions & Rationale
- **Decision 1**: Chose PostgreSQL row-level locking (`FOR UPDATE`) instead of Redis distributed lock because the cluster is single-region and DB transaction atomicity is required.
- **Decision 2**: Rejected library X due to lack of Swift 6 strict concurrency / Sendable support.
## 3. Work Completed in This Session
- [x] Implemented domain aggregate `Order` in `src/domain/order.ts`
- [x] Added database migration `004_create_orders.sql`
- [x] Wrote unit test suite with 100% invariant coverage
## 4. Active Continuation Point (Next Session Resumes Here)
- [ ] Implement HTTP controller in `src/api/order-controller.ts`
- [ ] Wire dependency injection container in `src/server.ts`
- [ ] Run integration tests with Testcontainers (`npm run test:integration`)
## 5. Critical Gotchas & Environment Quirks Learned
- [WARNING] Webhook payload timestamps are emitted in milliseconds UTC, not seconds.
- [WARNING] Database pool max connections must not exceed 20 to avoid exhausting AWS RDS limits.
- [WARNING] Ensure `CancellationToken` is propagated in all async database queries.Response Protocol
When codex-brain save completes:
- Provide a direct link to
[View Brain Memory Checkpoint](file:///.../codex-drive/brains/YYYY-MM-DD-session-<slug>.brain.md). - Display a compact 3-bullet resumption summary (What was done, What decisions were locked in, What is next).
- Inform the user: "You can start a fresh chat anytime and run
/codex-brain loador/codex-startto instantly resume with full context."
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

