Tokscale:跨平台AI编码助手令牌追踪与成本优化工具
Tokscale is a comprehensive monitoring tool that tracks AI coding assistant token usage across multiple platforms through a high-performance CLI and visualization dashboard, enabling developers to optimize costs and analyze consumption patterns with real-time pricing data and detailed breakdowns. (Tokscale是一款全面的监控工具,通过高性能CLI和可视化仪表盘追踪跨多个平台的AI编码助手令牌使用情况,使开发者能够利用实时定价数据和详细分解来优化成本和分析消费模式。)
Introduction to Tokscale: The AI Coding Assistant Token Tracker (Tokscale简介:AI编码助手令牌追踪器)
Tokscale is a high-performance CLI tool and visualization dashboard designed for tracking AI coding assistant token usage and costs across multiple platforms. It provides developers with granular insights into their AI consumption patterns, enabling data-driven optimization of development workflows.
Tokscale是一款高性能CLI工具命令行界面工具,允许用户通过文本命令与计算机系统交互,通常用于开发、系统管理和自动化任务。和可视化仪表盘,专为跨多个平台追踪AI编码助子的令牌使用量和成本而设计。它为开发者提供细粒度的AI消费模式洞察,支持数据驱动的开发工作流优化。
Core Architecture and Technical Implementation (核心架构与技术实现)
Native Rust Core with Zig Integration (原生Rust核心与Zig集成)
According to the project documentation, Tokscale employs a hybrid architecture combining Rust's performance with Zig's native rendering capabilities. The Rust core handles all parsing and aggregation operations, achieving approximately 10x faster processing through parallel file scanning and SIMD单指令多数据流,一种并行处理技术,允许单个指令同时处理多个数据元素,显著提高数据处理性能。 JSON parsing techniques.
根据项目文档,Tokscale采用混合架构,结合了Rust的性能与Zig的原生渲染能力。Rust核心处理所有解析和聚合操作,通过并行文件扫描和SIMD单指令多数据流,一种并行处理技术,允许单个指令同时处理多个数据元素,显著提高数据处理性能。 JSON解析技术实现约10倍的处理速度提升。
Multi-Platform Data Collection Framework (多平台数据收集框架)
Tokscale supports comprehensive monitoring across seven major AI development platforms:
- OpenCode - Data location:
/.local/share/opencode/storage/message/ (数据位置:/.local/share/opencode/storage/message/) - Claude Code - Data location:
/.claude/projects/ (数据位置:/.claude/projects/) - Codex CLI - Data location:
/.codex/sessions/ (数据位置:/.codex/sessions/) - Gemini CLI - Data location:
/.gemini/tmp/*/chats/ (数据位置:/.gemini/tmp/*/chats/) - Cursor IDE - API synchronization via
/.config/tokscale/cursor-cache/ (通过/.config/tokscale/cursor-cache/进行API同步) - Amp (AmpCode) - Data location:
/.local/share/amp/threads/ (数据位置:/.local/share/amp/threads/) - Droid (Factory Droid) - Data location:
/.factory/sessions/ (数据位置:/.factory/sessions/)
Key Features and Capabilities (关键特性与功能)
Interactive Terminal User Interface (交互式终端用户界面)
The TUI终端用户界面,在命令行环境中提供的图形化交互界面,结合了CLI的效率和GUI的直观性。 mode, powered by OpenTUI's native Zig modules, provides zero-flicker rendering with four comprehensive views:
- Overview: Combined chart visualization with top model statistics (概览:结合图表可视化与顶级模型统计)
- Models: Detailed breakdown of AI model usage patterns (模型:AI模型使用模式的详细分解)
- Daily: Temporal analysis of token consumption (每日:令牌消耗的时间分析)
- Stats: GitHub-style contribution graph with 9 color themes (统计:具有9种颜色主题的GitHub风格贡献图)
Real-Time Pricing Integration (实时定价集成)
Tokscale implements a sophisticated pricing lookup system that fetches current pricing data from LiteLLM一个统一的AI模型调用接口,支持多种大型语言模型,提供标准化的API和定价信息查询功能。 with 1-hour disk caching. The system includes automatic fallback to OpenRouter for new models and supports tiered pricing models with cache token discounts.
Tokscale实现了复杂的定价查询系统,从LiteLLM一个统一的AI模型调用接口,支持多种大型语言模型,提供标准化的API和定价信息查询功能。获取当前定价数据并采用1小时磁盘缓存。该系统包含对新模型的自动OpenRouter回退,并支持具有缓存令牌折扣的分层定价模型。
Advanced Filtering and Data Analysis (高级过滤与数据分析)
Developers can apply multiple filtering dimensions:
- Platform-specific filtering (e.g., --opencode, --claude) (平台特定过滤,例如--opencode、--claude)
- Temporal filtering with date ranges and year-based selection (具有日期范围和基于年份选择的时间过滤)
- Real-time sorting by cost, name, or token count (按成本、名称或令牌数量实时排序)
- JSON export capabilities for external visualization tools (用于外部可视化工具的JSON导出功能)
Installation and Deployment (安装与部署)
Quick Start Implementation (快速启动实现)
# Install Bun runtime (if not already installed)
curl -fsSL https://bun.sh/install | bash
# Execute Tokscale directly via bunx
bunx tokscale@latest
# Light mode execution (without OpenTUI)
bunx tokscale@latest --light
Development Environment Setup (开发环境设置)
For local development or source-based building:
# Clone the repository
git clone https://github.com/junhoyeo/tokscale.git
cd tokscale
# Install dependencies
bun install
# Run CLI in development mode
bun run cli
Visualization and Social Features (可视化与社交功能)
Frontend Visualization Dashboard (前端可视化仪表盘)
The web-based visualization component provides interactive 2D and 3D contribution graphs, enabling developers to visualize their AI consumption patterns across temporal dimensions. The frontend runs independently and can be accessed through standard web browsers.
基于Web的可视化组件提供交互式2D和3D贡献图,使开发者能够跨时间维度可视化其AI消费模式。前端独立运行,可通过标准Web浏览器访问。
Social Platform Integration (社交平台集成)
Tokscale includes a social platform feature that enables:
- Usage data sharing and public profile creation (使用数据共享和公共配置文件创建)
- Competitive leaderboards based on token consumption metrics (基于令牌消耗指标的竞争性排行榜)
- Data validation mechanisms for integrity assurance (用于完整性保证的数据验证机制)
Technical Considerations and Best Practices (技术考虑与最佳实践)
Data Retention and Privacy (数据保留与隐私)
According to the implementation details, Tokscale maintains session data with configurable retention policies. All data processing occurs locally unless explicitly shared to the social platform, ensuring developer privacy and data sovereignty.
根据实现细节,Tokscale以可配置的保留策略维护会话数据。除非明确共享到社交平台,否则所有数据处理都在本地进行,确保开发者隐私和数据主权。
Performance Optimization Strategies (性能优化策略)
The architecture employs several optimization techniques:
- Native binary pre-building for installation efficiency (用于安装效率的原生二进制预构建)
- Parallel file system scanning algorithms (并行文件系统扫描算法)
- Memory-efficient JSON parsing with SIMD单指令多数据流,一种并行处理技术,允许单个指令同时处理多个数据元素,显著提高数据处理性能。 instructions (使用SIMD单指令多数据流,一种并行处理技术,允许单个指令同时处理多个数据元素,显著提高数据处理性能。指令的内存高效JSON解析)
- Intelligent caching mechanisms for pricing data (定价数据的智能缓存机制)
Future Development and Ecosystem Integration (未来发展与生态系统集成)
Expansion Roadmap (扩展路线图)
The project maintains an active development roadmap focusing on:
- Additional AI platform integrations (额外的AI平台集成)
- Enhanced visualization capabilities (增强的可视化能力)
- Advanced analytics and predictive features (高级分析和预测功能)
- Enterprise-grade deployment options (企业级部署选项)
Community Contribution Framework (社区贡献框架)
Tokscale operates under open-source principles with clear contribution guidelines, encouraging community involvement in feature development, bug reporting, and documentation improvement.
Tokscale在开源原则下运作,具有清晰的贡献指南,鼓励社区参与功能开发、错误报告和文档改进。
Frequently Asked Questions (常见问题)
Tokscale支持哪些AI开发平台?
Tokscale目前支持OpenCode、Claude Code、Codex CLI、Cursor IDE、Gemini CLI、Amp (AmpCode)和Droid (Factory Droid)七个主要平台,通过读取各平台的本地数据文件实现监控。
如何安装和快速启动Tokscale?
需要先安装Bun运行时环境,然后通过
bunx tokscale@latest命令直接运行。系统会自动下载预构建的二进制文件,无需额外配置即可使用完整TUI终端用户界面,在命令行环境中提供的图形化交互界面,结合了CLI的效率和GUI的直观性。功能。Tokscale的定价数据如何获取和更新?
系统从LiteLLM一个统一的AI模型调用接口,支持多种大型语言模型,提供标准化的API和定价信息查询功能。获取实时定价数据,并采用1小时磁盘缓存机制。对于新模型,会自动回退到OpenRouter数据源,确保定价信息的准确性和及时性。
数据隐私和安全如何保障?
所有数据处理都在本地进行,除非用户明确执行
bunx tokscale@latest submit命令提交数据到排行榜。社交功能采用可选参与模式,充分尊重用户数据主权。如何为Tokscale项目做出贡献?
项目采用开源模式,开发者可以通过GitHub提交PR参与功能开发、修复bug或改进文档。项目维护者提供了完整的开发环境设置指南和代码规范。
版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。
文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。
若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。