How to Build a Local AI Coding Cost Monitoring Dashboard in 15 Minutes
A step-by-step guide to deploying a local desktop component for monitoring AI programming costs. Learn how to configure multi-tool API dashboards, set up budget alerts, and sync configuration data across devices using the `token-monitor` open-source project.

How to Build a Local AI Coding Cost Monitoring Dashboard in 15 Minutes
Last week, while reviewing our team's monthly bill for Claude Code, I discovered that the hidden consumption from Cursor and Codex actually accounted for 40% of our budget. If you're leveraging multiple AI coding assistants, you've likely run into the same bottlenecks:
- Scattered platform bills make manual reconciliation time-consuming.
- Lack of early warning mechanisms for sudden overage charges.
- Difficulty in allocating costs across collaborative teams.
Today, I'll walk you through a step-by-step setup of the token-monitor project. In just 15 minutes, you'll have a dedicated local cost monitoring hub. Once complete, you'll be able to view real-time usage radar charts for all your connected AI tools, configure tiered alert thresholds, and sync settings across your laptop and cloud servers.
Prerequisites
Environment Requirements:
- Node.js ≥18.0 (LTS version recommended)
- Basic familiarity with Git
- At least one AI tool API Key (Claude/Cursor/OpenAI works)
💡 Why Node.js? The project is built on an Electron + Vite architecture, relying on Node's build toolchain for the desktop environment. If you haven't installed Node, head to
nodejs.organd download the installer for your OS.
Quick Start: 4-Step Setup
1. Clone the Repository and Install Dependencies
bash
git clone https://github.com/Javis603/token-monitor.git
cd token-monitor
npm install
⚠️ Note: Windows users encountering
node-gypcompilation errors should install Visual StudioBuild Toolsin advance. You can also usenpm install --build-from-sourceto bypass binary dependency issues.
2. Initialize Monitoring Configuration
Copy the example config file:
bash
cp .env.example .env
Open .env and fill in the basic parameters:
env
DATABASE_URL=sqlite:./data/monitor.db
MONITOR_PORT=3001
SYNC_INTERVAL=300000 # 5-minute sync cycle
🔍 Configuration Breakdown: We use SQLite for local storage to eliminate network latency. Adjust
SYNC_INTERVALto change the cloud sync frequency. Keep the default value for your first run.
3. Bind AI Tool APIs
Before starting the service, register at least one monitoring source:
bash
npm run register-tool
Follow the interactive prompts to input your API Key. Here's an example for Claude:
[?] Select tool type: claude-code
[?] Enter API Key: sk-ant-xxxxxxx...[hidden]
[?] Set monthly budget (¥): 500
✅ Successfully added Claude Code monitoring node
4. Launch the Dashboard Service
bash
npm run dev
Navigate to http://localhost:3001 in your browser. The initial load will trigger a setup wizard. After configuring your account, the main panel will automatically render donut charts showing usage for each tool.
Real-World Scenario: Building a Team Alert System
Objective
Automatically push a warning message to WeCom (Enterprise WeChat) when daily total consumption exceeds 80% of the budget.
Implementation Steps
-
Enable the Alert Plugin
Createplugins/alert.jsin the project root:javascriptconst axios = require('axios'); module.exports = async (threshold) => { if (threshold.reach > 0.8) { await axios.post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send', { msgtype: 'text', text: { content: `⚠️ AI Token Alert: ${threshold.tool} usage at ${threshold.percent}%` } }); } }; -
Register the Plugin Hook
Updateconfig/hooks.json:json{ "onThresholdBreach": "./plugins/alert.js" } -
Test the Alert Pipeline
Run the following command in your terminal:bashnpm run trigger-alert -- --tool=cursor --percent=85If configured correctly, your WeCom group chat will receive the test notification.
Troubleshooting & Common Pitfalls
| Issue | Solution |
|---|---|
| Dashboard shows "Sync Failed" | Verify if SYNC_INTERVAL in .env or port 3001 is blocked by your firewall. |
| Data out of sync across devices | Ensure all devices share the same .env configuration. Restart the service to force a cloud state pull. |
| API Key authentication fails | Double-check the tool type spelling. Some platforms like Codex require enabling Beta permissions. |
| Charts render blank | Clear your browser cache and refresh. For Electron apps, use Ctrl+Shift+R for a hard refresh. |
Next Steps
Once the base deployment is complete, consider trying the following:
- Customize chart colors by modifying
src/renderer/charts/CostRadar.vue. - Export CSV reports for financial auditing via
/api/v1/usage. - Join GitHub Discussions to contribute to multi-tenant architecture design.
📌 Project Repo: Javis603/token-monitor Feel free to submit an Issue if you run into configuration challenges during your setup.