MCPcopy Create free account
hub / github.com/codeaashu/claude-code / setMockEarlyWarning

Function setMockEarlyWarning

src/services/mockRateLimits.ts:276–309  ·  view source on GitHub ↗
(
  claimAbbrev: '5h' | '7d' | 'overage',
  utilization: number,
  hoursFromNow?: number,
)

Source from the content-addressed store, hash-verified

274// utilization: 0-1 (e.g., 0.92 for 92% used)
275// hoursFromNow: hours until reset (default: 4 for 5h, 120 for 7d)
276export function setMockEarlyWarning(
277 claimAbbrev: '5h' | '7d' | 'overage',
278 utilization: number,
279 hoursFromNow?: number,
280): void {
281 if (process.env.USER_TYPE !== 'ant') {
282 return
283 }
284
285 mockEnabled = true
286
287 // Clear ALL early warning headers first (5h is checked before 7d, so we need
288 // to clear 5h headers when testing 7d to avoid 5h taking priority)
289 clearMockEarlyWarning()
290
291 // Default hours based on claim type (early in window to trigger warning)
292 const defaultHours = claimAbbrev === '5h' ? 4 : 5 * 24
293 const hours = hoursFromNow ?? defaultHours
294 const resetsAt = Math.floor(Date.now() / 1000) + hours * 3600
295
296 mockHeaders[`anthropic-ratelimit-unified-${claimAbbrev}-utilization`] =
297 String(utilization)
298 mockHeaders[`anthropic-ratelimit-unified-${claimAbbrev}-reset`] =
299 String(resetsAt)
300 // Set the surpassed-threshold header to trigger early warning
301 mockHeaders[
302 `anthropic-ratelimit-unified-${claimAbbrev}-surpassed-threshold`
303 ] = String(utilization)
304
305 // Set status to allowed so early warning logic can upgrade it
306 if (!mockHeaders['anthropic-ratelimit-unified-status']) {
307 mockHeaders['anthropic-ratelimit-unified-status'] = 'allowed'
308 }
309}
310
311// Clear mock early warning headers
312export function clearMockEarlyWarning(): void {

Callers

nothing calls this directly

Calls 1

clearMockEarlyWarningFunction · 0.85

Tested by

no test coverage detected