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:
Зарубин Филипп
2026-06-22 20:31:30 +03:00
co-authored by Claude Opus 4.8
parent bc3696bb38
commit 67e6b0e84d
10 changed files with 346 additions and 7 deletions
@@ -4,6 +4,7 @@ import path from "node:path";
const HOME = process.env.HOME;
const roots = [
path.join(HOME, ".claude/skills"),
path.join(HOME, ".agents/skills"),
path.join(HOME, ".codex/skills"),
path.join(HOME, ".codex/plugins/cache"),
@@ -359,6 +360,23 @@ for (const file of skillFiles) {
records.push(record);
}
// Thin-session: collapse parity-duplicate skills (same id present across
// .claude/skills, .agents/skills, .codex/skills) into ONE record, preferring
// the earliest root above (.claude first = canonical, /name-invocable copy the
// router should Read). Without this, adding .claude/skills would double records
// for every parity-synced skill. ponytail: id-dedup, path-level dedup below still runs.
const rootRank = (r) => {
const i = roots.indexOf(r);
return i === -1 ? 999 : i;
};
const bestSkillById = new Map();
for (const rec of records) {
const prev = bestSkillById.get(rec.id);
if (!prev || rootRank(rec.root) < rootRank(prev.root)) bestSkillById.set(rec.id, rec);
}
records.length = 0;
records.push(...bestSkillById.values());
for (const record of await configuredCapabilities()) {
records.push(record);
}
@@ -162,8 +162,11 @@ def effectiveness(stars, rating, parity_warn, usage_norm=0.0,
quality = (rating or 3) / 5 # real output quality (my judgement)
reach = stars_norm(stars) # community proof — weak signal
proven = success_rate if (runs >= 3 and success_rate is not None) else reach
val = round(100 * (0.42 * quality + 0.25 * proven + 0.18 * reach
+ 0.10 * usage_norm + 0.05 * fresh))
# usage/frequency deliberately NOT scored — collected for analytics only, never
# ranks (one past use must not pin a skill to the top). Its old 0.10 weight folds
# into quality so the score stays QUALITY-led and on a 0-100 scale. usage_norm is
# still accepted (callers pass it) but intentionally unused here.
val = round(100 * (0.52 * quality + 0.25 * proven + 0.18 * reach + 0.05 * fresh))
if parity_warn:
val -= 10
if archived:
@@ -182,8 +182,9 @@ function qualityBoost(record, lexicalScore, routeBoost) {
if (!registryScore) return 0;
if (lexicalScore <= 0 && routeBoost <= 0) return 0;
const usageAdj = Math.min(18, Number(reg.usage_30d || reg.usage_count || 0) * 3);
return Math.round(registryScore * 0.9 + usageAdj);
// usage/frequency intentionally excluded from ranking — collected for analytics
// only (one past use must not pin a skill above genuinely better matches).
return Math.round(registryScore * 0.9);
}
function costRank(cost) {
@@ -219,8 +220,7 @@ const scored = index.records
.sort((a, b) =>
b.route_score - a.route_score ||
b.registry_score - a.registry_score ||
b.usage_30d - a.usage_30d ||
b.usage_count - a.usage_count ||
// usage tiebreakers removed — frequency must not affect ordering/selection.
costRank(a.cost_tier) - costRank(b.cost_tier) ||
a.path.localeCompare(b.path)
);