# 475 2026 02 02 Remove Heuristic Token Counting 9c1ea9ff

> Remove heuristic token counting from agent flow

- Skill: `tools-only/475-2026-02-02-remove-heuristic-token-counting-9c1ea9ff` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add tools-only/475-2026-02-02-remove-heuristic-token-counting-9c1ea9ff`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tools-only/475-2026-02-02-remove-heuristic-token-counting-9c1ea9ff/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tools-only (https://skillmd.com/u/tools-only)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/tools-only/475-2026-02-02-remove-heuristic-token-counting-9c1ea9ff

---


# 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]]

