source dump of claude code
at main 56 lines 2.2 kB view raw
1/** 2 * Constants related to tool result size limits 3 */ 4 5/** 6 * Default maximum size in characters for tool results before they get persisted 7 * to disk. When exceeded, the result is saved to a file and the model receives 8 * a preview with the file path instead of the full content. 9 * 10 * Individual tools may declare a lower maxResultSizeChars, but this constant 11 * acts as a system-wide cap regardless of what tools declare. 12 */ 13export const DEFAULT_MAX_RESULT_SIZE_CHARS = 50_000 14 15/** 16 * Maximum size for tool results in tokens. 17 * Based on analysis of tool result sizes, we set this to a reasonable upper bound 18 * to prevent excessively large tool results from consuming too much context. 19 * 20 * This is approximately 400KB of text (assuming ~4 bytes per token). 21 */ 22export const MAX_TOOL_RESULT_TOKENS = 100_000 23 24/** 25 * Bytes per token estimate for calculating token count from byte size. 26 * This is a conservative estimate - actual token count may vary. 27 */ 28export const BYTES_PER_TOKEN = 4 29 30/** 31 * Maximum size for tool results in bytes (derived from token limit). 32 */ 33export const MAX_TOOL_RESULT_BYTES = MAX_TOOL_RESULT_TOKENS * BYTES_PER_TOKEN 34 35/** 36 * Default maximum aggregate size in characters for tool_result blocks within 37 * a SINGLE user message (one turn's batch of parallel tool results). When a 38 * message's blocks together exceed this, the largest blocks in that message 39 * are persisted to disk and replaced with previews until under budget. 40 * Messages are evaluated independently — a 150K result in one turn and a 41 * 150K result in the next are both untouched. 42 * 43 * This prevents N parallel tools from each hitting the per-tool max and 44 * collectively producing e.g. 10 × 40K = 400K in one turn's user message. 45 * 46 * Overridable at runtime via GrowthBook flag tengu_hawthorn_window — see 47 * getPerMessageBudgetLimit() in toolResultStorage.ts. 48 */ 49export const MAX_TOOL_RESULTS_PER_MESSAGE_CHARS = 200_000 50 51/** 52 * Maximum character length for tool summary strings in compact views. 53 * Used by getToolUseSummary() implementations to truncate long inputs 54 * for display in grouped agent rendering. 55 */ 56export const TOOL_SUMMARY_MAX_LENGTH = 50