Reduced redundant token estimation in tool-output pruning while preserving pruning behavior.
Context
The pruning loop in prune_old_tool_outputs() was estimating token counts twice for pruned parts and recalculating placeholder tokens for every mutation.
Changes
Added PRUNE_PLACEHOLDER_TOKENS to cache placeholder token counts.
Introduced get_part_content_text() to normalize part content before estimation/pruning.
Passed precomputed token counts into prune_part_content() to avoid re-estimation.
Stopped token estimation after protect + minimum is satisfied while still scanning for parts to prune.
Behavioral Impact
Pruning decisions and output remain unchanged; token estimation work is reduced and placeholder token counting is cached.
Related Cards
[[token-pruning-efficiency-plan]]
1---2name: 473-2026-02-02-pruning-token-estimation-optimization-767dd523description: Summary4---56# Summary78Reduced redundant token estimation in tool-output pruning while preserving pruning behavior.910# Context1112The pruning loop in `prune_old_tool_outputs()` was estimating token counts twice for pruned parts and recalculating placeholder tokens for every mutation.1314# Changes1516- Added `PRUNE_PLACEHOLDER_TOKENS` to cache placeholder token counts.17- Introduced `get_part_content_text()` to normalize part content before estimation/pruning.18- Passed precomputed token counts into `prune_part_content()` to avoid re-estimation.19- Stopped token estimation after `protect + minimum` is satisfied while still scanning for parts to prune.2021# Behavioral Impact2223Pruning decisions and output remain unchanged; token estimation work is reduced and placeholder token counting is cached.2425# Related Cards2627- [[token-pruning-efficiency-plan]]
Run npx skillmds@latest add tools-only/473-2026-02-02-pruning-token-estimation-optimization-767dd52 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Summary It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tools-only (@tools-only) published this skill. Their other Agent Skills are listed on their SkillMD profile.