mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
feat: 添加 prompt 缓存命中率检测与警告功能
每次 API 请求后自动计算缓存命中率,低于阈值(默认 80%)时在对话流中显示黄色警告消息。 同时更新 /context 命令输出中显示缓存命中率。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -229,6 +229,10 @@ export interface ContextData {
|
||||
cache_creation_input_tokens: number
|
||||
cache_read_input_tokens: number
|
||||
} | null
|
||||
/** Cache hit rate percentage (0-100), undefined if no data */
|
||||
readonly cacheHitRate?: number
|
||||
/** Cache warning threshold percentage */
|
||||
readonly cacheThreshold?: number
|
||||
}
|
||||
|
||||
export async function countToolDefinitionTokens(
|
||||
@@ -1396,5 +1400,13 @@ export async function analyzeContextUsage(
|
||||
isAutoCompactEnabled: isAutoCompact,
|
||||
messageBreakdown: formattedMessageBreakdown,
|
||||
apiUsage,
|
||||
...(() => {
|
||||
if (!apiUsage) return {}
|
||||
const { calculateCacheHitRate, getCacheThreshold } =
|
||||
require('./cacheWarning.js') as typeof import('./cacheWarning.js')
|
||||
const hitRate = calculateCacheHitRate(apiUsage)
|
||||
if (hitRate === null) return {}
|
||||
return { cacheHitRate: hitRate, cacheThreshold: getCacheThreshold() }
|
||||
})(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user