From 7de80e6717a984cf959e2d65be125c204c495364 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 11 Mar 2026 18:17:26 +0900 Subject: [PATCH] fix(context-window-monitor): show actual reminder limits --- ...indow-monitor.model-context-limits.test.ts | 3 +++ src/hooks/context-window-monitor.ts | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/hooks/context-window-monitor.model-context-limits.test.ts b/src/hooks/context-window-monitor.model-context-limits.test.ts index 2b2c9cc61..531b87963 100644 --- a/src/hooks/context-window-monitor.model-context-limits.test.ts +++ b/src/hooks/context-window-monitor.model-context-limits.test.ts @@ -86,5 +86,8 @@ describe("context-window-monitor modelContextLimitsCache", () => { // then expect(output.output).toContain("context remaining") + expect(output.output).toContain("262,144-token context window") + expect(output.output).toContain("[Context Status: 72.5% used (190,000/262,144 tokens), 27.5% remaining]") + expect(output.output).not.toContain("1,000,000") }) }) diff --git a/src/hooks/context-window-monitor.ts b/src/hooks/context-window-monitor.ts index f749bd4e5..ec5d93061 100644 --- a/src/hooks/context-window-monitor.ts +++ b/src/hooks/context-window-monitor.ts @@ -1,7 +1,6 @@ import type { PluginInput } from "@opencode-ai/plugin" import { createSystemDirective, SystemDirectiveTypes } from "../shared/system-directive" -const ANTHROPIC_DISPLAY_LIMIT = 1_000_000 const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000 const CONTEXT_WARNING_THRESHOLD = 0.70 @@ -18,11 +17,15 @@ function getAnthropicActualLimit(modelCacheState?: ModelCacheStateLike): number : DEFAULT_ANTHROPIC_ACTUAL_LIMIT } -const CONTEXT_REMINDER = `${createSystemDirective(SystemDirectiveTypes.CONTEXT_WINDOW_MONITOR)} +function createContextReminder(actualLimit: number): string { + const limitTokens = actualLimit.toLocaleString() -You are using Anthropic Claude with 1M context window. -You have plenty of context remaining - do NOT rush or skip tasks. + return `${createSystemDirective(SystemDirectiveTypes.CONTEXT_WINDOW_MONITOR)} + +You are using a ${limitTokens}-token context window. +You still have context remaining - do NOT rush or skip tasks. Complete your work thoroughly and methodically.` +} interface TokenInfo { input: number @@ -77,13 +80,12 @@ export function createContextWindowMonitorHook( remindedSessions.add(sessionID) - const displayUsagePercentage = totalInputTokens / ANTHROPIC_DISPLAY_LIMIT - const usedPct = (displayUsagePercentage * 100).toFixed(1) - const remainingPct = ((1 - displayUsagePercentage) * 100).toFixed(1) + const usedPct = (actualUsagePercentage * 100).toFixed(1) + const remainingPct = ((1 - actualUsagePercentage) * 100).toFixed(1) const usedTokens = totalInputTokens.toLocaleString() - const limitTokens = ANTHROPIC_DISPLAY_LIMIT.toLocaleString() + const limitTokens = actualLimit.toLocaleString() - output.output += `\n\n${CONTEXT_REMINDER} + output.output += `\n\n${createContextReminder(actualLimit)} [Context Status: ${usedPct}% used (${usedTokens}/${limitTokens} tokens), ${remainingPct}% remaining]` }