
tokencast
io.github.krulewis由 GitHub 账号 krulewis 发布v0.1.1更新于 Oct 27, 2026
Pre-execution cost estimation for LLM agent workflows with calibration learning
概览
在运行 LLM 智能体任务之前预估 API 成本,并根据上报的实际花费持续校准,使后续估算更准确。
- 可以做什么
- 根据规模、文件数和复杂度预估任务成本,给出乐观、预期与悲观三档区间
- 查看校准状态,浏览历史估算与实际花费的对比
- 上报整场会话的实际成本或单个流水线步骤的成本,用于校准
- 在助手内关闭匿名遥测
- 适用场景
- 适合规划包含多次付费模型调用的多步骤智能体工作流、希望在动手前先了解大致预算,或希望通过上报真实花费让估算逐步变准的场景。
- 运行要求
- 以 Python 包形式通过 stdio 在本机运行(pip install tokencast 或 uvx);Claude Code 插件方式需要先安装 uv。可通过参数指定校准目录与项目根目录。未声明需要账号或 API 密钥。
安装
在 SourceWeft 中
- 打开 控制台中的 tokencast,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
tokencast
Pre-execution cost estimation for LLM agent workflows. Get a cost estimate before running any agent task, then let tokencast learn from actuals to improve accuracy over time.
Available as a Claude Code plugin (recommended — one command delivers everything) or as an MCP server for Cursor, VS Code + Copilot, and Windsurf.
Installation
Claude Code (Recommended)
Install tokencast as a Claude Code plugin — delivers the MCP server, calibration hooks, and estimation skill in two commands:
The first command registers the tokencast marketplace. The second installs the plugin from it.
Prerequisites:
uvmust be installed for the MCP server to function. Install with:curl -LsSf https://astral.sh/uv/install.sh | sh
This delivers:
- MCP server (
estimate_cost,get_calibration_status,get_cost_history,report_session,report_step_cost) - Calibration hooks (auto-learning at session end, mid-session cost warnings, agent timeline tracking)
- SKILL.md (estimation algorithm auto-trigger after plans)
Calibration data is stored in ~/.tokencast/calibration/ (global across projects, preserved on uninstall).
Scope options:
--scope user(recommended — installs globally for all projects) or--scope project(per-project only).
Other IDEs (MCP Server)
Install the package:
Or with uvx (no install required — runs directly from PyPI):
Configure your IDE — replace /path/to/your/project with your actual project path in the config snippets below.
Cursor
Create or update .cursor/mcp.json in your project root:
VS Code + GitHub Copilot
Create or update .vscode/mcp.json in your project root:
Windsurf
Add to your Windsurf MCP config:
Full config examples are in docs/ide-configs/.
Available tools
Once configured, tokencast exposes five MCP tools in your IDE:
Example — estimate before starting work:
Example — report actuals after finishing:
Telemetry
tokencast includes opt-out anonymous usage telemetry. It is on by default — data is collected unless you explicitly disable it.
What is collected: session count, mean accuracy ratio, calibrated factor count, client name, framework, tool name, package version. What is NOT collected: project names, file paths, cost amounts, or any personal data.
To disable:
- Call the
disable_telemetryMCP tool (permanent opt-out, creates~/.tokencast/no-telemetry) - Pass
--no-telemetryto the MCP server command - Set
TOKENCAST_TELEMETRY=0in your environment
Precedence (highest to lowest):
TOKENCAST_TELEMETRY=0→ always disablesTOKENCAST_TELEMETRY=1→ always enables (overrides--no-telemetryand the no-telemetry file)~/.tokencast/no-telemetryfile exists → disables- Default (no flags, no env var) → enabled
To delete your install ID: rm ~/.tokencast/install_id.
Data is sent to PostHog (US region). A random UUID is generated locally as your install ID — it contains no personal information. See the wiki for full details.
MCP Server Flags
Claude Code Skill (Legacy)
The Claude Code plugin (recommended) delivers everything in one command. Use this only if you prefer the SKILL.md workflow without the plugin system.
If you use Claude Code and prefer the skill-based (SKILL.md) workflow, you can install tokencast as a Claude Code skill instead:
Paths with spaces: Always wrap the project path in quotes. Without them the install script will fail on paths like
/Volumes/Macintosh HD2/....
This does three things:
- Symlinks the skill into
<project>/.claude/skills/tokencast/ - Adds a
Stophook for auto-learning at session end - Adds a
PostToolUsehook to nudge estimation after planning agents
The SKILL.md workflow is Claude Code-specific. The MCP server works in any MCP-compatible client and is the recommended path for new users.
How It Works
- Infers size, file count, complexity from the plan in conversation
- Reads reference files for pricing and token heuristics
- Loads learned calibration factors (if any exist)
- Computes per-step token estimates using activity decomposition
- Applies complexity multiplier, context accumulation
(K+1)/2, and cache rates - Splits into Optimistic / Expected / Pessimistic bands
- If PR Review Loop is in scope, computes loop cost using geometric decay across N review cycles
- Applies calibration correction to Expected band
- Records the estimate for later comparison with actuals
Example output:
Confidence Bands
Calibration
Calibration is fully automatic once you report actuals:
- 0-2 sessions: No correction applied. "Collecting data" status.
- 3-10 sessions: Global correction factor via trimmed mean of actual/expected ratios (trim_fraction=0.1).
- 10+ sessions: EWMA with recency weighting. Per-size-class factors activate when a class has 3+ samples.
- Outlier filtering: Sessions with actual/expected ratio >3.0x or <0.2x are excluded from calibration.
Calibration data lives in ~/.tokencast/calibration/ (gitignored, local to each user).
Python API
Manual Invocation (Skill mode)
In Claude Code with SKILL.md installed, you can invoke explicitly:
Files
Limitations
- Pipeline step names reflect a default workflow — map your own steps to the closest defaults. Formulas are pipeline-agnostic (see
references/heuristics.md) - Heuristics assume typical 150-300 line source files
- Calibration requires 3+ completed sessions before corrections activate
- Pricing data embedded; check
last_updatedin references/pricing.md - Multi-session tasks only capture the session containing the estimate
License
MIT
来源:README.md,提交 f06e225
工具
0版本历史
1- v0.1.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分