Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/messages/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,17 @@ export function getMessagesWithinTokenLimit({
) as ThinkingContentText | undefined;
thinkingStartIndex = thinkingBlock != null ? currentIndex : -1;
}
/** False start, the latest message was not part of a multi-assistant/tool sequence of messages */
/**
* Exited the trailing assistant/tool sequence without finding a
* thinking block. Anthropic does not require Claude to emit a
* thinking block before every tool call, so the absence of one is
* a valid sequence — clear thinkingEndIndex so the pruner does not
* treat it as malformed.
*/
if (
thinkingEndIndex > -1 &&
currentIndex === thinkingEndIndex - 1 &&
thinkingStartIndex < 0 &&
!thinkingBlock &&
messageType !== 'ai' &&
messageType !== 'tool'
) {
Expand Down
Loading
Loading