tokencast

io.github.krulewis由 GitHub 帳號 krulewis 發布v0.1.1更新於 Oct 27, 2026

Pre-execution cost estimation for LLM agent workflows with calibration learning

已驗證STDIO僅桌面開發者工具AI 與機器學習

概覽

AI 產生的概覽

在執行 LLM 代理任務前預估 API 成本,並依回報的實際花費持續校準,讓後續估算更準確。

可以做什麼
  • 依規模、檔案數與複雜度預估任務成本,給出樂觀、預期與悲觀三段區間
  • 查看校準狀態,瀏覽歷史估算與實際花費的對照
  • 回報整場工作階段的實際成本或單一流程步驟的成本,用於校準
  • 在助理內關閉匿名遙測
適用情境
適合規劃含多次付費模型呼叫的多步驟代理工作流程、希望在動手前先掌握大致預算,或想透過回報真實花費讓估算逐步變準的情況。
執行需求
以 Python 套件形式透過 stdio 在本機執行(pip install tokencast 或 uvx);Claude Code 外掛方式需先安裝 uv。可用參數指定校準目錄與專案根目錄。未宣告需要帳號或 API 金鑰。
安裝前請注意
匿名使用遙測預設開啟並傳送至第三方服務,可用 disable_telemetry 工具、no-telemetry 參數或 TOKENCAST_TELEMETRY 環境變數關閉。回報實際花費會將歷史資料寫入本機校準目錄。估算基於啟發式規則,並非帳務保證。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 tokencast,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

[tokencast logo]

[CI] [PyPI]

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:

/plugin marketplace add krulewis/tokencast/plugin install tokencast@tokencast

The first command registers the tokencast marketplace. The second installs the plugin from it.

Prerequisites: uv must 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:

bash
pip install tokencast

Or with uvx (no install required — runs directly from PyPI):

bash
uvx tokencast

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:

json
{  "mcpServers": {    "tokencast": {      "command": "tokencast-mcp",      "args": [        "--calibration-dir", "/path/to/your/project/calibration",        "--project-dir", "/path/to/your/project"      ]    }  }}
VS Code + GitHub Copilot

Create or update .vscode/mcp.json in your project root:

json
{  "servers": {    "tokencast": {      "type": "stdio",      "command": "tokencast-mcp",      "args": [        "--calibration-dir", "/path/to/your/project/calibration",        "--project-dir", "/path/to/your/project"      ]    }  }}
Windsurf

Add to your Windsurf MCP config:

json
{  "mcpServers": {    "tokencast": {      "command": "tokencast-mcp",      "args": [        "--calibration-dir", "/path/to/your/project/calibration",        "--project-dir", "/path/to/your/project"      ]    }  }}

Full config examples are in docs/ide-configs/.

Available tools

Once configured, tokencast exposes five MCP tools in your IDE:

ToolWhat it does
estimate_costEstimate API cost for a planned task before running it
get_calibration_statusCheck whether your estimates are well-calibrated
get_cost_historyBrowse past estimates vs actuals
report_sessionReport actual cost at session end to improve calibration
report_step_costRecord the cost of a single pipeline step during a session

Example — estimate before starting work:

Estimate the cost for: size=M, files=8, complexity=high

Example — report actuals after finishing:

Report session cost: actual_cost=4.20

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_telemetry MCP tool (permanent opt-out, creates ~/.tokencast/no-telemetry)
  • Pass --no-telemetry to the MCP server command
  • Set TOKENCAST_TELEMETRY=0 in your environment

Precedence (highest to lowest):

  1. TOKENCAST_TELEMETRY=0 → always disables
  2. TOKENCAST_TELEMETRY=1 → always enables (overrides --no-telemetry and the no-telemetry file)
  3. ~/.tokencast/no-telemetry file exists → disables
  4. 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

FlagDefaultDescription
--calibration-dir PATH~/.tokencast/calibrationWhere calibration data is stored
--project-dir PATHNoneProject root for file measurement
--no-telemetryOffDisable anonymous usage telemetry (on by default)
--versionPrint version and exit

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:

