feat: thin session — hide skill bulk from injection, route on demand
Claude Code injects every personal skill name (~1.4k skills → ~11k tokens) into each session. Thin session hides the bulk via native skillOverrides (user-invocable-only) and surfaces the top-5 relevant skills per prompt — saving ~11k tokens/session while keeping every skill reachable by /name. - gen-skill-overrides.mjs: writes the skillOverrides hide-map (allowlist editable) - skill-router.mjs: UserPromptSubmit hook, per-prompt top-5, fail-open + guarded - athena-research: manual router skill - build-skill-index.mjs: index now scans ~/.claude/skills + dedupes parity copies - route-skills.mjs / build_registry.py: usage/frequency removed from ranking (still collected for analytics; ranking is quality-led) - settings.json.tmpl: register the hook; bootstrap Layer 2 runs the generator so thin session is on by default for fresh installs - docs/thin-session.md + README: what it is, how it saves tokens, how to revert Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
bc3696bb38
commit
67e6b0e84d
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env node
|
||||
// Thin-session: regenerate `skillOverrides` in ~/.claude/settings.local.json.
|
||||
//
|
||||
// Every personal skill under ~/.claude/skills EXCEPT the allowlist is set to
|
||||
// "user-invocable-only" — hidden from the model's skill listing (≈0 injected
|
||||
// tokens) but still invocable by the user via /name, and still Read-able by the
|
||||
// athena-research router. Allowlist skills are OMITTED from the map, so they
|
||||
// fall through to the default "on" (model-auto-invocable) — a typo here can
|
||||
// never force a needed skill off.
|
||||
//
|
||||
// Idempotent + machine-portable: it derives the set from THIS machine's FS, so
|
||||
// it is safe to ship via chezmoi and re-run anywhere. Re-run after adding skills.
|
||||
//
|
||||
// node ~/.claude/scripts/gen-skill-overrides.mjs
|
||||
//
|
||||
import { promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const HOME = process.env.HOME;
|
||||
const SKILLS = path.join(HOME, ".claude/skills");
|
||||
const SETTINGS = path.join(HOME, ".claude/settings.local.json");
|
||||
|
||||
// Kept model-auto-invocable (constitution lifecycle + cross-referenced + router).
|
||||
// caveman/ponytail are PLUGINS (separate visibility) — not listed here.
|
||||
const ALLOWLIST = new Set([
|
||||
"athena-research", // the router itself — entry point, must stay visible
|
||||
"mnemazina", // daily knowledge pipeline, model-invoked by name
|
||||
"self-learning", // constitution checkpoint
|
||||
"handoff", // constitution checkpoint
|
||||
"organize", // constitution structure workflow
|
||||
"grill-me", // constitution new-work workflow
|
||||
"codex", // cross-harness handoff, referenced
|
||||
"humanizer", // constitution: apply every response (UI strings)
|
||||
"humanizer-ru", // constitution: apply to RU text
|
||||
"humanizer-en", // constitution: apply to EN text
|
||||
"skill-creator", // model creates skills on request
|
||||
"bootstrap-project", // constitution new-project workflow
|
||||
]);
|
||||
|
||||
// Collect skill ids = basename of any dir (<=2 deep under SKILLS) holding SKILL.md.
|
||||
// Depth 2 covers top-level skills/<id> and one grouping level skills/<grp>/<id>.
|
||||
async function findSkillIds(root, depth, ids) {
|
||||
let entries;
|
||||
try {
|
||||
entries = await fs.readdir(root, { withFileTypes: true });
|
||||
} catch {
|
||||
return ids;
|
||||
}
|
||||
if (entries.some((e) => e.isFile() && e.name === "SKILL.md")) ids.add(path.basename(root));
|
||||
if (depth > 0) {
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules") {
|
||||
await findSkillIds(path.join(root, e.name), depth - 1, ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
const ids = [...(await findSkillIds(SKILLS, 2, new Set()))].sort();
|
||||
const overrides = {};
|
||||
for (const id of ids) {
|
||||
if (!ALLOWLIST.has(id)) overrides[id] = "user-invocable-only";
|
||||
}
|
||||
|
||||
let settings = {};
|
||||
try {
|
||||
settings = JSON.parse(await fs.readFile(SETTINGS, "utf8"));
|
||||
} catch {
|
||||
/* fresh file */
|
||||
}
|
||||
settings.skillOverrides = overrides;
|
||||
await fs.writeFile(SETTINGS, JSON.stringify(settings, null, 2) + "\n");
|
||||
|
||||
const present = [...ALLOWLIST].filter((i) => ids.includes(i));
|
||||
const missing = [...ALLOWLIST].filter((i) => !ids.includes(i));
|
||||
console.log(`skills on disk: ${ids.length}`);
|
||||
console.log(`hidden (user-invocable-only): ${Object.keys(overrides).length}`);
|
||||
console.log(`allowlist present (stays on): ${present.length} -> ${present.join(", ")}`);
|
||||
console.log(`allowlist MISSING on disk: ${missing.join(", ") || "(none)"}`);
|
||||
console.log(`wrote ${SETTINGS}`);
|
||||
Reference in New Issue
Block a user