Skip to content

fix: account for Domain Map header tokens in truncateToTokenBudget#200

Merged
claude[bot] merged 1 commit intomainfrom
claude/issue-197-20260228-0432
Feb 28, 2026
Merged

fix: account for Domain Map header tokens in truncateToTokenBudget#200
claude[bot] merged 1 commit intomainfrom
claude/issue-197-20260228-0432

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Feb 28, 2026

Summary

  • Pre-deduct the "\n\n## Domain Map\n" header token cost from remaining before collecting domain sections
  • Uses the same pattern as the Critical Files section (lines 239–254)
  • Prevents rendered output from exceeding the requested token budget when domain sections are included
  • If the header doesn't fit in the remaining budget, domain sections are skipped entirely (consistent behavior)

Details

The truncateToTokenBudget function in internal/template/render.go was collecting domain sections while deducting their tokens from remaining, but the "\n\n## Domain Map\n" header string was written without ever deducting its ~6 tokens. This could cause the final output to slightly exceed the requested budget — proportionally significant at very tight budgets (e.g. --max-tokens 50).

The fix reserves header token space upfront via a sectionBudget variable, collects sections against that budget, and only writes the header + sections if at least one section was collected.

Fixes #197

Generated with Claude Code

Pre-deduct the header token cost from `remaining` before collecting
domain sections, using the same pattern as the Critical Files section.
This prevents rendered output from exceeding the token budget when
domain sections are included.

Fixes #197

Co-Authored-By: Grey Newell <greyshipscode@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude claude bot merged commit 7c5ce5d into main Feb 28, 2026
1 check passed
@claude claude bot deleted the claude/issue-197-20260228-0432 branch February 28, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: truncateToTokenBudget omits Domain Map header from token budget accounting

0 participants