/superpowers-optimized:context-managementfrom superpowers-optimized
Persists durable state across sessions via state.md and generates project-map.md. Greps session-log.md for relevant history at task start.
Ships in superpowers-optimized. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| 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.
Claude Code automatically compresses context within a session. This skill has two complementary responsibilities:
state.md preserves decisions and progress for the current task when a session ends mid-work.session-log.md builds 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.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 -20
Check 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:
project-map.md Critical Constraints. Relevant history may have been promoted there instead of staying in the log. If still nothing, proceed without history.grep -i "<kw1>" session-log.md | grep -i "<kw2>" | tail -20Step 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.
Extract durable artifacts only:
state.md vs plan.md:
plan.md (or docs/.../plans/*.md): the authoritative task list with checkboxes. Owned by executing-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.md at the project root with concise sections:
Current GoalDecisionsPlan StatusEvidenceOpen IssuesCheck for superseded entries before appending. Grep session-log.md for 2-3 keywords from the current decision:
grep -i "<keyword>" session-log.md
Read any matching [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 to session-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 soonNever include in a [saved] entry:
state.mddocs/project-map.md Critical Constraints insteadHard limits per component — enforce while writing, not after:
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:
node -e "require('fs').writeFileSync(require('path').join(process.env.HOME||process.env.USERPROFILE||'.', '.claude','hooks-logs','last-saved-entry.txt'), new Date().toISOString())"
This prevents the stop hook from re-firing the decision-log reminder on every subsequent stop in the same session.
In a new session, read state.md first to restore task context, then grep session-log.md for relevant history.
The log contains a single entry type:
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:
CLAUDE.md and package.json[superseded by YYYY-MM-DD]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.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.
Check for git:
git rev-parse --git-dir 2>/dev/null
git rev-parse HEAD as the staleness hash.git init? It enables precise staleness tracking for project-map.md — creates a .git folder, 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."
git init --quiet, then proceed with git hash.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 from known-issues.md if they exist.
Never repeat what CLAUDE.md or AGENTS.md already 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.
git log --name-only --pretty=format: --since=6.months | grep -v '^$' | sort | uniq -c | sort -rn | head -15
Without git, fall back to the files most often named in session-log.md decisions. Do not look for Files: lines — that field belonged to [auto] entries, which were retired on 2026-04-04.
Write project-map.md at the project root — same level as CLAUDE.md and package.json, never in docs/ or any subdirectory. The session-start hook looks for it with ls project-map.md 2>/dev/null from 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>
When the staleness check in the entry sequence flags changed files:
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.
Open Issues.state.md under 100 lines — if it's longer, it's not compressed enough.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub repozy/superpowers-optimized --plugin superpowers-optimized24 skills in this plugin
/brainstormingUse when the user wants new features, behavior changes, refactoring with new capabilities, or architecture decisions and no approved design exists yet. Produces a design before any code is written — in the conversation for small changes, as an approved spec document for larger work. Triggers on: "build this", "add a feature", "I want to change", "how should we", "design", "architect", "new project", "refactor", "we need to add/build/create", "implement a new". Routed by using-superpowers, or invoke directly via /brainstorming.
/claude-md-creatorCreates minimal, high-signal CLAUDE.md and AGENTS.md context files based on empirical best practices. Invoke on /init command, "create CLAUDE.md", "update CLAUDE.md", "write AGENTS.md", or "set up Claude Code for this project". Also invoked by brainstorming when repo lacks a context file. tools: Read, Glob, Grep, Bash, Edit
/deliberationOther plugins' skills for the same job