Skip to content
Back to skills

475 2026 02 02 Remove Heuristic Token Counting 9c1ea9ff

ASecurity

The agent run flow no longer recomputes token totals by iterating over message history. This removes the slow heuristic `update_token_count` path in favor of usage totals as the canonical source for token display.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
ai-agentsperformance

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 475-2026-02-02-remove-heuristic-token-counting_9c1ea9ff --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 475 2026 02 02 Remove Heuristic Token Counting 9c1ea9ff?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 475 2026 02 02 Remove Heuristic Token Counting 9c1ea9ff
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-475-2026-02-02-remove-heuristic-token-counting-9c1/badge)](https://www.skillsdirectory.com/skills/tools-only-475-2026-02-02-remove-heuristic-token-counting-9c1)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
title: Remove heuristic token counting from agent flow
link: remove-heuristic-token-counting
type: delta
path: src/tunacode/core/agents/main.py
depth: 0
seams: [S, M]
ontological_relations:
  - relates_to: [[usage-tracking]]
  - affects: [[agent-flow]]
  - affects: [[session-state]]
tags:
  - tokens
  - usage
  - performance
  - cleanup
created_at: 2026-02-02T16:59:25-06:00
updated_at: 2026-02-02T16:59:25-06:00
uuid: 3b4c0dae-f00e-4b01-bba3-2537fd150899
---

# Remove heuristic token counting from agent flow

## Summary

The agent run flow no longer recomputes token totals by iterating over message
history. This removes the slow heuristic `update_token_count` path in favor of
usage totals as the canonical source for token display.

## Context

- `SessionState.update_token_count()` and `adjust_token_count()` were used after
  message mutations (cleanup, abort handling, persistence).
- These methods depended on `estimate_messages_tokens`, which scales poorly with
  large histories and does not match provider usage totals.

## Changes

- Removed `update_token_count` calls from `core/agents/main.py` cleanup and
  persistence paths.
- Deleted `SessionState.update_token_count()` and `adjust_token_count()` along
  with the heuristic import in `core/state.py`.
- Removed `update_token_count` from `SessionStateProtocol`.

## Behavioral Impact

- Message cleanup no longer recalculates `conversation.total_tokens`.
- UI token display will rely on usage totals rather than heuristic counts.

## Related Cards

- [[usage-total-token-source]]

Files in this skill

  • README.md1.1 KB
  • skill.md1.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.