MCPcopy Index your code
hub / github.com/codeaashu/claude-code / countCustomAgentTokens

Function countCustomAgentTokens

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

Source from the content-addressed store, hash-verified

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

Callers 1

analyzeContextUsageFunction · 0.85

Calls 3

countTokensWithFallbackFunction · 0.85
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected