llmkit_local_forecast
Project monthly costs for local AI tool usage and compare them to Max subscription plans to optimize spending decisions.
Instructions
Monthly cost projection based on local AI tool usage. Compares to Max subscription.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Implementation of the tool handler for 'llmkit_local_forecast'. It calculates projected costs based on local AI tool data.
export async function handleLocalForecast() { const active = await detectAdapters(); if (active.length === 0) return fail('No AI coding tool data found. Works with Claude Code and Cline.'); const allProjects: LocalProjectSummary[] = []; const results = await Promise.allSettled(active.map(a => a.getProjects())); for (const r of results) { if (r.status === 'fulfilled') allProjects.push(...r.value); } if (allProjects.length === 0) return fail('No project data for forecasting.'); const totalCost = allProjects.reduce((s, p) => s + p.totalCost, 0); const totalSessions = allProjects.reduce((s, p) => s + p.sessionCount, 0); // project from actual date range, not hardcoded 30 days const timestamps = allProjects.map(p => p.latestTimestamp).filter(Boolean).sort(); const earliest = timestamps[0] ?? ''; const latest = timestamps[timestamps.length - 1] ?? ''; const daySpan = earliest && latest ? Math.max(1, Math.ceil((new Date(latest).getTime() - new Date(earliest).getTime()) / 86400000) + 1) : 30; const dailyAvg = totalCost / daySpan; const monthlyProjection = dailyAvg * 30; const maxSavings = monthlyProjection - 200; // vs $200/mo Max subscription // legacy usage from old Claude Code versions const legacy = await getLegacyUsage(); const lines = [ 'Cost Forecast (all tools)', '\u2500'.repeat(25), `Monthly projection: $${monthlyProjection.toFixed(2)} (API rates)`, `Daily average: $${dailyAvg.toFixed(2)}`, `Current period: $${totalCost.toFixed(2)} across ${totalSessions} sessions`, '', `Max ($200/mo) ${maxSavings > 0 ? `saves: $${maxSavings.toFixed(2)}/mo` : 'costs more than API rates'}`, ]; if (legacy.totalCost > 0) { lines.push('', 'Historical usage (old Claude Code, no per-project breakdown):'); for (const m of legacy.months) lines.push(` ${m.month}: $${m.cost.toFixed(2)}`); lines.push(` Total: $${legacy.totalCost.toFixed(2)}`); } const allTimeCost = totalCost + legacy.totalCost; return ok(lines.join('\n'), { projectedMonthlyUsd: monthlyProjection, dailyAverageUsd: dailyAvg, totalTrackedUsd: totalCost, totalSessions, legacyUsageUsd: legacy.totalCost, allTimeCostUsd: allTimeCost, maxSubscriptionSavingsUsd: maxSavings > 0 ? maxSavings : 0, }); } - Tool definition/schema for 'llmkit_local_forecast'.
name: 'llmkit_local_forecast', description: 'Monthly cost projection based on local AI tool usage. Compares to Max subscription.', inputSchema: { type: 'object' as const, properties: {} }, outputSchema: { type: 'object' as const, properties: { projectedMonthlyUsd: { type: 'number' }, dailyAverageUsd: { type: 'number' }, totalTrackedUsd: { type: 'number' }, totalSessions: { type: 'number' }, maxSubscriptionSavingsUsd: { type: 'number' }, }, required: ['projectedMonthlyUsd', 'dailyAverageUsd'], }, annotations: { title: 'Cost Forecast', ...HINTS }, }, - packages/mcp-server/src/tools.ts:301-301 (registration)Registration of the 'llmkit_local_forecast' tool handler in the handler map.
llmkit_local_forecast: () => handleLocalForecast(),