context-management
Skill146 starsChanged 7 months agoMITView on GitHub
Use in long or noisy sessions to persist durable state across session boundaries via state.md. Also generates project-map.md when asked to map the project. Triggers on: user explicitly asks to "save state", "compress context", "map this project", "generate project map", "create project map", cross-session handoff needed, or repeated failures indicate context is getting stale.
- Reads credentials
14 other projects use a version of this.
Adopted by
Most recently taken up by
- AnthonyPoschen/agent-skillstheir own version, first seen Oct 26, 2026
- timfewi/unix-agent-skillstheir own version, first seen Oct 17, 2026
- opensite-ai/opensite-skillstheir own version, first seen Oct 13, 2026
- krema/agent-skillstheir own version, first seen Oct 13, 2026
- ttttmr/pi-contexttheir own version, first seen Oct 9, 2026
- OneDro1d/onedroid-docstheir own version, first seen Sep 18, 2026
Used with
Projects with it also use verification.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
OpenAISkillverification
Full-story verification — infers what the user is building, then verifies the complete flow end-to-end: browser → API → data → response. Triggers on dev server start and 'why isn't this working' signals.
Also in 3 projects that use this
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 14
- ttttmr/pi-context★ 304same name
- kangarooking/system-prompt-skills★ 178same name
- opensite-ai/opensite-skills★ 15same name
- sefaertunc/Worclaude★ 4same name
- AnthonyPoschen/agent-skills★ 2same name
- bjornjee/skills★ 2same name
- stateofthehart/claude-code-config★ 2same name
- timfewi/unix-agent-skills★ 2same name
- sefaertunc/anthropic-watch★ 1same name
- Bridev04/clauderail★ 0same name
4 more not listed
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.
In this repository23 other files it gives its agents.
- brainstormingSkill
- claude-md-creatorSkill
- deliberationSkill
- dependency-managementSkill
- dispatching-parallel-agentsSkill
- error-recoverySkill
- executing-plansSkill
- finishing-a-development-branchSkill
- frontend-designSkill
- performance-investigationSkill
- premise-checkSkill
- receiving-code-reviewSkill
- refactoringSkill
- requesting-code-reviewSkill
- self-consistency-reasonerSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- token-efficiencySkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- writing-plansSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
22 rules. 0 are common, 14 are distinctive, and 8 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
14
Distinctive
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Do not default to state.md for a map request.
- Very specific: line 45
Before diving in, grep session-log.md for history relevant to the current task.
- Distinctive: line 54
Check the hit count before reading results.
- Distinctive: line 61
Step 4 — Surface what matters: If relevant entries are found, state them explicitly before proceeding: what was decided, what was rejected, …
- Very specific: line 75
If a plan exists, state.md should say "Executing plan at docs/.../plan.md, currently on Task 3" — not copy the full task list.
- Very specific: line 77
Write state.md at the project root with concise sections:
- Distinctive: line 97
Test results or verification confirmations ("11/11 tests pass")
- Distinctive: line 110
If a decision doesn't fit in 25 words, the explanation belongs in a design doc.
- Very specific: line 123
After appending the [saved] entry, update the stop-hook marker so the decision-log reminder resets:
- Distinctive: line 141
Keep under 200 entries — prune entries older than 6 months when it exceeds this
- Very specific: line 142
When a decision is permanently superseded (e.g., the approach was replaced), mark it rather than deleting: append [superseded by YYYY-MM-DD]
- Distinctive: line 143
Do NOT log trivial sessions — a session with no decision worth carrying forward should leave no entry
- Distinctive: line 155
After a major refactor where many files moved or changed purpose
- Distinctive: line 163
If git exists → record git rev-parse HEAD as the staleness hash.
- Distinctive: line 206
When the staleness check in the entry sequence flags changed files:
- Distinctive: line 208
Update their entries in the Key Files section.
- Distinctive: line 209
Update the git hash / timestamp in the header.
- Distinctive: line 210
If any new critical constraints were discovered this session, add them.
- Distinctive: line 218
Do not drop user-provided constraints.
- Distinctive: line 219
Do not rewrite requirements.
- Very specific: line 220
If uncertain whether old context matters, keep a short reference in Open Issues.
- Very specific: line 221
Keep state.md under 100 lines — if it's longer, it's not compressed enough.
“Common” is measured: kept by at least 6 in 10 of the 13 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.
Files
Context Management
Route first — read this before anything else
| User said | Go to |
| "map this project" / "generate project map" / "create project map" / "update project map" | Project Map section |
| "save state" / "compress context" / session ending with ongoing work | Procedure section |
| Starting a task on a project with existing history | Grep session-log.md first, then proceed |
Do not default to state.md for a map request. Do not default to project-map.md for a save-state request.
Purpose
Claude Code automatically compresses context within a session. This skill has two complementary responsibilities:
- Cross-session persistence —
state.mdpreserves decisions and progress for the current task when a session ends mid-work. - Accumulated project memory —
session-log.mdbuilds a searchable history of decisions, rejected approaches, and hard-won facts across sessions. Written manually via this skill — only when there is something worth preserving.
When to Use
- User explicitly asks to save state or compress context
- Work will continue in a new session and progress must be preserved
- Complex multi-step task has significant accumulated decisions/evidence
- Starting a new task on a project with existing history — grep the log first
- Repeated failures suggest the session has accumulated stale/conflicting context
Procedure
At the start of any non-trivial task
Before diving in, grep session-log.md for history relevant to the current task.
Step 1 — Extract keywords. Take the 2-3 most distinctive nouns from the task description. Avoid generic words ("fix", "update", "file") — use domain nouns ("hook", "auth", "deploy", "staleness").
Step 2 — Grep each keyword individually first:
grep -i "<keyword1>" session-log.md | tail -20
grep -i "<keyword2>" session-log.md | tail -20Check the hit count before reading results. This tells you whether to narrow or widen before committing to any output.
Step 3 — Adjust based on hit count:
- 0 hits on all keywords → fall back to
project-map.mdCritical Constraints. Relevant history may have been promoted there instead of staying in the log. If still nothing, proceed without history. - 1–10 hits → read them. Surface past decisions, rejected approaches, and constraints.
- >10 hits on one keyword → narrow with a second term:
grep -i "<kw1>" session-log.md | grep -i "<kw2>" | tail -20
Step 4 — Surface what matters. If relevant entries are found, state them explicitly before proceeding: what was decided, what was rejected, what constraints apply. Don't silently absorb them — make them visible so the user can confirm or override.
When saving state (explicit invocation)
Extract durable artifacts only:
- Approved design decisions
- Active plan tasks and their status
- Verified facts/evidence
- Open questions/risks
state.md vs plan.md:
plan.md(ordocs/.../plans/*.md): the authoritative task list with checkboxes. Owned byexecuting-plans. Updated as tasks complete.state.md: a session-boundary snapshot of where you are in the plan — current task, blockers, what's verified. It references the plan but does not duplicate the task list.
If a plan exists, state.md should say "Executing plan at docs/.../plan.md, currently on Task 3" — not copy the full task list.
- Write
state.mdat the project root with concise sections:Current GoalDecisionsPlan StatusEvidenceOpen Issues
- Check for superseded entries before appending. Grep
session-log.mdfor 2-3 keywords from the current decision:
Read any matchinggrep -i "<keyword>" session-log.md[saved]entries and ask: does the new decision directly contradict an old one? If yes, append[superseded by YYYY-MM-DD]to the old entry's header line — do not delete it. If the old entry is merely related but not contradicted, leave it unchanged. This is a judgment call, not a mechanical keyword match. - Append a
[saved]entry tosession-log.md:
What belongs here vs state.md:
session-log.md [saved]: permanent decisions, anti-patterns to avoid, carry-forward open itemsstate.md: active task status, in-progress plans, checklists, version bump readiness — anything that will be resolved soon
Never include in a [saved] entry:
- Test results or verification confirmations ("11/11 tests pass")
- Task checklists, file changelogs, or release notes → use
state.md - "How it works" walkthroughs → read the code
- Speculative analysis not approved for implementation → use a design doc in
docs/ - One-time confirmations ("file deleted", "folder removed")
- Newly discovered permanent architectural constraints → add to
project-map.mdCritical Constraints instead
Hard limits per component — enforce while writing, not after:
- Goal: 1 line, ≤15 words
- Decisions: ≤5 bullets for multi-subsystem sessions, ≤3 for single-topic. Each bullet: decision + one-sentence why, ≤25 words total. No prose, no rationale beyond the why.
- Rejected: ≤3 bullets, ≤15 words each. What to avoid — not the full story of why it failed.
- Open: ≤2 items, ≤12 words each.
If a decision doesn't fit in 25 words, the explanation belongs in a design doc. Cut the explanation, not the decision.
Total entry backstop: 250 words / 1500 chars. If exceeded, a bullet violated its limit — find it and cut it. Typical single-topic sessions should target ~120 words; the higher cap exists for multi-subsystem sessions that genuinely touched 5+ areas.
## YYYY-MM-DD HH:MM [saved]
Goal: <one line>
Decisions:
- <what was chosen and the one-sentence why — not how it works>
Rejected: <what NOT to try, one line each — the anti-pattern knowledge>
Open: <carry-forward items only>- After appending the
[saved]entry, update the stop-hook marker so the decision-log reminder resets:
This prevents the stop hook from re-firing the decision-log reminder on every subsequent stop in the same session.node -e "require('fs').writeFileSync(require('path').join(process.env.HOME||process.env.USERPROFILE||'.', '.claude','hooks-logs','last-saved-entry.txt'), new Date().toISOString())" - In a new session, read
state.mdfirst to restore task context, then grepsession-log.mdfor relevant history.
session-log.md Format and Maintenance
The log contains a single entry type:
- [saved] — written by this skill when explicitly invoked: full decision record including goals, rationale, rejected approaches, and key facts.
Nothing else writes to this file. The Stop hook reads it and reminds you to save, but it never appends. If a session's decisions are not saved through this skill, they are lost when the session ends.
File management:
- Lives at the project root alongside
CLAUDE.mdandpackage.json - Keep under 200 entries — prune entries older than 6 months when it exceeds this
- When a decision is permanently superseded (e.g., the approach was replaced), mark it rather than deleting: append
[superseded by YYYY-MM-DD] - Do NOT log trivial sessions — a session with no decision worth carrying forward should leave no entry
For cross-project recall (finding how a similar problem was solved in a different codebase): session-log.md is per-project and keyword-searchable only. Cross-project recall is outside the scope of this system.
Project Map
project-map.md is the semantic memory layer — it captures the project's structure, key file purposes, and critical non-obvious constraints so that future sessions can orient without re-globbing or re-reading known files. Generate it once; update it when the project changes.
When to generate or update
- User says "map this project", "generate project map", or "update project map"
- First time setting up memory on a new project
- After a major refactor where many files moved or changed purpose
Generation procedure
- Check for git:
git rev-parse --git-dir 2>/dev/null- If git exists → record
git rev-parse HEADas the staleness hash. - If git does NOT exist → offer: "No git repository detected. Shall I run
git init? It enables precise staleness tracking forproject-map.md— creates a.gitfolder, touches none of your files. If you'd prefer not to, I'll fall back to file timestamp comparison instead, which works fine but is slightly less precise."- User confirms → run
git init --quiet, then proceed with git hash. - User declines → use generation timestamp as the staleness marker.
- User confirms → run
- If git exists → record
- Map the structure: Glob the project, identify the top-level directories and their purpose. Do not enumerate every file — summarise by directory.
- Document key files: For each file that is load-bearing, non-obvious, or frequently referenced, write one line describing what it does and why it matters. Aim for 10–20 entries. Skip files whose purpose is obvious from their name.
Capture critical constraints: The highest-value section. These are non-obvious facts that are not visible in the code itself — quoting rules, platform differences, version sync requirements, things that caused bugs before. Pull these from
session-log.md[saved]entries and fromknown-issues.mdif they exist.Never repeat what
CLAUDE.mdorAGENTS.mdalready says. Those files are loaded into every session; the map is injected alongside them, so a duplicated constraint costs tokens twice and adds nothing. Read them first and leave out anything they cover — in this section and in Key Files.- Identify hot files: The files that change most often — the ones most likely to need a freshness check on future sessions.
Without git, fall back to the files most often named ingit log --name-only --pretty=format: --since=6.months | grep -v '^$' | sort | uniq -c | sort -rn | head -15session-log.mddecisions. Do not look forFiles:lines — that field belonged to[auto]entries, which were retired on 2026-04-04. - Write
project-map.mdat the project root — same level asCLAUDE.mdandpackage.json, never indocs/or any subdirectory. The session-start hook looks for it withls project-map.md 2>/dev/nullfrom the project root — if it's anywhere else, the hook cannot find it and every future session loses the map. Use this format:
# Project Map
_Generated: YYYY-MM-DD HH:MM | Git: <short-hash> | (or: Staleness: timestamps)_
## Directory Structure
<dir>/ — <one-line purpose>
<dir>/ — <one-line purpose>
## Key Files
<path> — <what it does and why it matters>
<path> — <what it does and why it matters>
## Critical Constraints
- <non-obvious fact that would cost time to rediscover>
- <non-obvious fact that would cost time to rediscover>
## Hot Files
<path>, <path>, <path>Update procedure
When the staleness check in the entry sequence flags changed files:
- Re-read only the flagged files.
- Update their entries in the Key Files section.
- Update the git hash / timestamp in the header.
- If any new critical constraints were discovered this session, add them.
Size: 150 lines is the authoring target, 200 is the hard limit. Under 150, the map is doing its job. Between 150 and 200 it is still injected in full, but it has stopped being a map and become documentation — prune file entries whose purpose is now obvious. At 200+ the session-start hook stops injecting the full file and falls back to Critical Constraints and Hot Files only, so anything you wrote in Key Files silently stops reaching future sessions. Never let it cross 200.
Lines are not the only limit. All project memory shares one ~9,500-character injection budget, filled in order: state.md → Critical Constraints → open known issues → the latest session-log entries → the rest of the map. A 4,000-character Critical Constraints section pushes the latest decisions out of every session. Keep each constraint to one line and the section under ~1,500 characters; node tools/memory-health.js shows what was cut.
Guardrails
- Do not drop user-provided constraints.
- Do not rewrite requirements; preserve intent.
- If uncertain whether old context matters, keep a short reference in
Open Issues. - Keep
state.mdunder 100 lines — if it's longer, it's not compressed enough.
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.

