source dump of claude code
at main 20 lines 673 B view raw
1import { roughTokenCountEstimation } from '../services/tokenEstimation.js' 2import type { AgentDefinitionsResult } from '../tools/AgentTool/loadAgentsDir.js' 3 4export const AGENT_DESCRIPTIONS_THRESHOLD = 15_000 5 6/** 7 * Calculate cumulative token estimate for agent descriptions 8 */ 9export function getAgentDescriptionsTotalTokens( 10 agentDefinitions?: AgentDefinitionsResult, 11): number { 12 if (!agentDefinitions) return 0 13 14 return agentDefinitions.activeAgents 15 .filter(a => a.source !== 'built-in') 16 .reduce((total, agent) => { 17 const description = `${agent.agentType}: ${agent.whenToUse}` 18 return total + roughTokenCountEstimation(description) 19 }, 0) 20}