prime-context
Skill1 starsChanged 4 months agoMITView on GitHub
Self-learning project context with a thin AGENTS.md router. Called with no argument it LEARNS — captures this session's corrections, decisions and pitfalls into .claude/context/<area>.md files. With an area name it loads that area's context on demand. Also refactors bloated AGENTS.md/CLAUDE.md into the thin architecture, bootstraps new projects, and audits the structure for drift. Commands: learn (default), <area> (load), improve, setup, doctor.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- pablof7z/skillstheir own version, first seen Jul 13, 2026
- HermeticOrmus/prime-context-skillstheir own version, first seen May 25, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- pablof7z/skills★ 1same name
- HermeticOrmus/prime-context-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 9 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 74
Never touch AGENTS.md itself (rules there are managed via improve).
- Very specific: line 83
Read ~/.claude/projects/<hash>/memory/MEMORY.md if it exists.
- Distinctive: line 90
If the task at hand clearly touches several areas, read the relevant files in parallel.
- Distinctive: line 120
Read the entire AGENTS.md (or CLAUDE.md) at the CWD.
- Very specific: line 124
Ensure CLAUDE.md points at AGENTS.md (see symlink/fallback rules in setup).
- Distinctive: line 164
Keep total imperative instructions in AGENTS.md well under 150 — merge similar rules, push details into context files.
- Distinctive: line 169
Never invent content — only reorganize what already exists in the original file.
- Very specific: line 172
Idempotent re-runs: if .claude/context/ already has files, merge new content into the matching area file section by section — never …
- Distinctive: line 187
Use the CWD as project root (ask if ambiguous).
- Distinctive: line 188
Ask: "Describe the project in 1-2 lines (what it does, stack, for whom)."
- Distinctive: line 189
Ask: "What are the main work areas?
- Very specific: line 191
Create .claude/context/<area>.md for each area with the header # Context: <Area> and a <!-- Fill in as the project evolves --> comment.
- Distinctive: line 193
Create AGENTS.md from the thin template (routing table pointing at the created areas).
- Very specific: line 199
Create ~/.claude/projects/<hash>/memory/MEMORY.md containing the format spec header:
- Very specific: line 206
If AGENTS.md already exists → offer improve instead of overwriting.
- Very specific: line 207
If CLAUDE.md is already a symlink or an @AGENTS.md import → leave it alone.
- Distinctive: line 208
If CLAUDE.md is a regular file with real content → ask before replacing.
- Very specific: line 240
Never modify context files during load — read only.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
Prime Context
Manage project context efficiently — never load everything at once.
Core philosophy
AGENTS.md must be thin. It is loaded in EVERY session — every line costs tokens in every conversation.
Detailed content lives in .claude/context/<area>.md and is read only when the task requires it.
AGENTS.md contains only: overview (2 lines), routing table, non-negotiable rules, PR checklist.
This skill covers both directions: <area> is the read path (assemble the right
context into a session); the bare call is the write path (learn — persist this
session's learnings into those same files, so the next session starts smarter).
MEMORY.md format (specification)
MEMORY.md lives at ~/.claude/projects/<hash>/memory/MEMORY.md, where <hash> is the
project's absolute path with every / replaced by - (Claude Code's project-folder convention,
e.g. /home/dev/app → -home-dev-app). It is a pointer index only — one line per memory
file, never inline content:
- [Short title](filename.md) — one-line hook describing when this mattersEach referenced memory file is self-contained Markdown, optionally with frontmatter
(name, description, type: user|feedback|project|reference). Rules:
- MEMORY.md never holds memory content, only pointers — keeps the index cheap to scan.
- Dead pointers (file missing) are flagged by
doctorand duringload. - Memory files are point-in-time — warn when the newest is older than 7 days.
Command: learn (default — no argument, or the literal word learn)
Capture what this session taught into the context files. Claude Code already loads AGENTS.md/CLAUDE.md at session start — re-reading it adds nothing. The bare call's job is the opposite direction: write the session's learnings down so the next session starts smarter.
Flow:
- Review the current conversation for durable learnings: user corrections, decisions made, pitfalls hit, commands/configs discovered, gotchas that cost time. Ignore anything only relevant to this one task.
- Route each learning:
- Area-specific → append to the matching
.claude/context/<area>.md(fuzzy-match as inload). No matching area → propose creating one (file + routing-table row). - User preference → a file in
~/.claude/projects/<hash>/memory/plus a pointer line inMEMORY.md(create the directory and the MEMORY.md spec header if absent).
- Area-specific → append to the matching
- Check for contradicted memories, not just new ones. For every memory file touched
by this session's topic (same file, or linked via
[[name]]from one that is), check whether a specific claim it makes — a host, path, account owner, version, "current state of X" — is contradicted by evidence seen this session (a file read, a command result, a user statement). A contradicted claim is not an append target: rewrite the memory (current facts first, superseded history below, old claim struck through or moved to a clearly marked "historical" section) rather than tacking an "update" paragraph onto unchanged prose. If the whole file's premise died (e.g. the resource it describes no longer exists or isn't the user's anymore), delete the file and its MEMORY.md pointer line instead of leaving a corpse — don't invent this without evidence: only rewrite/delete what this session actually contradicted, leave everything else untouched. - For learnings that don't contradict anything, check the target file — skip anything already recorded; update in place if the learning supersedes an existing line.
- Report one bullet per learning written or memory rewritten/deleted, with its
destination file. Nothing durable in the session → say
learn: nothing newand stop. Never touch AGENTS.md itself (rules there are managed viaimprove).
Command: load (an area name as argument)
Load one area's context on demand.
Flow:
- Read
~/.claude/projects/<hash>/memory/MEMORY.mdif it exists; then read every file it lists. Skip silently if there is no memory directory — memory is optional. - Resolve the area argument:
- Exact filename match on
.claude/context/<area>.mdwins. - Otherwise case-insensitive substring match against files in
.claude/context/(e.g.filamentmatchesphp-filament.md). - Zero or multiple matches → list the available areas and ask which one.
- Exact filename match on
- If the task at hand clearly touches several areas, read the relevant files in parallel.
Output format:
## Context loaded — <area>
### Relevant now
<3-5 critical points for this session>
### Known pitfalls
<Applicable learnings from memory>
### Quick reference
<Most-used commands or configs>
### Verification
<Files actually read, one per line, with approximate size — so drift is visible>The Verification block is mandatory: list each file that was actually read and its approximate line count. If a routed file was missing, say so explicitly instead of omitting it.
Command: improve
Goal: take a bloated AGENTS.md (any project) and refactor it into the thin + context-files architecture.
Flow:
- Read the entire
AGENTS.md(orCLAUDE.md) at the CWD. - Identify natural groupings by area (e.g. Filament, API, DB, prod, multi-tenancy).
- For each area, create
.claude/context/<area>.mdwith that area's detailed content. - Rewrite
AGENTS.mdfollowing the thin template below. - Ensure
CLAUDE.mdpoints atAGENTS.md(see symlink/fallback rules insetup).
Thin AGENTS.md template:
# <Project Name>
<1-2 line description: what it does, main stack>
## Load context before working
Before starting any task, read the matching context file:
| Area | File |
|------|------|
| <area 1> | `.claude/context/<area1>.md` |
| <area 2> | `.claude/context/<area2>.md` |
If a task touches multiple areas, read the relevant files in parallel.
## Non-negotiable rules (always apply)
<Only rules that apply to EVERY task — max 8 concise bullets>
## Checklist before opening a PR
<Full checklist — always worth keeping here>
## Essential commands
<Only the most-used day-to-day commands>
<Any tool/MCP auto-managed block goes at the end, untouched>Quality rubric — apply while restructuring (aligned with documented CLAUDE.md best practices):
- Target the thin AGENTS.md at ≤ ~2.5k tokens (~100–150 lines); treat 4k as a hard ceiling.
- Static content first, dynamic last (cache-friendly ordering): overview, routing table, rules and checklist are static; anything that changes often (learnings, gotchas) belongs in context files, not in AGENTS.md.
- Keep total imperative instructions in AGENTS.md well under 150 — merge similar rules, push details into context files.
- Each context file gets the header
# Context: <Area>and must be self-contained.
Improve rules:
- Never invent content — only reorganize what already exists in the original file.
- Auto-managed blocks (
<laravel-boost-guidelines>,## graphify, etc.) go at the end of AGENTS.md, byte-for-byte intact. - Idempotent re-runs: if
.claude/context/already has files, merge new content into the matching area file section by section — never blind-overwrite; when the same topic exists in both with conflicting content, keep both versions side by side under a<!-- MERGE: review -->comment and tell the user. Runningimproveon an already-thin AGENTS.md is a no-op that reports "already thin" with the current line/token count. - Afterwards, report: AGENTS.md line count before and after, and the list of files created/updated.
Command: setup
Goal: configure the context structure from scratch in a new project.
Flow:
- Use the CWD as project root (ask if ambiguous).
- Ask: "Describe the project in 1-2 lines (what it does, stack, for whom)."
- Ask: "What are the main work areas? (e.g. API, database, infra, frontend)" — suggest candidates based on the detected stack.
- Create
.claude/context/<area>.mdfor each area with the header# Context: <Area>and a<!-- Fill in as the project evolves -->comment. - Create
AGENTS.mdfrom the thin template (routing table pointing at the created areas). - Make
CLAUDE.mdresolve toAGENTS.md:- Preferred: symlink
CLAUDE.md → AGENTS.md. - Fallback (Windows,
core.symlinks=false, or any environment where symlinks fail): create a regularCLAUDE.mdcontaining only the import line@AGENTS.md— Claude Code's import syntax gives the same single-source-of-truth effect without a symlink.
- Preferred: symlink
- Create
~/.claude/projects/<hash>/memory/MEMORY.mdcontaining the format spec header:# Memory index — one pointer per line, content lives in the linked files <!-- - [Short title](filename.md) — one-line hook -->
Setup rules:
- If
AGENTS.mdalready exists → offerimproveinstead of overwriting. - If
CLAUDE.mdis already a symlink or an@AGENTS.mdimport → leave it alone. - If
CLAUDE.mdis a regular file with real content → ask before replacing.
After setup, report: files created, how to fill context files as the project evolves,
and how to add learnings (a file in memory/ + a pointer line in MEMORY.md).
Command: doctor
Goal: audit the context structure for drift. Read-only — reports, never fixes silently.
Checks:
- Dangling routes — entries in the AGENTS.md routing table whose
.claude/context/<area>.mdfile does not exist. - Orphan context files — files in
.claude/context/missing from the routing table. - Dead memory pointers — lines in MEMORY.md referencing files that don't exist.
- Stale memory — newest memory file older than 7 days.
- AGENTS.md weight — line count and approximate token estimate (~4 chars/token); flag over ~150 lines / 2.5k tokens, hard-flag over 4k tokens.
- Ordering — dynamic-looking sections (learnings, gotchas, recent changes) sitting above static sections in AGENTS.md (cache-hostile).
- CLAUDE.md linkage — CLAUDE.md is neither a symlink to AGENTS.md nor an
@AGENTS.mdimport (drift risk: two diverging sources of truth).
Output: one line per finding with severity (HIGH/MED/LOW) and the specific fix.
End with doctor: N findings or doctor: clean. Offer to apply fixes only after reporting.
General rules
- Never modify context files during
load— read only. Writes happen only vialearn,improve, andsetup. - Blocks auto-managed by MCP servers are untouchable.
- Memory files are point-in-time — warn when > 7 days without updates.
- Unrecognized mode: list available commands (
learn,<area>,improve,setup,doctor) and ask.
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.

