Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 829faf4

Browse files
authored
fix(agent): stop resume hydration from overfilling the context window (#3331)
1 parent cc2228b commit 829faf4

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/agent/src/adapters/claude/session/jsonl-hydration.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,12 @@ export function rebuildConversation(
241241
return turns;
242242
}
243243

244-
const CHARS_PER_TOKEN = 4;
245-
const DEFAULT_MAX_TOKENS = 150_000;
246-
const LARGE_CONTEXT_MAX_TOKENS = 800_000;
244+
// JSON-heavy tool payloads tokenize at ~2.5-3 chars/token, so estimate low.
245+
const CHARS_PER_TOKEN = 3;
246+
// Target ~half the context window, leaving headroom for the system prompt,
247+
// tools, skills, estimation error, and the resumed run's own work.
248+
const DEFAULT_MAX_TOKENS = 80_000;
249+
const LARGE_CONTEXT_MAX_TOKENS = 400_000;
247250

248251
function estimateTurnTokens(turn: ConversationTurn): number {
249252
let chars = 0;

0 commit comments

Comments
 (0)