MC

marciopuga/cog

Developer tools
377 stars Quality 72 Trend 20MIT

One memory for every agent and project: a folder of plain-text files and one short instruction file. There's nothing to install, and no server, database, embeddings or scripts: just markdown and the...

Overview

One memory for every agent and project: a folder of plain-text files and one short instruction file. There's nothing to install, and no server, database, embeddings or scripts: just markdown and the...

README

Cog

One memory for every agent and project: a folder of plain-text files and one short instruction file. There’s nothing to install, and no server, database, embeddings or scripts: just markdown and the file tools your agent already has.

cog-skills installs the /cog command into other agents.

Quick start

git clone https://github.com/marciopuga/cog ~/cog
cd ~/cog
claude            # or any agent that reads AGENTS.md
> /cog            # first run: a few questions, then it creates your folders

From then on, ask about your life and work as you normally would. The agent reads memory before it answers and writes new facts as it learns them. Run /cog at the end of a session to catch anything it missed.

If you cloned somewhere else, set COG_HOME (for example export COG_HOME=~/projects/cog).

Use it from every project

Memory lives in one place, ~/cog/memory/. Keep it there and don’t scaffold memory inside each project.

  • Claude Code, everywhere: add @~/cog/AGENTS.md to ~/.claude/CLAUDE.md, and copy .claude/commands/cog.md to ~/.claude/commands/.
  • Codex, Cursor, Gemini CLI and others: point the agent’s own instruction file at ~/cog/AGENTS.md, and install the /cog command with npx skills add marciopuga/cog-skills.

How it works

At the start of every session the agent reads three small things:

Read What it says
memory/hot-memory.md What’s going on now (at most 25 lines)
memory/patterns.md How you want it to work (at most 40 lines, written by hand)
The top of the map The l0: line of each root file and of each folder’s index.md: one line per file or folder

The map opens one level at a time. When a folder fits the question, the agent reads the l0: lines of that folder’s files and one line per subfolder, and goes down only where a summary fits. A tree of hundreds of files still costs a few dozen lines to navigate, and nothing is generated: each folder’s index.md is one hand-written line. A file over 80 lines gets its headings listed first, then only the section it needs. A name no summary mentions gets one search inside the likely folder.

Time questions need no tool, because every dated line starts with its date:

  • A value on a date: the facts.md line whose from:/until: window covers that date.
  • “Before the trip”: the trip’s dates from events.md, then the observation lines in that window.
  • “Last October”: a search for ^- 2026-10.

That is the whole retrieval model. It works because the agent navigates rather than searches, so the design keeps every file small and every summary honest.

~/cog/
  AGENTS.md              the instructions (CLAUDE.md just imports it)
  memory/
    hot-memory.md        read every session
    patterns.md          read every session
    facts.md             values that change over time
    events.md            named dated anchors: trips, launches, appointments
    personal/            a folder per area of life or work
      index.md           one l0: line saying what the folder holds
      observations.md
      action-items.md
      entities.md
      kitchen-renovation.md    topic files, as they appear
      glacier/           archives
    work/
      ...

A folder is a domain, and nothing else acts as a manifest.

Line formats

Every file starts with a one-key frontmatter (l0:, a one-line summary), then a comment that states its line format. The rule travels with the file, so any agent, or you in an editor, can follow it without loading anything else.

---
l0: Who's who at home: family, friends, the people who help
---

File Line Edit
observations.md - 2026-11-20 [tag, tag]: text [[folder/file]], optionally about:2026-11-18 after the tags (when it happened, not when it was written) Append only
action-items.md - [ ] task | due:2026-12-01 | pri:high | added:2026-11-20 Append; tick when done
entities.md ### Name (relationship), then 1-3 lines Edit in place
facts.md - key: value | from:2026-11-08 | until: | src:[[folder/file]] | kind:health Fill until: on the old line, append the new one
events.md - beach-trip | 2026-09-30..2026-10-06 | note | aka: Beach, the trip Append; edit in place
hot-memory.md - **topic** — state [[folder/file]] Rewrite freely
topic file ## Current State (rewritten), then ## Timeline (- 2026-11-20: ..., appended) As shown

The four rules:

  • Absolute dates only.
  • Each fact lives in one place and is linked from elsewhere.
  • Links point to whole files ([[folder/file]]), because section links break when headings change.
  • A correction rewrites the wrong line rather than adding a contradicting one.

Staying small

