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

prime-context

Skill1 starsChanged 5 days agoMITView on GitHub

Manage thin AGENTS.md files, load context by area, capture durable learnings, and audit project context. Use setup shared to share rules and curated memory across Claude Code, Codex, and OpenCode. Use compaction to inspect or configure native session summarization.

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

28 rules. About 0 are common, 13 are distinctive, and 15 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈13

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 15

    Very specific

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

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

    Use its global memory/MEMORY.md for cross-project notes.

    line 26
  2. Very specific:

    Run the CLI with Python 3.8 or newer.

    line 30
  3. Very specific:

    Use migrate --map=CLAUDE-FOLDER=PATH to bind an unmapped folder explicitly.

    line 43
  4. Distinctive:

    Add new entries as pointers, one per memory file.

    line 45
  5. Very specific:

    Run sync --check to find newly written sensitive shared notes or quarantine --apply to mark them Claude-only with backups.

    line 69
  6. Distinctive:

    Keep new memory content in linked notes so the index stays cheap to scan.

    line 74
  7. Distinctive:

    If the check fails, rewrite the draft without the sensitive value and check again.

    line 113
  8. Very specific:

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

    line 120
  9. Very specific:

    If shared context is configured, consult the global index and run shared_sync.py resolve for the project index.

    line 129
  10. Distinctive:

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

    line 140
  11. Distinctive:

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

    line 170
  12. Very specific:

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

    line 174
  13. Distinctive:

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

    line 214
  14. Distinctive:

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

    line 219
  15. Very specific:

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

    line 222
  16. Distinctive:

    Follow the shared setup procedure.

    line 233
  17. Distinctive:

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

    line 246
  18. Distinctive:

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

    line 247
  19. Distinctive:

    Ask: "What are the main work areas?

    line 248
  20. 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 250
  21. Distinctive:

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

    line 252
  22. Very specific:

    Create <Claude config>/projects/<folder>/memory/MEMORY.md containing the format spec header:

    line 258
  23. Very specific:

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

    line 265
  24. Very specific:

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

    line 266
  25. Distinctive:

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

    line 267
  26. Very specific:

    Use Compaction. Bare compaction means status and is read-only.

    line 276
  27. Very specific:

    Run shared_sync.py doctor in addition to the project checks below.

    line 286
  28. Very specific:

    Never modify context files during load — read only.

    line 310

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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 location

Shared context is configured when the marker .prime-context-shared contains format=1 in $PRIME_CONTEXT_SHARED_HOME (default ~/.config/agent-instructions). Use its global memory/MEMORY.md for cross-project notes. Use shared_sync.py resolve for the project index. For unregistered projects, use the existing Claude project memory location below.

Run the CLI with Python 3.8 or newer. With the Claude Code plugin, the script is ${CLAUDE_PLUGIN_ROOT}/scripts/shared_sync.py. When only the skill folder is installed, including in Codex or OpenCode, use <skill dir>/scripts/shared_sync.py. See the shared setup contract.

MEMORY.md format (specification)

Claude's local MEMORY.md lives at <Claude config>/projects/<folder>/memory/MEMORY.md. The config root is $CLAUDE_CONFIG_DIR or ~/.claude. Claude replaces every character outside [A-Za-z0-9] in the absolute project path with -. Migration considers the first cwd in each transcript when it still exists and reproduces the folder name. The home folder supplies global memory by default, even without transcripts. Use migrate --map=CLAUDE-FOLDER=PATH to bind an unmapped folder explicitly.

Add new entries as pointers, one per memory file. Migrated indexes can also contain prose preserved from the original indexes:

- [Short title](filename.md) — one-line hook describing when this matters

Each referenced memory file is self-contained Markdown. Use this frontmatter for shared notes:

---
name: <slug>
description: <one line>
metadata:
  type: user|feedback|project|reference
  share: all|claude-only
---

An absent metadata.share means all. Other harnesses must skip notes marked claude-only. Doctor flags legacy top-level type as LOW. In Claude Code the plugin runs an incremental, time-bounded quarantine at SessionStart and resumes unfinished work on the next run. Quarantine backups stay in .state/backups/. Run sync --check to find newly written sensitive shared notes or quarantine --apply to mark them Claude-only with backups. Remove sensitive values from credentials and attachments at their source.

  • Keep new memory content in linked notes so the index stays 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).
    • Personal learning → a note and a pointer in the selected private memory index. Use the shared global index for a confirmed cross-project preference, the shared project index for a project-specific note, or the existing Claude project memory when shared context is not configured.
  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. In shared mode, stage the note privately and run shared_sync.py check-note FILE. If the check fails, rewrite the draft without the sensitive value and check again. When recording a credential, point to its storage location. Once the check passes, publish the note and add a new pointer with shared_sync.py append-index INDEXFILE LINE --apply. Concurrent appends are serialized and commit atomically without creating a backup for each pointer.
  6. 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. If shared context is configured, consult the global index and run shared_sync.py resolve for the project index. Load only notes relevant to the area. If resolve exits 4 or 5, use the legacy Claude project index if it exists. Outside Claude Code, inspect each note's frontmatter before loading its body and skip notes with metadata.share: claude-only. Disclose broken pointers in Verification.
  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 shared

Follow the shared setup procedure. Initialize the store, review the migration plan, close Claude Code sessions before applying it, generate the entrypoints, and run doctor. Match the complete setup shared argument before the standalone setup command.


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 config>/projects/<folder>/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: compaction [status|enable|disable]

Use Compaction. Bare compaction means status and is read-only. enable and disable apply to the active harness unless the user names another one. Resolve the complete command before matching an area name.


Command: doctor

Goal: audit the context structure for drift. Read-only — reports, never fixes silently.

Run shared_sync.py doctor in addition to the project checks below. Pass --claude-home DIR if auditing a different Claude configuration.

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 the selected MEMORY.md referencing files that don't exist. In shared mode, also check entrypoints and the project index mapping.
  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, setup, and setup shared. Change compaction settings only through the explicit compaction enable or compaction disable workflow.
  • 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, setup shared, compaction, 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.