Persistent HUD showing AI context usage, token cost, and session health across IDE and CLI environments.
-
Install the extension:
cursor --install-extension cost-monitor-hud-0.1.0.vsix --force
-
Configure the hook:
mkdir -p .cursor/hooks cp cost-monitor.py .cursor/hooks/
Create
.cursor/hooks/hooks.json:{ "hooks": { "afterAgentResponse": [ { "type": "command", "command": "python .cursor/hooks/cost-monitor.py --cursor" } ] } } -
Restart Cursor and start chatting!
-
Install the extension:
- Open CodeBuddy IDE
- Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) - Type "Install from VSIX"
- Select
cost-monitor-hud-0.1.0.vsix
-
Configure the hook:
mkdir -p .codebuddy/hooks cp cost-monitor.py .codebuddy/hooks/
Create/edit
.codebuddy/settings.json:{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "python \"$CODEBUDDY_PROJECT_DIR/.codebuddy/hooks/cost-monitor.py\"" } ] } ] } } -
Restart CodeBuddy IDE and start chatting!
-
Install the plugin:
claude /plugin install cost-monitor-hud
-
Or manually copy
cli-plugin/to your Claude Code plugins directory. -
Start Claude Code - the statusline will appear automatically.
- Status Bar: Always-visible item at the bottom showing
T5 | 32% | $0.15- Green (normal), yellow background (>40%), red background (>70%)
- Click to open the detail sidebar
- Sidebar Panel: Full breakdown with progress bar, token distribution, trend chart, and warnings
- Terminal Output: Rich terminal UI showing context usage, cost, and warnings after each response
- Node.js (v18+) - for building the extension from source
- Python 3.x - for running the hook script
- VS Code / Cursor / CodeBuddy IDE - for running the extension
If you want to build the extension yourself:
# Clone the repository
git clone https://github.com/geminiyao/Cost-Monitor.git
cd Cost-Monitor
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Package as .vsix
npm run packageOutput: cost-monitor-hud-0.1.0.vsix
Download the latest cost-monitor-hud-0.1.0.vsix from the Releases page.
cursor --install-extension cost-monitor-hud-0.1.0.vsix --forceMethod 1 - Via UI:
- Open CodeBuddy IDE
- Press
Ctrl+Shift+P - Type "Install from VSIX"
- Select the
.vsixfile
Method 2 - Via command line (if codebuddy command is available):
codebuddy --install-extension cost-monitor-hud-0.1.0.vsix --forcecode --install-extension cost-monitor-hud-0.1.0.vsix --forceCursor uses .cursor/hooks/hooks.json to configure hooks.
mkdir -p .cursor/hooks
cp /path/to/cost-monitor.py .cursor/hooks/Create or edit .cursor/hooks/hooks.json:
{
"hooks": {
"afterAgentResponse": [
{
"type": "command",
"command": "python .cursor/hooks/cost-monitor.py --cursor",
"description": "Cost Monitor: track token usage"
}
]
}
}Important:
- Hook event:
afterAgentResponse(triggered after each AI response) - Command:
python .cursor/hooks/cost-monitor.py --cursor(note the--cursorflag) - Output:
.cursor/hooks/.cost-state.json(watched by the extension)
- Start a chat in Cursor
- Check if
.cursor/hooks/.cost-state.jsonis created - The Cost Monitor extension should show data
Manual Test:
echo '{}' | python .cursor/hooks/cost-monitor.py --cursor
ls -la .cursor/hooks/.cost-state.jsonCodeBuddy uses .codebuddy/settings.json to configure hooks.
mkdir -p .codebuddy/hooks
cp /path/to/cost-monitor.py .codebuddy/hooks/Create or edit .codebuddy/settings.json:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "python \"$CODEBUDDY_PROJECT_DIR/.codebuddy/hooks/cost-monitor.py\""
}
]
}
]
}
}Important:
- Hook event:
Stop(triggered when AI stops responding) - Command: Uses
$CODEBUDDY_PROJECT_DIRenvironment variable - Output:
.codebuddy/hooks/.cost-state.json(watched by the extension)
Note: The exact hook event name may vary by CodeBuddy version. Check the documentation for the correct event name.
- Start a chat in CodeBuddy IDE
- Check if
.codebuddy/hooks/.cost-state.jsonis created - The Cost Monitor extension should show data
Manual Test:
echo '{"transcript_path": ""}' | python .codebuddy/hooks/cost-monitor.py
ls -la .codebuddy/hooks/.cost-state.jsonFor CLI usage, use the statusline plugin.
claude /plugin install cost-monitor-hudCopy cli-plugin/ directory to your Claude Code plugins directory:
cp -r cli-plugin ~/.claude/plugins/cost-monitor-hudOr follow Claude Code's plugin installation documentation.
| Aspect | Cursor IDE | CodeBuddy IDE | Claude Code CLI |
|---|---|---|---|
| Config File | .cursor/hooks/hooks.json |
.codebuddy/settings.json |
Plugin system |
| Hook Event | afterAgentResponse |
Stop |
N/A |
| Hook Command | python ... --cursor |
python ... |
N/A |
| Output | .cursor/hooks/.cost-state.json |
.codebuddy/hooks/.cost-state.json |
stdout (terminal) |
| Extension Watches | .cursor/hooks/.cost-state.json |
.codebuddy/hooks/.cost-state.json |
N/A |
Cause: The .cost-state.json file is not being generated.
Solution:
- Check if hook is configured correctly
- Verify
cost-monitor.pyis in the right location - Start a chat and check if
.cost-state.jsonis created
Debug Steps:
# Check if hook script exists
ls -la .cursor/hooks/cost-monitor.py # Cursor
ls -la .codebuddy/hooks/cost-monitor.py # CodeBuddy
# Manual test - Cursor mode
echo '{}' | python .cursor/hooks/cost-monitor.py --cursor
ls -la .cursor/hooks/.cost-state.json
# Manual test - CodeBuddy mode
echo '{"transcript_path": ""}' | python .codebuddy/hooks/cost-monitor.py
ls -la .codebuddy/hooks/.cost-state.jsonCause: Canvas chart doesn't resize properly when sidebar is widened.
Status: Fixed in v0.1.0. If you still see issues, rebuild the extension.
Check hook configuration:
- Cursor:
.cursor/hooks/hooks.json - CodeBuddy:
.codebuddy/settings.json
Verify Python is available:
python --version
# or
python3 --versionCheck hook event name:
- Cursor: Should be
afterAgentResponse - CodeBuddy: Should be
Stop(may vary by version)
Check if extension is installed:
# Cursor
cursor --list-extensions | grep cost-monitor
# CodeBuddy (if command available)
codebuddy --list-extensions | grep cost-monitor
# VS Code
code --list-extensions | grep cost-monitorReinstall if needed:
cursor --install-extension cost-monitor-hud-0.1.0.vsix --force┌─────────────────────────────────────────────────────────────┐
│ AI Coding Session │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ cost-monitor.py (Hook) │
│ - Reads session data from stdin │
│ - Calculates token usage & cost │
└─────────────────────────────────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ .cost-state.json │ │ stdout (terminal) │
│ (for VS Code Ext) │ │ (for CLI statusline)│
└─────────────────────┘ └─────────────────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ VS Code Extension │ │ Claude Code / │
│ - Status Bar HUD │ │ CodeBuddy CLI │
│ - Sidebar Panel │ │ - Terminal output │
└─────────────────────┘ └─────────────────────┘
Data Flow:
- AI responds → Hook triggered
cost-monitor.pyreads session data → writes.cost-state.json- VS Code extension watches
.cost-state.json→ updates UI - CLI mode:
cost-monitor.pyoutputs to stdout → terminal display
Cost-Monitor/
├── src/ # TypeScript source (extension)
│ ├── extension.ts # Extension entry point
│ ├── statusBar.ts # Status bar HUD
│ ├── sidebarProvider.ts # Sidebar webview with chart
│ ├── dataWatcher.ts # Watches .cost-state.json
│ └── types.ts # Type definitions
├── cli-plugin/ # CLI plugin for Claude Code
│ ├── plugin.json # Plugin metadata
│ └── statusline.js # Statusline renderer
├── cost-monitor.py # Python hook (MUST be deployed to project)
├── media/ # Icons and images
├── out/ # Compiled JavaScript (generated)
├── templates/ # Configuration templates
│ └── .codebuddy/
│ └── settings.json # CodeBuddy settings template
├── test-hook.ps1 # Hook testing script (PowerShell)
├── package.json # Extension manifest
├── tsconfig.json # TypeScript config
└── README.md # This file
npm install
npm run compile
npm run package # Creates cost-monitor-hud-0.1.0.vsixnpm run watch- Build the
.vsix - Install to Cursor/CodeBuddy
- Reload the IDE
- Start a chat to trigger the hook
- Check the Cost Monitor panel
# Test hook in CLI mode
echo '{"transcript_path": ""}' | python cost-monitor.py
# Test hook in Cursor mode
echo '{}' | python cost-monitor.py --cursor
# Check generated .cost-state.json
cat .codebuddy/hooks/.cost-state.json
cat .cursor/hooks/.cost-state.jsonMIT
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for AI coding assistants