Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "turntax",
"source": "./plugins/turntax",
"description": "Measure the per-turn token cost of AI coding-agent instruction files and MCP servers, and preview safe fixes.",
"version": "0.10.0",
"version": "0.11.0",
"category": "development"
}
]
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- id: turntax
name: turntax
description: Fail when an agent's instruction files go over a per-turn token budget (--max-tokens, or maxTokens in turntax.config.json).
entry: npx --yes turntax@0.10.0
entry: npx --yes turntax@0.11.0
language: system
pass_filenames: false
always_run: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.11.0 (2026-11-09)

- A finding when a repository's Claude Code skill and command descriptions pass the skill listing budget: 30,000 characters on a 1M-token context window, as Claude Code reports it in its debug log. Past it, Claude Code drops the descriptions of the skills invoked least. turntax counts each entry as Claude Code 2.1.296 does, which matched its count for a fixture of 160 skills; user skills are left out.
- `scripts/state-of.mjs --recount <edition.json> --out <file>` counts an edition's repositories again at the commits it pinned, with the current turntax, and prints how the median, the 90th percentile and each agent move.

## 0.10.0 (2026-11-08)

- GitHub Copilot is modelled on what Copilot CLI 1.0.107 loads, checked with `scripts/observe.mjs` (62 of 62 checks), instead of the legacy VS Code Local harness. VS Code's Copilot harness shares that runtime. Counts change:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: TorutDev/turntax@v0.10.0
- uses: TorutDev/turntax@v0.11.0
with:
max-increase: 500 # optional: fail when an agent grows by more than 500 tokens per turn
# max-tokens: 8000 # optional: absolute budget
Expand All @@ -232,7 +232,7 @@ The repository is also a [pre-commit](https://pre-commit.com) hook, which fails
```yaml
repos:
- repo: https://github.com/TorutDev/turntax
rev: v0.10.0
rev: v0.11.0
hooks:
- id: turntax
args: [--max-tokens, '8000']
Expand Down
4 changes: 2 additions & 2 deletions docs/how-it-counts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In Claude Code, started at the root of the repository:

After Claude reads a file in a subfolder, that folder's `CLAUDE.md` and a rule with `paths` for it load too. With `AGENTS.md` and no `CLAUDE.md`, `AGENTS.md` loads.

On 2026-11-08 Claude Code listed the command by name with no description, in every run that day. The likely cause, not confirmed: its skill listing is capped at 1% of the context window, and past that it drops the descriptions of the least-used entries, and the account used for the run had many plugin skills. A small fixture with only that command and one skill listed both descriptions. turntax counts every description and does not apply that cap.
On 2026-11-08 Claude Code listed the command by name with no description, in every run that day. Its debug log (`--debug-file`) on 2026-11-09 gave the cause: "Skill listing over budget: 479 skills, 203121 chars > 30000 budget". The account used for the run has many plugin and user skills, so the listing was over budget before the fixture's skills were added, and Claude Code dropped descriptions of the skills invoked least. turntax counts every description and flags a repository whose own skills go over the budget (see [Claude Code](#claude-code)).

Copilot CLI did not list what its instructions say when asked, so each Copilot fixture file gives it a project code to repeat, and the skills it lists are read from the CLI's own `session.skills_loaded` event. The first run disagreed with turntax's model of the VS Code Local harness in 14 of 31 checks at the root; turntax now models what the CLI loads, described under [GitHub Copilot](#github-copilot). Copilot CLI loads repository instructions only in a folder you trust; the script passes `--trust-folder`.

Expand All @@ -54,7 +54,7 @@ Sources: [memory](https://code.claude.com/docs/en/memory), [skills](https://code
| `.claude/agents/**/*.md` | description always; body is the subagent's own prompt |
| `.claude/agents/` in a subdirectory | ignored: Claude Code finds subagents only from the launch directory up |

Claude Code caps the skill listing at 1% of the context window and drops the descriptions of the least-used skills past it; that cap is not applied. Skills with `paths` frontmatter are counted like other skills, since how they are listed is not documented. Claude Code warns at startup when the subagent descriptions together pass 15,000 tokens.
Claude Code fits the skill and command listing into 1% of the context window: 30,000 characters on a 1M-token window, as its debug log reports it, and twice that with `skillListingBudgetFraction: 0.02`. Past it, it drops the descriptions of the skills invoked least. turntax still counts every description, because user and plugin skills share the budget and which descriptions go depends on use; when the repository's own skill and command descriptions pass 30,000 characters, counted as Claude Code counts them (each entry `- name: description` and a newline, which matched its count for a fixture of 160 skills to the character, with Claude Code 2.1.296), a finding says so. User skills from `--include-user` are left out of it, though they share the real budget. Skills with `paths` frontmatter are counted like other skills, since how they are listed is not documented. Claude Code warns at startup when the subagent descriptions together pass 15,000 tokens.

Claude Code skips a `CLAUDE.md` over 4 MiB at launch and loads none of it, and from 2.1.309 gives a `CLAUDE.md` or rule in a subdirectory only its first 40,000 characters on a 200K context window (more on a 1M window). `turntax` flags a `CLAUDE.md` or `CLAUDE.local.md` over 4 MiB at the root, in `.claude/` or in your home folder, and a `CLAUDE.md`, `CLAUDE.local.md` or `.claude/rules` file over 40,000 characters in a subfolder. The docs apply the 40,000 limit to path-scoped rules and to files imported by nested files too; turntax does not check those. A subdirectory's `AGENTS.md` loads only when that subdirectory has none of `CLAUDE.md`, `.claude/CLAUDE.md` or `CLAUDE.local.md`.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turntax",
"version": "0.10.0",
"version": "0.11.0",
"description": "Measure the per-turn token cost of AI coding-agent instruction files (AGENTS.md, CLAUDE.md, Cursor, Copilot, Cline, Roo, Kiro, Windsurf and more) for every agent that reads them.",
"mcpName": "io.github.TorutDev/turntax",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions plugins/turntax/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turntax",
"version": "0.10.0",
"version": "0.11.0",
"description": "Measure the per-turn token cost of AI coding-agent instruction files (AGENTS.md, CLAUDE.md, Cursor rules and more) and MCP servers, and preview safe fixes.",
"author": {
"name": "TORUT LTD",
Expand All @@ -15,7 +15,7 @@
"mcpServers": {
"turntax": {
"command": "npx",
"args": ["-y", "turntax@0.10.0", "mcp"]
"args": ["-y", "turntax@0.11.0", "mcp"]
}
}
}
2 changes: 1 addition & 1 deletion plugins/turntax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Measures how many tokens your agent instruction files (CLAUDE.md, `.claude/rules

## What it runs and sends

The server runs `npx -y turntax@0.10.0 mcp` on your machine. npx downloads the `turntax` package from npm on first use. `package.json` and `package-lock.json` in this folder pin the same version and its one dependency, with integrity hashes. The tools read instruction files and MCP configs in the folder you audit. They do not start the MCP servers they find, do not call any vendor API, and send nothing over the network.
The server runs `npx -y turntax@0.11.0 mcp` on your machine. npx downloads the `turntax` package from npm on first use. `package.json` and `package-lock.json` in this folder pin the same version and its one dependency, with integrity hashes. The tools read instruction files and MCP configs in the folder you audit. They do not start the MCP servers they find, do not call any vendor API, and send nothing over the network.

## Install

Expand Down
8 changes: 4 additions & 4 deletions plugins/turntax/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/turntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Pins the turntax package that this plugin's MCP server runs (npx -y turntax@<version> mcp).",
"license": "MIT",
"dependencies": {
"turntax": "0.10.0"
"turntax": "0.11.0"
}
}
58 changes: 57 additions & 1 deletion scripts/state-of.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
* npm run build
* GITHUB_TOKEN=$(gh auth token) node scripts/state-of.mjs [--limit 100] [--date YYYY-MM-DD] [--out web/state/YYYY-MM.json]
* node scripts/state-of.mjs --index-only [--out web/state/YYYY-MM.json]
* GITHUB_TOKEN=$(gh auth token) node scripts/state-of.mjs --recount web/state/YYYY-MM.json --out <file outside web/state>
*
* --date reproduces an edition's selection (its selection.date): repositories pushed to in the 92 days before it.
* After writing, editions.json next to --out is rebuilt from every YYYY-MM.json in that folder;
* --index-only only rebuilds it, without the network or a token.
* --recount counts an edition's repositories again at the commits it pinned, with this turntax, and prints how the
* headline numbers move: a change between editions can come from the rules as well as from the repositories.
*
* Talks only to api.github.com (with the token) and raw.githubusercontent.com (without it).
* Every file is read at the default branch's head commit, pinned by SHA.
Expand Down Expand Up @@ -49,8 +52,10 @@ const { values: args } = parseArgs({
date: { type: 'string' },
out: { type: 'string' },
'index-only': { type: 'boolean', default: false },
recount: { type: 'string' },
},
});
if (args.recount && !args.out) fail('--recount needs --out, outside web/state: a recount is not an edition.');
const LIMIT = Number(args.limit);
if (!Number.isInteger(LIMIT) || LIMIT <= 0) fail('--limit must be a positive integer.');
const DATE = args.date ?? new Date().toISOString().slice(0, 10);
Expand Down Expand Up @@ -232,7 +237,7 @@ async function scan(item) {

async function scanRepo(item) {
const fullName = item.full_name;
const sha = (await api(`/repos/${fullName}/commits/${encodeURIComponent(item.default_branch)}`, 'application/vnd.github.sha')).trim();
const sha = item.sha ?? (await api(`/repos/${fullName}/commits/${encodeURIComponent(item.default_branch)}`, 'application/vnd.github.sha')).trim();
const tree = await api(`/repos/${fullName}/git/trees/${sha}?recursive=1`);
if (tree.truncated) return { status: 'truncated' };

Expand Down Expand Up @@ -466,6 +471,7 @@ function summarize(repos) {
}

async function main() {
if (args.recount) return recount(args.recount);
const generatedAt = new Date().toISOString();
const version = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf8')).version;
const engineCommit = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8' }).trim();
Expand Down Expand Up @@ -562,6 +568,56 @@ async function main() {
writeIndex(dirname(OUT));
}

/** Counts an edition's repositories again at their pinned commits and prints how the headline numbers move. */
async function recount(file) {
const before = JSON.parse(readFileSync(file, 'utf8'));
if (resolve(dirname(OUT)) === resolve(ROOT, 'web/state')) fail('--out must be outside web/state: a recount is not an edition.');
const items = before.repos.map((r) => ({ full_name: r.full_name, stargazers_count: r.stars, language: r.language, default_branch: r.default_branch, sha: r.sha }));
const results = await mapLimited(items, REPO_CONCURRENCY, scan);
const repos = [];
const failed = [];
const empty = [];
results.forEach((r, i) => {
if (r.status === 'qualifying') repos.push({ rank: before.repos[i].rank, ...r.record });
// Read, but no agent loads anything from it any more: a change the rules made.
else if (r.status === 'none') empty.push(items[i].full_name);
else failed.push(`${items[i].full_name} (${r.status}${r.reason ? `: ${r.reason}` : ''})`);
});
const summary = summarize(repos);
for (const r of repos) delete r._rootPair;
const version = JSON.parse(readFileSync(resolve(ROOT, 'package.json'), 'utf8')).version;
mkdirSync(dirname(OUT), { recursive: true });
writeFileSync(OUT, `${JSON.stringify({ recountOf: before.edition, countedBefore: before.turntaxVersion, turntaxVersion: version, repos, summary }, null, 1)}\n`);

const byName = new Map(before.repos.map((r) => [r.full_name, r]));
const perTurn = (r) => (r.maxPerTurnLinksOnce ?? r.maxPerTurn).o200k;
// Both sides over the repositories read again, so a repository that could not be read does not move the numbers.
const pick = (list) => ({ median: percentile(list.map(perTurn), 0.5), p90: percentile(list.map(perTurn), 0.9) });
const was = pick(repos.map((r) => byName.get(r.full_name)));
const now = pick(repos);
const moved = repos.map((r) => ({ name: r.full_name, was: perTurn(byName.get(r.full_name)), now: perTurn(r) })).filter((m) => m.was !== m.now);
// Per agent: how many repositories each agent loads more or less for.
const agents = {};
for (const r of repos) {
const old = byName.get(r.full_name).agents;
for (const id of new Set([...Object.keys(old), ...Object.keys(r.agents)])) {
const d = (r.agents[id] ?? 0) - (old[id] ?? 0);
if (!d) continue;
const a = (agents[id] ??= { up: 0, down: 0, tokens: 0 });
a[d > 0 ? 'up' : 'down']++;
a.tokens += d;
}
}
log(`Recount of ${before.edition} (counted with ${before.turntaxVersion}) with ${version}: ${repos.length} of ${items.length} repositories read again.`);
if (failed.length) log(`Not read, and left out of the comparison: ${failed.join(', ')}`);
if (empty.length) log(`No longer counted for any agent with these rules: ${empty.join(', ')}`);
log(`Largest per-turn total, median ${was.median} -> ${now.median}, 90th percentile ${was.p90} -> ${now.p90}.`);
log(`${moved.length} repositories changed: ${moved.filter((m) => m.now > m.was).length} up, ${moved.filter((m) => m.now < m.was).length} down.`);
for (const [id, a] of Object.entries(agents).sort((x, y) => Math.abs(y[1].tokens) - Math.abs(x[1].tokens)))
log(` ${before.agentNames?.[id] ?? id}: ${a.up} up, ${a.down} down, ${a.tokens > 0 ? '+' : ''}${a.tokens} tokens in all`);
log(`Wrote ${OUT}.`);
}

/** The figures of one edition that the trend view compares; per-turn sizes count a symlinked file once, as the report does. */
function trendOf(edition, file, data) {
const s = data.summary;
Expand Down
4 changes: 2 additions & 2 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"source": "github"
},
"websiteUrl": "https://torutdev.github.io/turntax/",
"version": "0.10.0",
"version": "0.11.0",
"packages": [
{
"registryType": "npm",
"identifier": "turntax",
"version": "0.10.0",
"version": "0.11.0",
"runtimeHint": "npx",
"packageArguments": [
{
Expand Down
26 changes: 26 additions & 0 deletions src/core/advice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function buildAdvice(units: LoadedUnit[], files: RepoFile[], opts: Advice
const advice: Advice[] = [
...misconfigured(units),
...sizeLimits(units, files),
...listingBudgets(units),
...duplicates(units),
...contradictions(units, raw),
...sections(repo, opts.sectionTokens ?? DEFAULT_SECTION_TOKENS, raw, opts.exists),
Expand Down Expand Up @@ -173,6 +174,31 @@ function sizeLimits(units: LoadedUnit[], files: RepoFile[]): Advice[] {
return out;
}

/** A tool's listed skill descriptions over the budget it fits them into. */
function listingBudgets(units: LoadedUnit[]): Advice[] {
const out: Advice[] = [];
for (const tool of TOOLS) {
const budget = tool.listingBudget;
if (!budget) continue;
// The repository's own skills: user and plugin skills share the budget, but a finding on a repository file must be
// about the repository.
const listed = units.filter((u) => !u.scope && u.tool === tool.id && u.part === 'description' && u.mode === 'always' && budget.pattern.test(u.path));
const chars = listed.reduce((n, u) => n + u.text.length + budget.perEntry, 0);
if (chars <= budget.chars) continue;
const largest = [...listed].sort((a, b) => b.text.length - a.text.length);
out.push({
kind: 'size-limit',
severity: 'high',
tools: [tool.id],
paths: largest.slice(0, 3).map((u) => u.path),
message: `${listed.length} skill and command descriptions take about ${chars.toLocaleString('en-US')} characters, over the listing budget of ${budget.chars.toLocaleString('en-US')}. ${budget.text} Source: ${budget.source}`,
savingTokens: null,
savingNote: 'Fewer tokens load than counted, but skills past the budget lose the words Claude matches requests on; shorten descriptions or turn skills off.',
});
}
return out;
}

/** Lowercased, whitespace-collapsed instruction lines long enough to be meaningful. */
function normalizedLines(text: string): Map<string, string> {
const out = new Map<string, string>();
Expand Down
Loading
Loading