agentleFS
fbsmna-coderfbsmna-coder/karpathy-pro-max/skills/memory-hygiene/SKILL.md

memory-hygiene

Skill0 starsChanged 8 months agoMITView on GitHub

Maintain persistent memory files (CLAUDE.md, MEMORY.md, rules indexes) so they actually load and stay useful. Use when adding, editing, or auditing memory entries — to prevent silent truncation, orphan files, and split sections.

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If "Feedback" appears at line 50 and again at line 220, half is loaded and half is silently lost.

    line 31
  2. Distinctive:

    Run this whenever you add a memory file.

    line 44
  3. Distinctive:

    When you add a new memory entry, check the line number of the new entry vs.

    line 48
  4. Distinctive:

    When the index approaches the load window, do NOT just keep appending.

    line 57
  5. Distinctive:

    Run periodically (monthly, or whenever the file feels bloated):

    line 71

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Memory Hygiene

Persistent memory only works if it gets loaded. Most memory systems have a load window (line limit, token limit, or context budget). Entries past the window exist on disk but never reach the model. They become silent dead weight: the user thinks the rule is in effect, the agent never sees it.

This skill is for any project that uses Claude Code's MEMORY.md, CLAUDE.md, or a similar rules index.

The rules

1. Know your load window

Find the limit. For Claude Code's auto-memory: first 200 lines of MEMORY.md. Past that, truncated. Other tools have token limits or section limits — find yours and write it at the top of the file.

2. Keep index entries one line, ≤150 characters

Index files are indexes, not content. Each entry: title, link, one-line hook.

- [Topic title](path/to/topic.md) — one-line hook

Long entries push later entries past the truncation line. Detail goes in the linked file, never in the index.

3. One section per topic, never split

If "Feedback" appears at line 50 and again at line 220, half is loaded and half is silently lost. Audit periodically: grep -n '^## ' MEMORY.md to see all section headers.

4. Detect orphans regularly

Files that exist on disk but are not referenced from the index are dead. They will never be loaded.

cd memory/
for f in feedback_*.md; do
  grep -q "$f" MEMORY.md || echo "ORPHAN: $f"
done

Run this whenever you add a memory file. If anything prints, fix it (add to index or delete the file).

5. Verify load on add

When you add a new memory entry, check the line number of the new entry vs. the load window. If you put it at line 250 and the window is 200, it does not work. Move it up.

grep -n "feedback_new_thing.md" MEMORY.md
# If line number > load window, move it.

6. Compress before adding

When the index approaches the load window, do NOT just keep appending. Audit:

  • Are any entries duplicated across sections?
  • Are any verbose entries that could become one-liners?
  • Are any obsolete (project killed, decision reversed, lesson superseded)?
  • Are any project-specific deep details that belong in their topic file, not the index?

Compress first. Add second.

7. Backup before restructure

Any large rewrite of a memory index: copy to MEMORY.md.backup-YYYY-MM-DD first. Restructures lose information surprisingly often. Backup is cheap insurance.

Audit checklist

Run periodically (monthly, or whenever the file feels bloated):

1. Total lines vs. load window?         (target: ≤ window − 5 line safety margin)
2. Orphan files?                        (target: 0)
3. Sections appearing twice?            (target: 0)
4. Entries >150 chars?                  (target: refactor each)
5. Entries past load window?            (target: 0)
6. Backup exists from last restructure? (target: yes)

Why this is in Karpathy Pro Max

Memory hygiene is invisible until it fails. The user adds a feedback rule, sees it on disk, assumes it works. Six months later they wonder why the agent keeps making the same mistake. The rule was real, the file existed, but it never loaded — buried past line 240 of a 360-line index.

Most rule systems die this way. This skill prevents it.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.