openclaw - ✅(Solved) Fix [Bug]: Session context limit shows 200k instead of 1M for Anthropic Opus/Sonnet 4 models [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#66766Fetched 2026-04-15 06:24:29
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
cross-referenced ×2referenced ×2commented ×1

Session context limit displays 200k instead of the correct 1M for Anthropic Claude Opus 4 and Sonnet 4 models. openclaw models list correctly shows 977k, but /status and the Control UI show Context: 439k/200k (220%).

Root Cause

In src/agents/context.ts, resolveContextTokensForModel() line 402-404:

const modelParams = resolveConfiguredModelParams(params.cfg, ref.provider, ref.model);
if (modelParams?.context1m === true && isAnthropic1MModel(ref.provider, ref.model)) {
  return ANTHROPIC_CONTEXT_1M_TOKENS;
}

This requires params.context1m: true in the model config entry. But runtime discovery (used by models list) correctly reports 977k via the provider plugin. The session context path calls resolveContextTokensForModel with allowAsyncLoad: false (line 1232 of session-utils.ts), which skips async discovery and falls through to a 200k default.

The ANTHROPIC_1M_MODEL_PREFIXES array already contains ["claude-opus-4", "claude-sonnet-4"] — the model IS recognized as 1M-capable. The issue is that the 1M return path is gated behind a config flag (context1m: true) that users don't know they need to set.

Fix Action

Fix / Workaround

Additional information

Workaround: add params: { context1m: true } to the model entry in agents.defaults.models.

PR fix notes

PR #66790: fix: return 1M context tokens for Anthropic Opus/Sonnet 4 without context1m config

Description (problem / solution / changelog)

Summary

Fixes incorrect 200k context limit display for Anthropic Claude Opus 4 and Sonnet 4 models in `/status* and Control UI.

Root Cause

resolveContextTokensForModel()\* in src/agents/context.ts* required BOTH context1m: true\* in config AND isAnthropic1MModel()* to return 1M tokens. Users without the explicit config flag got the 200k default fallback even though the model is correctly identified as 1M-capable.

Fix

Removed the context1m: true\* config requirement. When isAnthropic1MModel()* returns true (model ID starts with claude-opus-4\* or claude-sonnet-4*), return `ANTHROPIC_CONTEXT_1M_TOKENS* unconditionally. The model identification is already sufficient — the config flag is redundant.

Test Plan

  • Unit tests pass
  • `openclaw models list* shows 977k for claude-opus-4-6
  • /status\* shows correct ~1M context limit without context1m: true* config

Closes openclaw#66766

Changed files

  • src/agents/context.ts (modified, +1/-1)

PR #66862: fix: return 1M context for Anthropic Opus/Sonnet 4 without requiring context1m flag

Description (problem / solution / changelog)

Summary

Fixes #66766 Supersedes #66790 (same core fix, also addresses Greptile blocking issues)

Previously, resolveContextTokensForModel() required both isAnthropic1MModel() AND params.context1m === true to return 1M context tokens. This meant users had to manually add context1m: true to their model config, even though the model identity alone (matching claude-opus-4 or claude-sonnet-4 prefixes) is sufficient to determine 1M support.

The context1m config flag was a redundant gate: it only triggered for models already identified as 1M-capable by the prefix check, so it served as an opt-out rather than an opt-in — the opposite of what users expected.

Changes

  • src/agents/context.ts: isAnthropic1MModel() alone triggers the 1M return, no config flag needed
  • src/agents/context.ts: context1m: false explicitly opts out of 1M return (for OAuth/legacy token auth where Anthropic strips the context-1m beta header)
  • src/agents/context.ts: Removed dead resolveConfiguredModelParams() helper and AgentModelEntry type (re-added for context1m: false opt-out support)
  • src/agents/context.test.ts: Updated test title and expectation for opus-4-6 without context1m (fixes stale test flagged by Greptile)
  • src/agents/context.test.ts: Added test for context1m: false opt-out

Test plan

  • All 14 tests in src/agents/context.test.ts pass
  • claude-opus-4-6 without context1m flag now returns 1M (was 200k)
  • claude-haiku-3-5 with context1m: true still returns 200k (non-1M model not in prefix list)
  • claude-opus-4-6 with context1m: false returns 200k (opt-out for OAuth auth)

Changed files

  • src/agents/context.test.ts (modified, +33/-3)
  • src/agents/context.ts (modified, +10/-2)

Code Example

const modelParams = resolveConfiguredModelParams(params.cfg, ref.provider, ref.model);
if (modelParams?.context1m === true && isAnthropic1MModel(ref.provider, ref.model)) {
  return ANTHROPIC_CONTEXT_1M_TOKENS;
}

---

📚 Context: 439k/200k (220%) · 🧹 Compactions: 0

$ openclaw models list
anthropic/claude-opus-4-6    text+image   977k   yes   yes   default,configured
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Session context limit displays 200k instead of the correct 1M for Anthropic Claude Opus 4 and Sonnet 4 models. openclaw models list correctly shows 977k, but /status and the Control UI show Context: 439k/200k (220%).

Steps to reproduce

  1. Configure anthropic/claude-opus-4-6 as primary model (via HAI proxy or direct)
  2. Add the model to agents.defaults.models with only an alias (no params.context1m: true)
  3. Run openclaw models list → shows 977k (correct)
  4. Start a session, run /status → shows Context: Xk/200k (wrong limit)

Expected behavior

Session context limit should be 977k (or 1M), matching what openclaw models list reports. The runtime discovery already knows the correct value.

Actual behavior

Session context calculator returns 200k. The Control UI bar fills at 200k and shows 100%/overflow when the session is actually well within the 1M window.

Root cause analysis

In src/agents/context.ts, resolveContextTokensForModel() line 402-404:

const modelParams = resolveConfiguredModelParams(params.cfg, ref.provider, ref.model);
if (modelParams?.context1m === true && isAnthropic1MModel(ref.provider, ref.model)) {
  return ANTHROPIC_CONTEXT_1M_TOKENS;
}

This requires params.context1m: true in the model config entry. But runtime discovery (used by models list) correctly reports 977k via the provider plugin. The session context path calls resolveContextTokensForModel with allowAsyncLoad: false (line 1232 of session-utils.ts), which skips async discovery and falls through to a 200k default.

The ANTHROPIC_1M_MODEL_PREFIXES array already contains ["claude-opus-4", "claude-sonnet-4"] — the model IS recognized as 1M-capable. The issue is that the 1M return path is gated behind a config flag (context1m: true) that users don't know they need to set.

Suggested fix

When isAnthropic1MModel() returns true, return ANTHROPIC_CONTEXT_1M_TOKENS regardless of the context1m config param. The model identification is already sufficient — the config flag is redundant. Alternatively, fall through to the discovery cache before giving up.

OpenClaw version

2026.4.14 (323493f)

Operating system

macOS 15.4 (arm64)

Install method

pnpm dev

Model

anthropic/claude-opus-4-6

Provider / routing chain

openclaw -> HAI proxy (localhost:6655) -> anthropic

Logs, screenshots, and evidence

📚 Context: 439k/200k (220%) · 🧹 Compactions: 0

$ openclaw models list
anthropic/claude-opus-4-6    text+image   977k   yes   yes   default,configured

Impact and severity

Affected: All users with Anthropic Opus/Sonnet 4 models without explicit context1m: true config Severity: Medium (misleading UI, may trigger premature compaction) Frequency: Always (deterministic) Consequence: Control UI shows overflow, potential unnecessary context compaction at 200k instead of 1M

Additional information

Workaround: add params: { context1m: true } to the model entry in agents.defaults.models.

extent analysis

TL;DR

Remove the redundant context1m config flag requirement for Anthropic 1M models by modifying the resolveContextTokensForModel function.

Guidance

  • Modify the resolveContextTokensForModel function in src/agents/context.ts to return ANTHROPIC_CONTEXT_1M_TOKENS when isAnthropic1MModel returns true, regardless of the context1m config param.
  • As a temporary workaround, add params: { context1m: true } to the model entry in agents.defaults.models to ensure the correct context limit is applied.
  • Verify the fix by running openclaw models list and checking the Control UI to ensure the correct context limit is displayed.
  • Consider falling through to the discovery cache before giving up if the model is recognized as 1M-capable to handle cases where the config flag is not set.

Example

const modelParams = resolveConfiguredModelParams(params.cfg, ref.provider, ref.model);
if (isAnthropic1MModel(ref.provider, ref.model)) {
  return ANTHROPIC_CONTEXT_1M_TOKENS;
}

Notes

This fix assumes that the isAnthropic1MModel function correctly identifies Anthropic 1M models. If this function is not reliable, additional modifications may be necessary.

Recommendation

Apply the workaround by adding params: { context1m: true } to the model entry in agents.defaults.models until the modified resolveContextTokensForModel function is implemented and verified.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Session context limit should be 977k (or 1M), matching what openclaw models list reports. The runtime discovery already knows the correct value.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING