agentleFS
rodrigopgrodrigopg/claude-skill-prime-context/skills/prime-context/SKILL.md

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

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. pablof7z/skills★ 1same name
    2. 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
  1. Very specific:

    Never touch AGENTS.md itself (rules there are managed via improve).

    line 74
  2. Very specific:

    Read ~/.claude/projects/<hash>/memory/MEMORY.md if it exists.

    line 83
  3. Distinctive:

    If the task at hand clearly touches several areas, read the relevant files in parallel.

    line 90
  4. Distinctive:

    Read the entire AGENTS.md (or CLAUDE.md) at the CWD.

    line 120
  5. Very specific:

    Ensure CLAUDE.md points at AGENTS.md (see symlink/fallback rules in setup).

    line 124
  6. Distinctive:

    Keep total imperative instructions in AGENTS.md well under 150 — merge similar rules, push details into context files.

    line 164
  7. Distinctive:

    Never invent content — only reorganize what already exists in the original file.

    line 169
  8. Very specific:

    Idempotent re-runs: if .claude/context/ already has files, merge new content into the matching area file section by section — never …

    line 172
  9. Distinctive:

    Use the CWD as project root (ask if ambiguous).

    line 187
  10. Distinctive:

    Ask: "Describe the project in 1-2 lines (what it does, stack, for whom)."

    line 188
  11. Distinctive:

    Ask: "What are the main work areas?

    line 189
  12. Very specific:

    Create .claude/context/<area>.md for each area with the header # Context: <Area> and a <!-- Fill in as the project evolves --> comment.

    line 191
  13. Distinctive:

    Create AGENTS.md from the thin template (routing table pointing at the created areas).

    line 193
  14. Very specific:

    Create ~/.claude/projects/<hash>/memory/MEMORY.md containing the format spec header:

    line 199
  15. Very specific:

    If AGENTS.md already exists → offer improve instead of overwriting.

    line 206
  16. Very specific:

    If CLAUDE.md is already a symlink or an @AGENTS.md import → leave it alone.

    line 207
  17. Distinctive:

    If CLAUDE.md is a regular file with real content → ask before replacing.

    line 208
  18. Very specific:

    Never modify context files during load — read only.

    line 240

≈ “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.

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

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 matters

Each 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 doctor and during load.
  • 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:

  1. 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.
  2. Route each learning:
    • Area-specific → append to the matching .claude/context/<area>.md (fuzzy-match as in load). No matching area → propose creating one (file + routing-table row).
    • User preference → a file in ~/.claude/projects/<hash>/memory/ plus a pointer line in MEMORY.md (create the directory and the MEMORY.md spec header if absent).
  3. 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.
  4. 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.
  5. Report one bullet per learning written or memory rewritten/deleted, with its destination file. Nothing durable in the session → say learn: nothing new and stop. Never touch AGENTS.md itself (rules there are managed via improve).

Command: load (an area name as argument)

Load one area's context on demand.

Flow:

  1. Read ~/.claude/projects/<hash>/memory/MEMORY.md if it exists; then read every file it lists. Skip silently if there is no memory directory — memory is optional.
  2. Resolve the area argument:
    • Exact filename match on .claude/context/<area>.md wins.
    • Otherwise case-insensitive substring match against files in .claude/context/ (e.g. filament matches php-filament.md).
    • Zero or multiple matches → list the available areas and ask which one.
  3. 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:

  1. Read the entire AGENTS.md (or CLAUDE.md) at the CWD.
  2. Identify natural groupings by area (e.g. Filament, API, DB, prod, multi-tenancy).
  3. For each area, create .claude/context/<area>.md with that area's detailed content.
  4. Rewrite AGENTS.md following the thin template below.
  5. Ensure CLAUDE.md points at AGENTS.md (see symlink/fallback rules in setup).

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. Running improve on 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:

  1. Use the CWD as project root (ask if ambiguous).
  2. Ask: "Describe the project in 1-2 lines (what it does, stack, for whom)."
  3. Ask: "What are the main work areas? (e.g. API, database, infra, frontend)" — suggest candidates based on the detected stack.
  4. Create .claude/context/<area>.md for each area with the header # Context: <Area> and a <!-- Fill in as the project evolves --> comment.
  5. Create AGENTS.md from the thin template (routing table pointing at the created areas).
  6. Make CLAUDE.md resolve to AGENTS.md:
    • Preferred: symlink CLAUDE.md → AGENTS.md.
    • Fallback (Windows, core.symlinks=false, or any environment where symlinks fail): create a regular CLAUDE.md containing only the import line @AGENTS.md — Claude Code's import syntax gives the same single-source-of-truth effect without a symlink.
  7. Create ~/.claude/projects/<hash>/memory/MEMORY.md containing 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.md already exists → offer improve instead of overwriting.
  • If CLAUDE.md is already a symlink or an @AGENTS.md import → leave it alone.
  • If CLAUDE.md is 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:

  1. Dangling routes — entries in the AGENTS.md routing table whose .claude/context/<area>.md file does not exist.
  2. Orphan context files — files in .claude/context/ missing from the routing table.
  3. Dead memory pointers — lines in MEMORY.md referencing files that don't exist.
  4. Stale memory — newest memory file older than 7 days.
  5. AGENTS.md weight — line count and approximate token estimate (~4 chars/token); flag over ~150 lines / 2.5k tokens, hard-flag over 4k tokens.
  6. Ordering — dynamic-looking sections (learnings, gotchas, recent changes) sitting above static sections in AGENTS.md (cache-hostile).
  7. CLAUDE.md linkage — CLAUDE.md is neither a symlink to AGENTS.md nor an @AGENTS.md import (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 via learn, improve, and setup.
  • 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.

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.