Skip to main content

vtcode_config/constants/
context.rs

1/// Head ratio percentage for code files (legacy, kept for compatibility)
2pub const CODE_HEAD_RATIO_PERCENT: usize = 60;
3
4/// Head ratio percentage for log files (legacy, kept for compatibility)
5pub const LOG_HEAD_RATIO_PERCENT: usize = 20;
6
7// =========================================================================
8// Context Window Sizes
9// =========================================================================
10
11/// Standard context window size (200K tokens) - default for most models
12pub const STANDARD_CONTEXT_WINDOW: usize = 200_000;
13
14/// Extended context window size (1M tokens) - beta feature
15/// Available for Claude Sonnet 4, Sonnet 4.5 in usage tier 4
16/// Requires beta header: "context-1m-2025-08-07"
17pub const EXTENDED_CONTEXT_WINDOW: usize = 1_000_000;
18
19/// Claude.ai Enterprise context window (500K tokens)
20pub const ENTERPRISE_CONTEXT_WINDOW: usize = 500_000;
21
22// =========================================================================
23// Token Budget Thresholds (for proactive context management)
24// =========================================================================
25
26/// First warning threshold - start preparing for context handoff
27/// At 70% usage: Consider updating key artifacts to persist context
28pub const TOKEN_BUDGET_WARNING_THRESHOLD: f64 = 0.70;
29
30/// Second warning threshold - active context management needed
31/// At 90% usage: Actively summarize and persist state
32pub const TOKEN_BUDGET_HIGH_THRESHOLD: f64 = 0.90;
33
34/// Critical threshold - immediate action required
35/// At 95% usage: Force context handoff or summary
36pub const TOKEN_BUDGET_CRITICAL_THRESHOLD: f64 = 0.95;
37
38// =========================================================================
39// Extended Thinking Token Management
40// =========================================================================
41
42/// Minimum budget tokens for extended thinking (Anthropic requirement)
43pub const MIN_THINKING_BUDGET: u32 = 1_024;
44
45/// Recommended budget tokens for complex reasoning tasks
46pub const RECOMMENDED_THINKING_BUDGET: u32 = 10_000;
47
48/// Default thinking budget for production use (64K output models: Opus 4.5, Sonnet 4.5, Haiku 4.5)
49/// Extended thinking is now auto-enabled by default as of January 2026
50pub const DEFAULT_THINKING_BUDGET: u32 = 31_999;
51
52/// Maximum thinking budget for 64K output models (Opus 4.5, Sonnet 4.5, Haiku 4.5)
53/// Use MAX_THINKING_TOKENS=63999 environment variable to enable this
54pub const MAX_THINKING_BUDGET_64K: u32 = 63_999;
55
56/// Maximum thinking budget for 32K output models (Opus 4)
57pub const MAX_THINKING_BUDGET_32K: u32 = 31_999;
58
59// =========================================================================
60// Beta Headers
61// =========================================================================
62
63/// Beta header for 1M token context window
64/// Include in requests to enable extended context for Sonnet 4/4.5
65pub const BETA_CONTEXT_1M: &str = "context-1m-2025-08-07";
66
67// =========================================================================
68// Context-Aware Model Detection
69// =========================================================================
70
71/// Models that support context awareness (budget tracking in prompts)
72/// Context awareness: model tracks remaining token budget throughout conversation
73/// Currently: Claude Sonnet 4.6, Claude Haiku 4.5
74pub const CONTEXT_AWARE_MODELS: &[&str] = &[
75    crate::constants::models::anthropic::CLAUDE_SONNET_4_6,
76    crate::constants::models::anthropic::CLAUDE_HAIKU_4_5,
77    crate::constants::models::anthropic::CLAUDE_HAIKU_4_5_20251001,
78];
79
80/// Check if a model supports context awareness
81pub fn supports_context_awareness(model: &str) -> bool {
82    CONTEXT_AWARE_MODELS.iter().any(|m| model.contains(m))
83}
84
85/// Models eligible for 1M context window (beta)
86/// Requires usage tier 4 or custom rate limits
87pub const EXTENDED_CONTEXT_ELIGIBLE_MODELS: &[&str] = &[
88    crate::constants::models::anthropic::CLAUDE_SONNET_4_6,
89    crate::constants::models::anthropic::CLAUDE_OPUS_4_6,
90];
91
92/// Check if a model is eligible for 1M context window
93pub fn supports_extended_context(model: &str) -> bool {
94    EXTENDED_CONTEXT_ELIGIBLE_MODELS
95        .iter()
96        .any(|m| model.contains(m))
97}