Skip to content

feat: add token-aware context limiting for Addie#738

Merged
bokelley merged 1 commit into
mainfrom
bokelley/addie-token-limit
Jan 13, 2026
Merged

feat: add token-aware context limiting for Addie#738
bokelley merged 1 commit into
mainfrom
bokelley/addie-token-limit

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Prevents "prompt is too long" errors when Addie conversation history exceeds Claude's 200K token limit
  • Estimates token counts locally using a conservative character-based heuristic (~3.5 chars/token)
  • Reserves ~50K tokens for system prompt, tools, and safety buffer
  • Trims oldest messages when conversation exceeds ~150K tokens
  • Truncates single messages that exceed the limit with a notice
  • Logs when trimming occurs for debugging

Test plan

  • Unit tests for token-limiter.ts pass
  • Unit tests for buildMessageTurnsWithMetadata pass
  • TypeScript compiles without errors
  • Docker app starts and health check passes
  • All existing tests pass

🤖 Generated with Claude Code

Prevents "prompt is too long" errors when conversation history exceeds
Claude's 200K token limit. The system now:

- Estimates token counts locally using character-based heuristic
- Reserves ~50K tokens for system prompt, tools, and safety margin
- Trims oldest messages when conversation exceeds ~150K tokens
- Truncates single messages that exceed the limit
- Logs when trimming occurs for debugging

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit dc2c522 into main Jan 13, 2026
6 checks passed
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.

1 participant