pcusage
v1.2.0
Published
Enhanced Claude Code usage analyzer with server data upload integration - PCUsage (Personal Claude Usage)
Downloads
37
Maintainers
Readme
🚀 PCUsage: 个人Claude使用分析器,支持自动将Claude Code使用数据上传到管理系统服务器!
✨ 相比原版的改进
- 🌐 服务器集成: 自动上传使用数据到指定服务器
- ⚙️ 灵活配置: 支持自定义服务器地址和API端点
- 🔒 数据加密: 支持数据加密传输
- 🔄 重试机制: 自动重试失败的上传请求
- 📊 完全兼容: 保持原版ccusage的所有功能
📦 安装
全局安装(推荐)
# 从npm安装
npm install -g pcusage
# 从本地安装(开发版本)
npm install -g .临时使用
# 使用npx临时运行
npx pcusage
# 使用bunx(推荐,更快)
bunx pcusage⚙️ 配置
1. 创建配置文件
在您的项目根目录或ccusage工作目录下创建配置文件:
api-config.json - API基础配置
{
"port": 3000,
"host": "1.15.226.183",
"apiKeys": ["your-api-key-12345"],
"encryptionKey": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456",
"jwtSecret": "super-secret-jwt-key-for-development-only",
"rateLimitWindowMs": 60000,
"rateLimitMax": 100,
"corsOrigins": ["*"],
"enableEncryption": false,
"logLevel": "info"
}upload-config.json - 上传配置
{
"apiEndpoint": "http://1.15.226.183:3000/api/ccusage/upload",
"encryptionKey": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456",
"userId": "user_12345678",
"uploadInterval": 3600,
"maxRetries": 3,
"timeout": 30000
}2. 服务器端配置
确保您的服务器支持以下API端点:
// Express.js 示例
app.post('/api/ccusage/upload', (req, res) => {
const data = req.body;
console.log('接收到ccusage数据:', data);
// 处理数据逻辑...
res.json({
success: true,
message: '数据上传成功',
timestamp: new Date().toISOString()
});
});
app.get('/api/ccusage/health', (req, res) => {
res.json({
success: true,
message: 'CCUsage API运行正常',
timestamp: new Date().toISOString()
});
});Usage
# Basic usage
ccusage # Show daily report (default)
ccusage daily # Daily token usage and costs
ccusage monthly # Monthly aggregated report
ccusage session # Usage by conversation session
ccusage blocks # 5-hour billing windows
ccusage statusline # Compact status line for hooks (Beta)
# Live monitoring
ccusage blocks --live # Real-time usage dashboard
# Filters and options
ccusage daily --since 20250525 --until 20250530
ccusage daily --json # JSON output
ccusage daily --breakdown # Per-model cost breakdown
ccusage daily --timezone UTC # Use UTC timezone
ccusage daily --locale ja-JP # Use Japanese locale for date/time formatting
# Project analysis
ccusage daily --instances # Group by project/instance
ccusage daily --project myproject # Filter to specific project
ccusage daily --instances --project myproject --json # Combined usage
# Compact mode for screenshots/sharing
ccusage --compact # Force compact table mode
ccusage monthly --compact # Compact monthly reportFeatures
- 📊 Daily Report: View token usage and costs aggregated by date
- 📅 Monthly Report: View token usage and costs aggregated by month
- 💬 Session Report: View usage grouped by conversation sessions
- ⏰ 5-Hour Blocks Report: Track usage within Claude's billing windows with active block monitoring
- 📈 Live Monitoring: Real-time dashboard showing active session progress, token burn rate, and cost projections with
blocks --live - 🚀 Statusline Integration: Compact usage display for Claude Code status bar hooks (Beta)
- 🤖 Model Tracking: See which Claude models you're using (Opus, Sonnet, etc.)
- 📊 Model Breakdown: View per-model cost breakdown with
--breakdownflag - 📅 Date Filtering: Filter reports by date range using
--sinceand--until - 📁 Custom Path: Support for custom Claude data directory locations
- 🎨 Beautiful Output: Colorful table-formatted display with automatic responsive layout
- 📱 Smart Tables: Automatic compact mode for narrow terminals (< 100 characters) with essential columns
- 📸 Compact Mode: Use
--compactflag to force compact table layout, perfect for screenshots and sharing - 📋 Enhanced Model Display: Model names shown as bulleted lists for better readability
- 📄 JSON Output: Export data in structured JSON format with
--json - 💰 Cost Tracking: Shows costs in USD for each day/month/session
- 🔄 Cache Token Support: Tracks and displays cache creation and cache read tokens separately
- 🌐 Offline Mode: Use pre-cached pricing data without network connectivity with
--offline(Claude models only) - 🔌 MCP Integration: Built-in Model Context Protocol server for integration with other tools
- 🏗️ Multi-Instance Support: Group usage by project with
--instancesflag and filter by specific projects - 🌍 Timezone Support: Configure timezone for date grouping with
--timezoneoption - 🌐 Locale Support: Customize date/time formatting with
--localeoption (e.g., en-US, ja-JP, de-DE) - ⚙️ Configuration Files: Set defaults with JSON configuration files, complete with IDE autocomplete and validation
- 🚀 Ultra-Small Bundle: Unlike other CLI tools, we pay extreme attention to bundle size - incredibly small even without minification!
Documentation
Full documentation is available at ccusage.com
Sponsors
Featured Sponsor
Check out ccusage: The Claude Code cost scorecard that went viral
Claude Code Resources
ClaudeLog by InventorBlack
A comprehensive knowledge base with detailed breakdowns of advanced topics, including:
- Advanced mechanics and CLAUDE.md best practices.
- Practical technique guides for plan mode, ultrathink, and sub-agents.
- Concepts like agent-first design, agent engineering, and humanizing agents.
- Configuration guides.
