[PR #180] [MERGED] refactor(claude-kiro): improve token counting accuracy using API contextUsagePercentage #286

Closed
opened 2026-02-27 07:18:49 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/justlovemaki/AIClient-2-API/pull/180
Author: @tickernelz
Created: 1/8/2026
Status: Merged
Merged: 1/8/2026
Merged by: @justlovemaki

Base: mainHead: fix-kiro-token-count


📝 Commits (2)

  • e18303d refactor(claude-kiro): improve token counting accuracy using API contextUsagePercentage
  • 085b1ef Merge branch 'main' into fix-kiro-token-count

📊 Changes

1 file changed (+353 additions, -275 deletions)

View changed files

📝 src/claude/claude-kiro.js (+353 -275)

📄 Description

Replace client-side token estimation with server-provided contextUsagePercentage for accurate input token calculation. This eliminates discrepancies between estimated and actual token counts by using the API's native context window measurement.

Key changes:

  • Add contextUsage event parsing in AWS Event Stream buffer
  • Calculate input tokens from contextUsagePercentage in both streaming and non-streaming responses
  • Deprecate estimateInputTokens() method in favor of API-provided metrics
  • Import CLAUDE_DEFAULT_MAX_TOKENS for context window calculations
  • Add fallback error handling when contextUsagePercentage is not received
  • Fix code formatting and whitespace consistency throughout the file

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/justlovemaki/AIClient-2-API/pull/180 **Author:** [@tickernelz](https://github.com/tickernelz) **Created:** 1/8/2026 **Status:** ✅ Merged **Merged:** 1/8/2026 **Merged by:** [@justlovemaki](https://github.com/justlovemaki) **Base:** `main` ← **Head:** `fix-kiro-token-count` --- ### 📝 Commits (2) - [`e18303d`](https://github.com/justlovemaki/AIClient-2-API/commit/e18303de80232640b16b2abf16bac2a0ef66c1d0) refactor(claude-kiro): improve token counting accuracy using API contextUsagePercentage - [`085b1ef`](https://github.com/justlovemaki/AIClient-2-API/commit/085b1ef52ebfffb0c85270bb3c2742700a6bf428) Merge branch 'main' into fix-kiro-token-count ### 📊 Changes **1 file changed** (+353 additions, -275 deletions) <details> <summary>View changed files</summary> 📝 `src/claude/claude-kiro.js` (+353 -275) </details> ### 📄 Description Replace client-side token estimation with server-provided contextUsagePercentage for accurate input token calculation. This eliminates discrepancies between estimated and actual token counts by using the API's native context window measurement. Key changes: - Add contextUsage event parsing in AWS Event Stream buffer - Calculate input tokens from contextUsagePercentage in both streaming and non-streaming responses - Deprecate estimateInputTokens() method in favor of API-provided metrics - Import CLAUDE_DEFAULT_MAX_TOKENS for context window calculations - Add fallback error handling when contextUsagePercentage is not received - Fix code formatting and whitespace consistency throughout the file --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 07:18:49 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AIClient-2-API-justlovemaki#286
No description provided.