MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / countCustomAgentTokens

Function countCustomAgentTokens

src/utils/analyzeContext.ts:742–778  ·  view source on GitHub ↗
(agentDefinitions: {
  activeAgents: AgentDefinition[]
})

Source from the content-addressed store, hash-verified

740}
741
742async function countCustomAgentTokens(agentDefinitions: {
743 activeAgents: AgentDefinition[]
744}): Promise<{
745 agentTokens: number
746 agentDetails: Agent[]
747}> {
748 const customAgents = agentDefinitions.activeAgents.filter(
749 a => a.source !== 'built-in',
750 )
751 const agentDetails: Agent[] = []
752 let agentTokens = 0
753
754 const tokenCounts = await Promise.all(
755 customAgents.map(agent =>
756 countTokensWithFallback(
757 [
758 {
759 role: 'user',
760 content: [agent.agentType, agent.whenToUse].join(' '),
761 },
762 ],
763 [],
764 ),
765 ),
766 )
767
768 for (const [i, agent] of customAgents.entries()) {
769 const tokens = tokenCounts[i] || 0
770 agentTokens += tokens || 0
771 agentDetails.push({
772 agentType: agent.agentType,
773 source: agent.source,
774 tokens: tokens || 0,
775 })
776 }
777 return { agentTokens, agentDetails }
778}
779
780type MessageBreakdown = {
781 totalTokens: number

Callers 1

analyzeContextUsageFunction · 0.85

Calls 3

countTokensWithFallbackFunction · 0.85
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected