Skip to content

ch05

@codereindeer-dev codereindeer-dev tagged this 11 May 15:28
- count_tokens() via SDK count_tokens API; last_input_tokens recorded
  from response.usage so per-turn display is free.
- Rolling-summary auto-trim: when input tokens exceed --max-input-tokens
  (default 100000), oldest turns fold into a single
  [Earlier conversation summary] message at index 0 instead of being
  dropped. Recent turns (default 5, --keep-recent-turns) stay verbatim.
  Cuts only at real (string-content) user messages so tool_use /
  tool_result pairing stays intact.
- /compact and auto-trim share the same _summarize_messages() helper;
  the summarizer recognizes its own prefix and folds new turns into the
  existing summary on subsequent triggers (no summary-of-summary rot).
- /messages dumps a one-line-per-message view for inspecting state.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Assets 2
Loading