UNPKG

claude-monitor

Version:

Real-time terminal monitoring tool for Claude AI token usage

135 lines 4.32 kB
#!/usr/bin/env node import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { settingsManager } from '../core/settings.js'; const version = '1.0.0'; const argv = yargs(hideBin(process.argv)) .scriptName('claude-monitor') .usage('$0 [options]') .version(version) .alias('v', 'version') .help('h') .alias('h', 'help') .options({ plan: { type: 'string', choices: ['pro', 'max5', 'max20', 'custom'], description: 'Subscription plan type', }, 'custom-limit': { type: 'number', description: 'Token limit for custom plan', }, timezone: { type: 'string', description: 'Timezone for display (auto-detected by default)', }, theme: { type: 'string', choices: ['light', 'dark', 'auto'], description: 'Display theme', }, 'time-format': { type: 'string', choices: ['12h', '24h', 'auto'], description: 'Time format', }, 'refresh-rate': { type: 'number', description: 'Refresh rate in seconds (1-60)', default: 10, }, 'refresh-per-second': { type: 'number', description: 'Display refresh rate per second (0.1-20 Hz)', default: 0.75, }, clear: { type: 'boolean', description: 'Clear saved configuration', default: false, }, debug: { type: 'boolean', description: 'Enable debug logging', default: false, }, simple: { type: 'boolean', description: 'Use simple console output instead of rich UI', default: false, }, }) .example('$0', 'Start monitoring with default settings') .example('$0 --plan pro', 'Monitor with Pro plan limits') .example('$0 --plan custom --custom-limit 50000', 'Monitor with custom token limit') .example('$0 --theme dark --timezone UTC', 'Use dark theme and UTC timezone') .example('$0 --simple', 'Use simple console output') .epilogue('For more information, visit https://github.com/aistackhq/claude-monitor') .parseSync(); import { MonitoringOrchestrator } from '../monitoring/orchestrator.js'; import { ConsoleDisplay } from '../ui/console-display.js'; import { RichDisplay } from '../ui/rich-display.js'; async function main() { try { const settings = settingsManager.loadWithCLI(argv); const display = argv.simple ? new ConsoleDisplay({ clearScreen: true }) : new RichDisplay(); const orchestrator = new MonitoringOrchestrator({ updateInterval: settings.updateInterval, }); orchestrator.setSettings(settings); orchestrator.on('data-update', (data) => { display.display(data); }); orchestrator.on('error', (error) => { display.displayError(error); }); orchestrator.on('warning', (message) => { display.displayWarning(message); }); orchestrator.on('info', (message) => { if (argv.debug) { display.displayInfo(message); } }); orchestrator.on('session-change', (event, sessionId) => { if (argv.debug) { display.displayInfo(`Session ${event}: ${sessionId}`); } }); console.log('Starting Claude Monitor...'); orchestrator.start(); const hasData = await orchestrator.waitForInitialData(30000); if (!hasData) { display.displayWarning('No data received within 30 seconds. Waiting for Claude activity...'); } process.on('SIGINT', () => { if (!argv.simple) { display.cleanup(); } else { console.log('\n\nShutting down...'); } orchestrator.stop(); process.exit(0); }); process.on('SIGTERM', () => { if (!argv.simple) { display.cleanup(); } orchestrator.stop(); process.exit(0); }); } catch (error) { console.error('Error:', error); process.exit(1); } } main().catch((error) => { console.error('Unhandled error:', error); process.exit(1); }); //# sourceMappingURL=index.js.map