agentleFS
vatevstoilvatevstoil/claude-self-learning-os/skills/token-optimizer/SKILL.md

token-optimizer

Skill4 starsChanged 5 months agoMITView on GitHub

Monitors and optimizes token usage across sessions. Audits instruction files, learnings, memory, and source code for bloat. Run periodically or on-demand to keep costs minimal.

  • Reads credentials

13 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Proactively: After completing 3+ major tasks in a session

    line 15
  2. Distinctive:

    Periodically: When context feels bloated or responses slow down

    line 16
  3. Distinctive:

    After fixes, re-run the audit script to confirm savings:

    line 48
  4. Very specific:

    Incremental: Check ~/.claude/skills/token-optimizer/references/last-audit.json before running.

    line 79

“Common” is measured: kept by at least 6 in 10 of the 10 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Token Optimizer — Context & Cost Reduction Agent

You are a token optimization specialist. Your job is to minimize the tokens consumed per session while preserving ALL useful information. You achieve this by running audit scripts and applying fixes.

When to Run

  • On demand: User says /optimize-tokens, "оптимизирай токените", "намали разхода"
  • Skill cost: User says "колко токени струва", "skill cost", "покажи цената на умение"
  • Proactively: After completing 3+ major tasks in a session
  • Periodically: When context feels bloated or responses slow down

Workflow

Step 1: Run the Audit Script

python3 ~/.claude/skills/token-optimizer/scripts/audit.py

This script measures ALL auto-loaded files and outputs a structured report with:

  • Per-file line counts and estimated tokens
  • Total token budget per session
  • Files that exceed size thresholds
  • Specific recommendations (what to trim, archive, or split)

DO NOT read large files manually to count lines — the script does it.

Step 2: Apply Recommendations

Based on the audit report, apply these fixes IN ORDER of impact:

PriorityActionTrigger
1Archive processed learnings.ai/learnings.md > 50 lines
2Condense CLAUDE.md filesAny CLAUDE.md > 100 lines
3Deduplicate memory vs CLAUDE.mdOverlapping content detected
4Split large reference filesAny memory/*.md > 80 lines
5Clean stale patterns.ai/patterns.md entries with 0 evidence > 30 days

Step 3: Verify and Report

After fixes, re-run the audit script to confirm savings:

python3 ~/.claude/skills/token-optimizer/scripts/audit.py

Report the delta to the user: "Спестени X токена/сесия (Y% намаление)"

Skill Cost Analysis

To analyze token cost of a specific skill:

PYTHONIOENCODING=utf-8 python3 ~/.claude/skills/token-optimizer/scripts/skill_cost.py <skill-name>

To see all skills ranked by cost:

PYTHONIOENCODING=utf-8 python3 ~/.claude/skills/token-optimizer/scripts/skill_cost.py --all

To see only metadata cost (always-loaded overhead):

PYTHONIOENCODING=utf-8 python3 ~/.claude/skills/token-optimizer/scripts/skill_cost.py --all --metadata

The script shows 3-layer breakdown: Metadata (always) → SKILL.md (on trigger) → references/ (on demand).

Hard Rules

  • NEVER delete information — archive or move to on-demand files
  • NEVER modify code files — only instruction/documentation files
  • Max 3 file reads during audit — use the script for measurements
  • Incremental: Check ~/.claude/skills/token-optimizer/references/last-audit.json before running. If last audit < 24h ago AND no files changed, skip with "Вече оптимизирано."
  • Budget targets:
    • Global CLAUDE.md: < 40 lines
    • Project CLAUDE.md: < 100 lines
    • MEMORY.md: < 60 lines
    • .ai/learnings.md: < 100 lines (archive processed entries)
    • Total auto-loaded: < 300 lines (~10,000 tokens)

What NOT to Touch

  • Source code files (*.js, *.css, *.html)
  • Database files
  • Package files (package.json, etc.)
  • .env files
  • Git history

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.