
turntax
io.github.TorutDev由 GitHub 帳號 TorutDev 發布v0.9.0更新於 Nov 7, 2026
Per-turn token cost of AGENTS.md, CLAUDE.md and other agent instruction files, with safe fixes.
概覽
唯讀 MCP 伺服器,稽核儲存庫中代理指示檔每輪消耗的 token,並預覽安全修正。
- 可以做什麼
- 稽核資料夾:報告各支援的編碼代理每輪從 AGENTS.md、CLAUDE.md 等指示檔載入多少 token,依代理與檔案分行並提供費用估算
- 預覽修正:以 diff 形式顯示安全修正(重複行、可下移或過大的章節、設定錯誤的規則),不寫入任何檔案
- 讀取設定:比照命令列讀取 turntax.config.json 中的工具、模型、預算與忽略設定
- 適用情境
- 當你維護 AGENTS.md、CLAUDE.md 等指示檔,想讓助理在對話中說明它們每輪的成本以及可從哪裡精簡,而不改動檔案時使用。
- 執行需求
- 以 stdio 在本機執行,通常透過 npx 啟動,因此需要 Node.js。未宣告帳號、API 金鑰或環境變數;離線運作,不啟動 MCP 伺服器,也不呼叫廠商 API。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 turntax,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
turntax
Coding agents re-send their instruction files with every turn. turntax measures that fixed per-turn cost for a repository, for every agent that reads it, and shows where to cut it.
Try it in the browser, with nothing uploaded: https://torutdev.github.io/turntax/ — drop a folder or enter a public GitHub repository. Links like https://torutdev.github.io/turntax/?repo=owner/name open straight to that repository's report.
State of agent instruction files: what turntax finds in 100 popular repositories, a new edition every month with pinned commits and the script to reproduce it (scripts/state-of.mjs).
Set up the GitHub Action and a config in one command:
Supported agents
Each agent's documented loading rules decide what is sent on every turn, what loads only when the agent works in a folder or touches a matching file, and what is ignored.
Where an agent reads the same skill name from two folders, it is counted once, in the order the agent documents (or an assumed order, noted for that agent).
Agents that load exactly the same files share one row in the report (files loaded only as a /command, which cost nothing per turn, do not split a row):
(Excerpt of the output for test/fixtures/mixed with --models gpt-6.1-sol.)
What it counts, and how
Claude's tokenizer is not public, and Anthropic's docs note that newer Claude models produce noticeably more tokens than older ones for the same text. turntax never shows an OpenAI count as a Claude or Gemini number: without a key those rows say "needs API key". The o200k column is a labelled reference count for every file.
Cost per N turns = tokens per turn × N × input price. The "cached" column assumes every turn reads the context from the prompt cache. Prices come from a dated table with a source link per model (turntax --list-models); pass --prices my-prices.json to use your own.
See docs/how-it-counts.md for the loading rules per agent and their sources.
Advice
All checks are deterministic. Each one shows an estimated saving in o200k tokens per turn.
- duplicate: identical lines in two files. A per-turn saving only when one tool loads both; otherwise flagged as drift risk.
- contradiction: conflicting rules reaching the same agent (package manager, indentation, quotes, semicolons).
- scopable-section: a section mostly about one directory that could load only there (nested file, path-scoped rule,
applyTo). - oversized-section: a large always-loaded section that could become an on-demand skill.
- size-limit: documented limits (CLAUDE.md under 200 lines, Codex's 32 KiB cut-off, Windsurf's 12,000 characters per rule and 6,000 for global rules, Cursor's 500 lines, Factory's 80,000 characters, Augment's 49,512 characters).
- misconfigured: files a tool ignores, such as
.mdfiles in.cursor/rulesor Windsurf rules without atrigger. - stale-reference: referenced files or
npm runscripts that no longer exist. - non-english: non-English sections. The token multiplier is measured only against an English version you supply (
--english CLAUDE.md=CLAUDE.en.md) or, if you opt in, a Claude translation (--translate).
Fixing
--fix handles four kinds of advice:
- duplicate: removes lines from a file when every agent that reads the file also reads the same lines every turn from another file. Skill, command and subagent files are left whole. A
CLAUDE.mdthat repeats at least 80% of the lines of theAGENTS.mdnext to it, at least 3 of them full sentences, and every file it imports, keeps only its own lines and imports the rest with@AGENTS.md, as Claude Code's docs suggest; agents that read both stop paying for the copy, and the summary says how much any agent now reads on top. - scopable-section: moves a section into the folder it is about: the same file name there (
packages/api/CLAUDE.md), a nestedAGENTS.md, or a Claude Code rule withpaths:. The folder the section is about must already exist, and sections with@importsor relative links stay put. A section moves together with its subsections. - oversized-section: moves a large procedure (a section of at least
--section-tokens, 600 by default, whose heading names a release, deploy, setup or similar procedure, or that is mostly numbered steps; each subsection must pass too) into a new skill,.claude/skills/<name>/SKILL.mdfor Claude Code or.agents/skills/<name>/SKILL.mdfor Codex, and leaves the heading with a one-line pointer. Only the skill's name and description load every turn. Many agents now read one or both folders, but not all of them do (Zed reads only.agents/skills, for example), so by default this fix is often refused;--toolslimits the check to the agents you use. - misconfigured: renames
.mdfiles in.cursor/rulesto.mdc.
Before a fix is kept, the files are classified again with the change applied: every agent must still read every line it read before, including files reached through @imports, and as often as before. The exceptions are moved text: a section moved into a folder may load only when the agent works there, and a procedure moved into a skill only when the skill is used. Otherwise the fix is skipped and the reason is printed. A moved section can reach agents that did not read it before (a nested AGENTS.md is read by more agents than a CLAUDE.md); the summary names them. By default that check covers every supported agent, so a section of AGENTS.md usually stays where it is, because some agents read only the root file. --tools codex,claude-code limits the check to the agents you use.
In preview the diff is on stdout and works with git apply, and the summary is on stderr; with --write the summary is on stdout. --write checks that no file changed since it was read and writes nothing if one did. Symlinked files, their targets and files in symlinked folders are never changed. Contradictions and stale references need a person to decide, so --fix leaves them alone. Files that are also documents for people (DESIGN.md, CONTEXT.md, agents.md, Agents.md, Claude.md) are never changed, and no file is created whose name differs from one of them only by case.
The web page shows the same fixes for any repository you load, with a downloadable fix.patch.
Config file
Put defaults in turntax.config.json in the audited folder (or pass --config <file>). Command-line flags override it.
Keys: tools, models, turns, maxTokens, maxIncrease (applies only with --compare or --baseline), sectionTokens, and ignore: globs of instruction files to leave out, relative to the audited folder (* and ? within a folder name, ** across folders, a trailing / for a whole folder). Ignored files are also left out of --compare and are never changed by --fix. Unknown keys and ids are errors.
MCP servers
Every MCP server an agent starts adds its tool definitions (names, descriptions, input schemas) to the context. turntax reads the agents' MCP configs and lists the servers each agent starts:
A server name an agent finds in several configs is counted once, by the agent's documented precedence (or config order, marked as assumed); the other copies are listed as overridden. Tool filters in the configs (Codex enabled_tools/disabled_tools, Gemini includeTools/excludeTools, Factory enabledTools/disabledTools, Copilot tools, Kiro, Roo and Windsurf disabledTools) are applied.
Counting the tool definitions needs the servers running, so it is opt-in:
--mcp starts each stdio server with the command from its config (in the repository folder; environment variables are expanded into commands, URLs and headers the repository config defines, as the agents themselves do) and connects to streamable HTTP servers, asks for tools/list, and counts the definitions as JSON with o200k. A server several agents share is started once. Environment variables in the config (${VAR}, ${VAR:-default}, ${env:VAR}, {env:VAR}, ${workspaceFolder}) are expanded; servers that need a VS Code ${input:...} prompt, legacy SSE and WebSocket servers and servers that fail or time out (--mcp-timeout, default 30 s) are listed with the reason and not counted.
Claude Code defers MCP tool definitions by default (tool search): only the tool names are in context until a tool is used, so its row counts the names and shows the full size separately. A server with alwaysLoad: true, or a tool marked _meta["anthropic/alwaysLoad"], is counted in full. Server instructions load at the start of every session and are counted for Claude Code (cut at 4,096 characters, as Claude Code does), Gemini CLI, Codex and Kilo Code, whose docs say they reach the context.
MCP tokens are an o200k estimate and are not included in the model cost columns.
User-level files
Agents also read instruction files from your home directory in every project. --include-user adds them in a separate user/turn column and a total:
It reads only the locations the agents document (the full list, per agent, is in docs/how-it-counts.md): for example ~/.claude/, ~/.codex/AGENTS.md, ~/.agents/, ~/.gemini/, ~/.copilot/, ~/.cursor/skills, Windsurf's and Devin's global_rules.md and ~/.config/devin/, Cline's global rules, ~/.roo/, ~/.kiro/, ~/.junie/, ~/.config/goose/, ~/.config/amp/, ~/.config/opencode/, ~/.config/zed/AGENTS.md, ~/.factory/, ~/.augment/, ~/.config/kilo/, ~/.warp/ and ~/.trae/skills, plus the user MCP configs above. Contradictions and duplicates between user-level and repository files are reported. User-level files never count toward the badge or --max-tokens, so the result does not depend on who runs it.
Comparing with a baseline
The comparison covers repository instruction files (o200k), per agent and per file, and lists MCP servers that were added or removed. It never changes the working tree.
GitHub Action
The repository is also an Action, listed on the GitHub Marketplace; npx turntax init writes this workflow and a turntax.config.json for you. On pull requests it compares with the base branch, posts one comment (updated on every push), writes the report to the job summary and marks findings on the lines they are about in the pull request's changed files (GitHub shows up to 10 warnings and 10 notices per step):
The comment opens with a table of the change per agent and per file. When --fix has safe fixes, it says how many and how many tokens they save, with the diff folded; the full report is folded below. A turntax.config.json in the repository is read as well. Pull requests from forks get a read-only token, so the comment step is skipped there; the job summary still has the report.
pre-commit
The repository is also a pre-commit hook, which fails a commit when an agent goes over a budget. Set the budget with args, or with maxTokens in turntax.config.json; without one the hook always passes. It runs npx turntax@<version>, so it needs Node.js 22 or later on your PATH, and it does not run on pre-commit.ci, which has no system hooks.
Options
When a selected model's price was checked more than 90 days ago, turntax says so on stderr; check the source or pass --prices.
Agents and MCP
turntax mcp (MCP Registry: io.github.TorutDev/turntax) is a read-only MCP server with two tools: audit (the report for a folder) and fix_preview (the --fix diff, never written). It reads turntax.config.json like the CLI and does not start MCP servers or call vendor APIs.
For Cursor and clients with an mcpServers map, add { "mcpServers": { "turntax": { "command": "npx", "args": ["-y", "turntax", "mcp"] } } } to their MCP config (VS Code's .vscode/mcp.json calls the map servers). On native Windows, run it through cmd /c npx -y turntax mcp if your client cannot start npx directly.
This repository is also a Claude Code plugin marketplace. The plugin adds the server and a /turntax:context-tax command:
VS Code
vscode/ is a VS Code extension on the same engine: the largest per-turn cost of the open folder in the status bar, a line above each instruction file with its tokens per turn and the agents that load it, findings in the Problems panel, the report as a Markdown preview, and safe fixes shown as diffs and written only when you choose Apply. It is offline and uses the folder's turntax.config.json; its one setting, turntax.codeLens, turns the line above each file off.
Install it from the VS Code Marketplace or, for Cursor, Windsurf and VSCodium, Open VSX, or run:
Privacy
Offline by default: no network calls, no telemetry. File contents are sent only when you pass --claude-api, --gemini-api or --translate, and only to that vendor's API. Keys are read from environment variables and sent only in request headers.
--mcp runs the commands in the MCP configs it finds and connects to the configured HTTP servers, as the agents themselves would. Run it only on repositories whose configs you trust. turntax prints each command before starting it. --include-user reads files in your home directory and never sends them anywhere. --fix --write is the only option that changes files, and only repository files.
Web page
web/ is a static page that runs the same engine in the browser with the offline tokenizer only. Drop a repository folder or paste files; nothing is uploaded.
It can also load a public GitHub repository: it lists the files with the GitHub API (api.github.com, unauthenticated, 60 requests per hour) and downloads only the instruction files, and files they @import, from raw.githubusercontent.com. Those are the only network requests the page makes, and only when you load a repository or open a ?repo= link.
Badge
The badge shows the largest always-loaded total among the tools found, counted with o200k_base: repository files plus measured project MCP tools, never user-level files.
Limits
- Assumes the agent starts at the repository root. User-level files are counted only with
--include-user; rules kept in an app's settings or a team dashboard (Cursor user rules, Copilot organization instructions) are not counted. - Counts instruction files and, with
--mcp, MCP tool definitions; not the agent's own system prompt or built-in tools. - Loading rules change. Each rule cites the vendor page and the date it was checked; please open an issue when one is out of date.
Contributing
Loading rules and prices go out of date. Corrections with a link to the vendor's page are the most useful contribution; see CONTRIBUTING.md.
License
MIT
來源:README.md,提交 9680ad9
工具
0版本歷史
6- v0.9.0最新Nov 7, 2026
- v0.8.0Nov 3, 2026
- v0.7.2Oct 25, 2026
- v0.7.1Oct 18, 2026
- v0.7.0Oct 17, 2026
- v0.6.1Oct 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分