agentleFS
EugineKosenkoEugineKosenko/majordom/skills/token-count/SKILL.md

token-count

Skill0 starsChanged 47 days agoMITView on GitHub

Count the lexical tokens of source code, ignoring comments and whitespace, with pygments (any language it knows - Rust, PHP, Python, shell and so on), and compare the count before and after a change or between variants. The fewer tokens for the same meaning, the better (rule tokens.md). Use when the user asks how big a piece of code or a change is by tokens, asks to compare two variants of code, to check the token metric or to run token-count, or when you weigh two rewrites and the numbers can decide.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. smcllns/skills★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository7 other files it gives its agents.

The file

Files
SKILL.md

token-count

Числова оцінка коду за правилом ~/.claude/rules/tokens.md: кількість лексичних одиниць (токенів) без коментарів і пробілів. Точніша за кількість рядків чи символів. Токен — ключове слово, ідентифікатор, число, літерал (рядок чи символ) або оператор чи розділювач, який мова вважає одним неподільним (::, ->, &&); )?; — це три токени. Довжина ідентифікатора не впливає.

Коли запускати

  • Користувач просить порахувати розмір коду чи зміни в токенах або порівняти два варіанти.
  • Ти вагаєшся між двома варіантами коду, і число може вирішити (зайвий use для одного вживання, вивід типу, спільний блок замість повторів).
  • Не запускай на кожну правку: це інструмент для порівняння, а не обов'язкова перевірка.

Використання

Потрібні python3 і pygments (apt install python3-pygments); перевір python3 -c "import pygments".

S=~/.claude/skills/token-count/scripts/tokens.py
python3 $S FILE...                 # токени у файлах і сума
python3 $S --diff [REV] [PATH...]  # до/після/різниця для змінених файлів від REV (типово HEAD)
python3 $S --show FILE             # токени по одному в рядку: перевірити, як розібрано
python3 $S --lang rust -           # код зі stdin (`--lang` — назва лексера pygments)
  • --diff порівнює версію з git (REV) з робочим файлом; нові файли мають «до» = 0, видалені — «після» = 0. Запускай із каталогу репозиторію, PATH — відносно нього.
  • Порівнюй два варіанти малого фрагмента так: збережи кожен у тимчасовий файл (або подай зі stdin з --lang) і порівняй числа.
  • Org-babel: рахуй результат tangle (.rs тощо), а не .org. Файли .org, .md, .txt, .rst скрипт пропускає як прозу.

Як читати результат

  • Число корисне для порівняння однакових за змістом варіантів одним інструментом, а не як абсолютна величина. Показуй користувачу «до/після» і різницю, а не одне число.
  • Метрика не самоціль: якщо скорочення робить код незрозумілішим, скажи це поруч із числом (strctr.md, idntfrs.md).

Обмеження (підрахунок наближений)

Лексери pygments не такі точні, як компілятор. Скрипт виправляє найгрубіше: рядок — один токен; складний оператор склеюється за таблицею мови (::, ->, =>, &&, ||, <=, ..=); макрос Rust name! — два токени; число з суфіксом Rust (42u32) — один. Не виправлено, тож похибка можлива: інтерполяція в f-рядках Python, лайфтайми й сирі ідентифікатори Rust, heredoc у shell, директиви препроцесора (рахуються як один токен). Для мови без своєї таблиці береться таблиця C-подібних мов. Підозрюєш розбір — виклич --show на файлі й переглянь токени.

Чого не робити

  • Не читай сторонній код pygments чи інших пакетів: правила vendor.md; бракує знань про лексер — питай користувача.
  • Не міняй код лише заради меншого числа: спершу покажи різницю користувачу.

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.