一键导入
optimize-context
Scan project, then generate or reconcile .primeignore patterns for smarter /prime loading
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scan project, then generate or reconcile .primeignore patterns for smarter /prime loading
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run WCAG accessibility audits on frontend projects. Checks HTML semantics, ARIA usage, color contrast, and keyboard navigation patterns.
Generate OpenAPI specs from code, validate API contracts, and check for breaking changes between versions.
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Incrementally fix TypeScript and build errors one at a time with verification. Invokes the build-error-resolver agent.
Create or verify a checkpoint in your workflow
ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.
| name | optimize-context |
| description | Scan project, then generate or reconcile .primeignore patterns for smarter /prime loading |
| argument-hint | [analyze|--reconcile] |
Manage a .primeignore file that tells /prime which tracked files to skip during bulk context loading. Files listed in .primeignore remain fully accessible — they are not blocked, just not loaded by default.
This is Layer 3 of the exclusion model:
| Layer | Mechanism | Effect |
|---|---|---|
| Hard Block | permissions.deny | Cannot read at all (for secrets) |
| Noise Filter | .gitignore | Not tracked, not visible (for junk) |
| Soft Skip | .primeignore | Tracked and readable, but skipped by /prime |
/prime loaded large files that weren't useful/prime feels slow or token-heavy$ARGUMENTS options:
.primeignore if missing, otherwise propose additionsanalyze — Scan and report findings without writing any files--reconcile — Regenerate the entire .primeignore from scratch: collapse dated appendix sections, drop subsumed and zero-match patterns, refresh every count against ground truth. User-added patterns (lines without a # [auto] tag) are always preserved.Auto-escalate to reconcile: if the existing .primeignore has ≥3 dated "Added by /optimize-context" sections, OR verification (Step 3) finds any category whose real match count exceeds its labeled count by >2x, recommend --reconcile and get confirmation before proceeding in append mode. Append-only accretion is how pattern labels drift into lies.
Never infer what a pattern matches by reading it. Ask git. Ignore-glob semantics (patterns don't cross /, parent-dir exclusion blocks child re-inclusion, anchoring rules) routinely surprise even careful authors. Every count, every claim, every header comment in this skill's output must come from git's own matcher:
# Ground truth for the whole file:
git ls-files -ci --exclude-from=.primeignore # what IS excluded
comm -23 <(git ls-files | sort) \
<(git ls-files -ci --exclude-from=.primeignore | sort) # what survives
# Ground truth for a single candidate pattern:
git ls-files -ci --exclude='PATTERN'
This principle requires git — it is the only faithful matcher for gitignore syntax and the only way to verify a count instead of guessing it. Outside a git repo the skill degrades to best-effort estimates (see Step 0); when that happens, say so plainly and never present an estimated count as verified.
Run git rev-parse --is-inside-work-tree 2>/dev/null.
--reconcile guarantees hold. This is strongly preferred.git init. For any directory you prime repeatedly, this is the right fix — one non-destructive command that unlocks the fully-verified path plus version history. Weakening the analysis to avoid it is a bad trade..git is unwelcome), run best-effort mode and label every output no git — counts are ESTIMATES, unverified:
find . -type f minus a built-in junk-skip (.git, node_modules, .venv, venv, __pycache__, dist, build, .next, target, .pytest_cache) and minus anything matched by a local .gitignore if one exists (parse it).fnmatch/glob — this is NOT gitignore-faithful (negation, **, anchoring, and parent-dir re-inclusion may differ). Never claim a verified count.--reconcile counts, and the allowlist-survivor check all depend on git — say so explicitly rather than fake them.The rest of this process assumes the verified git path; in best-effort mode, substitute the fallbacks above and downgrade every "verified" claim to "estimated".
Check for manifest files: package.json (Node/TS), requirements.txt/pyproject.toml (Python), composer.json (PHP), go.mod (Go), Cargo.toml (Rust). None → generic. Use default-patterns.md (in this skill's directory) as the pattern reference library for the detected type.
git ls-files | wc -l — total tracked files.gitignore (do NOT recommend patterns duplicating it — git ls-files already omits untracked files).claude/settings.json deny rules if present.primeignore exists, run the ground-truth commands above and record: cumulative exclusion %, the survivor list, and how old the file is (git log -1 --format=%ci -- .primeignore)For each existing pattern, check with git ls-files -ci --exclude='PATTERN':
Never suggest excluding, and refuse patterns that match:
CLAUDE.md, README.md (root), .primeignore itselfscripts/main fields, Dockerfile CMD, and CLAUDE.md run instructions, not just a generic list (app.py, index.ts, main.py, server.js, main.go).claude/rules/*.md for directories the rules require reading.primeignore savings depend entirely on how /prime reads — model it before estimating anything:
bytes ÷ 4 of what you exclude. This is where a bloated survivor set hurts most (a >100K prime is almost always full mode).^class |^def |^export |^function ) and merely lists everything else. A source file's quick-mode cost ≈ its signature-line count × ~12 tokens, NOT bytes ÷ 4. Docs/data/binary that quick mode never reads cost ~one listing line each.Detect the user's usual mode (ask if unknown; default full, since that's where optimization pays). Estimate and prioritize against that mode:
bytes ÷ 4.Always report the fully-read floor — the token cost of the protected, always-read set (CLAUDE.md + README head + entry point). Prime cannot go below this via .primeignore; if the user's target is under the floor, say so and point them at trimming CLAUDE.md / the injected rules stack / connected MCP servers instead.
KEEP: source files in the architectural core (the modules CLAUDE.md's architecture section actually names), configuration/manifests, primary docs, the protected set.
SUGGEST EXCLUDE — built-in categories (see default-patterns.md for the full library):
plans/archive/, .claude/handoffs/, .claude/brainstorms/, .claude/code-reviews/, _archive/, old/, deprecated/).claude/commands/, .claude/agents/, .claude/rules/ (Claude Code loads these itself; reading them during prime is redundant)SUGGEST EXCLUDE — derived by scan (not just the hardcoded list):
archive|handoff|brainstorm|render|snapshot|deprecated|old — the project's own junk-drawer conventions beat a canned listgit ls-files | tr '\n' '\0' | xargs -0 wc -c 2>/dev/null | sort -rn | head -20; flag any surviving file over ~25K tokens (~100KB) regardless of extension — catches large tracked HTML/JSON/generated docs, not just binaries. Also flag all binary assets (*.png, *.pdf, *.jpg, media) as their own category.git ls-files | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -20; directories with >50 tracked files of data, migrations, or fixturesActive/archive split rule: never blanket-exclude a directory whose contents the project splits into active vs. archived (e.g. plans/ when the workflow says active plans live there and completed ones move to plans/archive/). Exclude only the archive half. Check project rules before proposing any whole-directory pattern.
For every candidate pattern, before presenting it:
git ls-files -ci --exclude='PATTERN' → the real file count (this number goes in the header comment)wc -c, divide bytes by 4 → measured token estimate (no per-file guessing)Compute the cumulative exclusion % (existing + proposed, via --exclude-from on the would-be file — not per-run).
>70% excluded: recommend flipping to allowlist form — shorter, self-documenting, and drift-safe (new files default to excluded instead of silently leaking into prime):
# Allowlist mode: exclude everything, re-include what prime should read.
# The !*/ line is required — gitignore semantics cannot re-include a file
# whose parent directory is excluded.
*
!*/
!.primeignore
!CLAUDE.md
!README.md
!src/main.py
!docs/architecture.md
Verify the allowlist the same way: the survivor list from comm -23 must equal the intended include set.
>80% excluded and staying denylist: warn explicitly and require confirmation.
Group by category. For each: name, verified file count, measured token estimate, exact patterns, and a sample of matched files. Then:
## .primeignore Recommendations for [project-name]
Prime mode optimized for: [full | quick]
Tracked files: X total
Currently excluded (verified): Y (Z%)
Survivor text prime can read/grep: ~AK tokens → ~BK after these patterns
Fully-read floor (CLAUDE.md + README head + entry, cannot be excluded): ~CK tokens
Survivors worth attention: [list any large/binary/historical files currently surviving]
### Category 1: ... (N files verified, ~XK tokens measured)
Pattern: `...`
Files matched (sample): ...
[If reconciling] ### Removals: M stale/subsumed patterns, K label corrections
---
Resulting exclusion: X% (Y files survive prime)
Projected prime cost: ~floor + read-survivors (state the number, and if it can't reach the user's target, name what else must shrink — CLAUDE.md, the injected rules stack, or connected MCP servers)
Approve categories? (numbers, "all", or "none")
CRITICAL: Do NOT write anything until the user explicitly approves. (analyze mode always stops here.)
# Reconciled by /optimize-context on YYYY-MM-DD. Preserve user-added patterns (no # [auto] tag) verbatim.# [auto] pattern the new ones subsume# [auto] tag; category header comments carry the verified count and measured tokensRerun the ground-truth commands against the written file and report:
git ls-files -ci --exclude-from=.primeignore, not arithmetic).primeignore FormatGitignore-compatible syntax:
# for comments, blank lines ignoreddirectory/ to skip an entire directory*.extension for file type patternspath/to/specific-file.json for individual files!pattern negation to force-include (needed for allowlist mode; remember !*/)# [auto]; untagged lines are user-added and always preserved/primeThe prime-quick and prime-full commands in this repo already read .primeignore at Step 0: they parse the patterns, filter all listing/reading, protect CLAUDE.md/manifests/entry points regardless of patterns, and report "X files excluded by .primeignore (~YK tokens saved)". Files are always readable on demand — if the user asks for a skipped file, read it normally.
.primeignore should be committed to git (project configuration, not a secret)permissions.deny for that.gitignore already covers a pattern, don't duplicate it here--reconcile periodically; a .primeignore older than ~30 days or ~50 commits in an active repo is presumptively stale