get_current_session_usage
Monitor current Claude Code session metrics including token usage, cost, and activity to track resource consumption and manage spending.
Instructions
Get usage metrics for the current Claude Code session (tokens, cost, activity)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/telemetry-service.ts:33-50 (handler)Core handler function that executes the tool logic by querying Prometheus for current session usage metrics across various dimensions (tokens, cost, etc.) and building the UsageData response.async getCurrentSessionUsage(): Promise<UsageData> { const sessionStart = this.sessionStartTime.toISOString(); const now = new Date().toISOString(); // Query for usage since session start - use sum() to aggregate across all label dimensions const queries = { tokens: `sum(increase(claude_code_token_usage_tokens_total[${this.getTimeRange()}]))`, cost: `sum(increase(claude_code_cost_usage_USD_total[${this.getTimeRange()}]))`, sessions: `sum(increase(claude_code_session_count_total[${this.getTimeRange()}]))`, activeTime: `sum(increase(claude_code_active_time_seconds_total[${this.getTimeRange()}]))`, linesOfCode: `sum(increase(claude_code_lines_of_code_count_total[${this.getTimeRange()}]))`, commits: `sum(increase(claude_code_commit_count_total[${this.getTimeRange()}]))`, editDecisions: `sum(increase(claude_code_code_edit_tool_decision_total[${this.getTimeRange()}]))` }; const results = await this.executeQueries(queries); return this.buildUsageData(results); }
- src/index.ts:199-209 (handler)MCP CallToolRequestHandler case that handles calls to 'get_current_session_usage', delegates to TelemetryService, and formats the response as MCP content.case 'get_current_session_usage': { const usage = await this.telemetryService.getCurrentSessionUsage(); return { content: [ { type: 'text', text: this.formatUsageData('Current Session', usage), }, ], }; }
- src/index.ts:38-45 (registration)Tool registration in the ListToolsRequestHandler response, defining the tool name, description, and input schema.{ name: 'get_current_session_usage', description: 'Get usage metrics for the current Claude Code session (tokens, cost, activity)', inputSchema: { type: 'object', properties: {}, }, },
- src/index.ts:41-44 (schema)Input schema definition for the tool (empty object, indicating no input parameters required).inputSchema: { type: 'object', properties: {}, },
- src/telemetry-service.ts:86-90 (helper)Helper usage of getCurrentSessionUsage within the getUsageSummary method.const [currentSession, today, thisWeek] = await Promise.all([ this.getCurrentSessionUsage(), this.getTodayUsage(), this.getWeekUsage() ]);