bash
# Clone the repo (anywhere — it doesn't need to live inside your project)git clone https://github.com/krulewis/tokencast.git
# Install into your project (quote paths with spaces)bash tokencast/scripts/install-hooks.sh "/path/to/your-project"

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:

  1. Symlinks the skill into <project>/.claude/skills/tokencast/
  2. Adds a Stop hook for auto-learning at session end
  3. Adds a PostToolUse hook 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

  1. Infers size, file count, complexity from the plan in conversation
  2. Reads reference files for pricing and token heuristics
  3. Loads learned calibration factors (if any exist)
  4. Computes per-step token estimates using activity decomposition
  5. Applies complexity multiplier, context accumulation (K+1)/2, and cache rates
  6. Splits into Optimistic / Expected / Pessimistic bands
  7. If PR Review Loop is in scope, computes loop cost using geometric decay across N review cycles
  8. Applies calibration correction to Expected band
  9. Records the estimate for later comparison with actuals

Example output:

## tokencast estimate
Change: size=M, files=5, complexity=mediumCalibration: 1.12x from 8 prior runs
| Step                  | Model  | Optimistic | Expected | Pessimistic ||-----------------------|--------|------------|----------|-------------|| Research Agent        | Sonnet | $0.60      | $1.17    | $4.47       || Architect Agent       | Opus   | $0.67      | $1.18    | $3.97       || ...                   | ...    | ...        | ...      | ...         || TOTAL                 |        | $3.37      | $6.26    | $22.64      |

Confidence Bands

BandCache HitMultiplierMeaning
Optimistic60%0.6xBest case — focused agent work
Expected50%1.0xTypical run
Pessimistic30%3.0xWith rework loops, debugging, retries

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

python
from tokencast import estimate_cost, report_session, report_step_costfrom tokencast import get_calibration_status, get_cost_history
# Estimate before running a taskresult = estimate_cost(    {"size": "M", "files": 5, "complexity": "medium"},    calibration_dir="./calibration",)
# Report actuals at session endreport_session({"actual_cost": 4.20}, calibration_dir="./calibration")
# Check calibration healthstatus = get_calibration_status({}, calibration_dir="./calibration")
# Browse historyhistory = get_cost_history({"window": "30d"}, calibration_dir="./calibration")
# Report a single step's costreport_step_cost(    {"step_name": "Research Agent", "cost": 0.85},    calibration_dir="./calibration",)

Manual Invocation (Skill mode)

In Claude Code with SKILL.md installed, you can invoke explicitly:

/tokencast size=L files=12 complexity=high/tokencast steps=implement,test,qa/tokencast review_cycles=3/tokencast review_cycles=0

Files

SKILL.md                        — Skill definition (auto-trigger, algorithm)references/pricing.md           — Model prices, cache rates, step→model mapreferences/heuristics.md        — Token budgets, pipeline decompositions, multipliersreferences/examples.md          — Worked examples with arithmeticreferences/calibration-algorithm.md — Detailed calibration algorithm referencedocs/ide-configs/               — Per-IDE MCP config examplessrc/tokencast/                  — Core estimation engine (Python package)src/tokencast_mcp/              — MCP server (Python package)scripts/  install-hooks.sh              — One-time project setup (skill mode)  disable.sh                    — Remove from project (skill mode)  tokencast-learn.sh            — Stop hook: auto-captures actuals (skill mode)  tokencast-track.sh            — PostToolUse hook: nudges estimation after plans  sum-session-tokens.py         — Parses session JSONL for actual costs  update-factors.py             — Computes calibration factors from historycalibration/                    — Per-user local data (gitignored)  history.jsonl                 — Estimate vs actual records  factors.json                  — Learned correction factors  active-estimate.json          — Transient marker for current estimate

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_updated in references/pricing.md
  • Multi-session tasks only capture the session containing the estimate

License

MIT

來源:README.md,提交 f06e225

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分