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

Function calculateToolResultTokens

src/services/compact/microCompact.ts:138–157  ·  view source on GitHub ↗
(block: ToolResultBlockParam)

Source from the content-addressed store, hash-verified

136
137// Helper to calculate tool result tokens
138function calculateToolResultTokens(block: ToolResultBlockParam): number {
139 if (!block.content) {
140 return 0
141 }
142
143 if (typeof block.content === 'string') {
144 return roughTokenCountEstimation(block.content)
145 }
146
147 // Array of TextBlockParam | ImageBlockParam | DocumentBlockParam
148 return block.content.reduce((sum, item) => {
149 if (item.type === 'text') {
150 return sum + roughTokenCountEstimation(item.text)
151 } else if (item.type === 'image' || item.type === 'document') {
152 // Images/documents are approximately 2000 tokens regardless of format
153 return sum + IMAGE_MAX_TOKEN_SIZE
154 }
155 return sum
156 }, 0)
157}
158
159/**
160 * Estimate token count for messages by extracting text content

Callers 2

estimateMessageTokensFunction · 0.85

Calls 1

Tested by

no test coverage detected