There’s no cleanup job. The agent keeps files within their limits whenever it writes to them:

  • Observations: once a file passes 50 entries, the oldest move into glacier/observations-.md until 40 remain.
  • Action items: once more than 10 are ticked, they move to glacier/action-items-done.md.
  • Expired lines: a line in hot-memory.md or action-items.md whose until: date has passed is ignored when read and moved to glacier/expired.md at the next edit.

/cog is the only command. Run it at the end of a session.

  • It writes what the conversation added: a dated observation, a changed fact, a new event, an action item.
  • It updates hot memory only where a fact changed, and does the upkeep above.
  • It proposes a topic file when one subject has come up three times.

On first run it sets up folders from a few questions instead, and when it finds a Cog v1 folder it offers to convert it.

Try it on the example

examples/memory/ is a made-up person across two folders: about 35 files, archives, expired lines and a fact history. Point COG_HOME at a copy of it and ask questions.

Evaluation

Twenty questions about the example person (eval/questions.json, answer key included). Each was asked in a fresh headless Claude Code session (Sonnet, claude -p) against two copies of the same memory.

  • Cog v1: the old layout and instructions (`` comments, domains.yml, per-folder hot memory and INDEX.md, threads/, calendar.md, values kept as History lines).
  • Cog v2: this repo.

Both copies hold the same facts. eval/run.py is a development tool, not part of Cog: it rebuilds both copies and reruns everything. Per-question answers and tool calls are in eval/results-*.jsonl.

Cog v1 Cog v2
Correct 20/20 20/20
Tool calls, total 42 34
Input tokens per question (incl. cache) 61.5k 49.2k
Cost for all 20 $1.07 $0.88
Question type v1 tool calls v2 tool calls v1 tokens v2 tokens
Who (4) 8 9 59k 60k
What’s due (4) 9 6 64k 45k
Value on a date (4) 10 5 71k 40k
Before / during / after an event (4) 7 7 54k 51k
Current state of a topic (3) 6 5 59k 49k
Archived history (1) 2 2 59k 54k

Both versions answered everything correctly. The example memory is small enough that v1 finds every answer too, so accuracy here only shows that v2 loses nothing. The difference is in the work. v2 reached the same answers with fewer reads and about 20% fewer input tokens, mostly on questions about a value on a date, where one facts.md line replaces searching through History sections. Each question ran once, so expect a few calls of noise either way. The v2 run used the example with its home topics grouped into a personal/home/ subfolder, so the map is navigated across two levels.

During development, v2 briefly shipped a helper script for archiving and date queries. It used 32 tool calls and 47.1k tokens per question on the same questions (eval/results-v2-script.jsonl). That was a little cheaper, but it cost a Python dependency, and the prompt-only version keeps the accuracy.

What was left out, and why

Earlier versions of Cog shipped about 1,700 lines of prompts. They included weekly housekeeping and reflection passes, a backlink index, self-observation logs, foresight and scenario skills, a domain manifest with keyword triggers, and a hot-memory file per folder. v2 keeps about 130 lines of prompt text and nothing else.

The rule behind the cut: a routine has to change files. One that writes a report for another routine to read doesn’t make the cut.

  • Backlink index: searching for [[folder/file gives backlinks on demand.
  • Generated indexes: each file’s l0: line is its index entry, and each folder’s index.md is one hand-written line.
  • Self-observations, run logs, foresight, scenarios: you can just ask the agent. When the same correction comes up twice, write it in patterns.md.
  • Automated pattern promotion and weekly reflection: /cog works from the conversation, which is where new facts actually come from.
  • Domain manifest and keyword triggers: an agent reading one-line summaries routes just as well.
  • Per-folder hot memory, rich frontmatter, last_updated: one hot memory is enough, and a file’s modification time doesn’t go stale.
  • from:, grace: and muted: markers: from: lives in facts.md, and instead of grace: you set a later until:.

Upgrading from Cog v1

Run /cog. When it finds a v1 folder it offers to convert it:

  • `` comments become l0: frontmatter.
  • Each domains.yml label becomes the l0: of that folder’s index.md.
  • calendar.md becomes events.md.
  • cog-meta/patterns.md becomes patterns.md.
  • domains.yml, link-index.md, the INDEX.md files and the rest of cog-meta/ move to glacier/legacy/.

Use with Obsidian

memory/ is a valid Obsidian vault. l0: shows as a property, wiki-links resolve, and edits you make by hand are picked up next session.

Credits

OpenViking (L0 summaries and tiered loading) | Zettelkasten (topic files) | SSOT (one fact, one place)

License

MIT

View the full README on GitHub

Recommended Tools

Try a different keyword or remove a filter.

Install

npx skillfish add marciopuga/cog
New to MCP? Start with the mcpskill.org guide →