generated from nhcarrigan/template
fix: document cost estimation review and update default model fallback (#228)
Confirms char-based estimation is unaffected by the CLI v2.1.75 token overcounting fix. Updates default model fallback to claude-sonnet-4-6.
This commit is contained in:
@@ -800,14 +800,17 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let input_chars = stats.current_request_input.as_ref().map(|s| s.len() as u64).unwrap_or(0);
|
let input_chars = stats.current_request_input.as_ref().map(|s| s.len() as u64).unwrap_or(0);
|
||||||
let model = stats.model.clone().unwrap_or_else(|| "claude-sonnet-4-5-20250929".to_string());
|
let model = stats.model.clone().unwrap_or_else(|| "claude-sonnet-4-6".to_string());
|
||||||
|
|
||||||
(input_chars, stats.current_request_output_chars, stats.current_request_thinking_chars, stats.current_request_tools.clone(), model)
|
(input_chars, stats.current_request_output_chars, stats.current_request_thinking_chars, stats.current_request_tools.clone(), model)
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::info!("[COST ESTIMATION] Estimating cost for interrupted request");
|
tracing::info!("[COST ESTIMATION] Estimating cost for interrupted request");
|
||||||
|
|
||||||
// Use conservative 3.5 chars/token for estimation (vs standard 4)
|
// Char-based estimation: 3.5 chars/token is intentionally conservative (standard English
|
||||||
|
// averages ~4 chars/token). CLI v2.1.75 fixed over-counting in Claude Code's compaction
|
||||||
|
// logic but does not affect this heuristic — we count characters ourselves, independently
|
||||||
|
// of Claude Code's internal token tracking. The 1.2 safety margin avoids undercharging.
|
||||||
let estimated_input_tokens = (input_chars as f64 / 3.5).ceil() as u64;
|
let estimated_input_tokens = (input_chars as f64 / 3.5).ceil() as u64;
|
||||||
let estimated_output_tokens = ((output_chars as f64 / 3.5).ceil() as u64)
|
let estimated_output_tokens = ((output_chars as f64 / 3.5).ceil() as u64)
|
||||||
+ ((thinking_chars as f64 / 3.5).ceil() as u64);
|
+ ((thinking_chars as f64 / 3.5).ceil() as u64);
|
||||||
@@ -1585,7 +1588,7 @@ fn process_json_line(
|
|||||||
stats_guard.model.clone()
|
stats_guard.model.clone()
|
||||||
}).unwrap_or_else(|| {
|
}).unwrap_or_else(|| {
|
||||||
tracing::warn!("No model info available for cost calculation, using default");
|
tracing::warn!("No model info available for cost calculation, using default");
|
||||||
"claude-sonnet-4-5-20250929".to_string()
|
"claude-sonnet-4-6".to_string()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate cost for historical tracking (including cache tokens)
|
// Calculate cost for historical tracking (including cache tokens)
|
||||||
|
|||||||
Reference in New Issue
Block a user