MCPcopy Create free account
hub / github.com/codeaashu/claude-code / countToolCalls

Function countToolCalls

src/utils/messages.ts:4691–4713  ·  view source on GitHub ↗
(
  messages: Message[],
  toolName: string,
  maxCount?: number,
)

Source from the content-addressed store, hash-verified

4689 * Stops early at maxCount for efficiency
4690 */
4691export function countToolCalls(
4692 messages: Message[],
4693 toolName: string,
4694 maxCount?: number,
4695): number {
4696 let count = 0
4697 for (const msg of messages) {
4698 if (!msg) continue
4699 if (msg.type === 'assistant' && Array.isArray(msg.message.content)) {
4700 const hasToolUse = msg.message.content.some(
4701 (block): block is ToolUseBlock =>
4702 block.type === 'tool_use' && block.name === toolName,
4703 )
4704 if (hasToolUse) {
4705 count++
4706 if (maxCount && count >= maxCount) {
4707 return count
4708 }
4709 }
4710 }
4711 }
4712 return count
4713}
4714
4715/**
4716 * Check if the most recent tool call succeeded (has result without is_error)

Callers 1

submitMessageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected