[BUG] `CLAUDE_CODE_AUTO_COMPACT_WINDOW` is capped at the hardcoded model context window size (preventing larger context for custom APIs)

Resolved 💬 3 comments Opened May 11, 2026 by Masterisk-F Closed Jun 16, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

I am using Claude Code with a custom API endpoint (ANTHROPIC_BASE_URL) and custom models that support a larger context window (e.g., 1M tokens). However, I've observed that CLAUDE_CODE_AUTO_COMPACT_WINDOW only works when the value is smaller than the model's hardcoded default (200k).

If I set a value larger than 200k (e.g., 1,000,000), the setting appears to be ignored , and Claude Code triggers compaction at the default 200k limit.

Observed Behavior

  • If CLAUDE_CODE_AUTO_COMPACT_WINDOW is set to 100,000 (less than 200k), compaction correctly triggers at 100k.
  • If CLAUDE_CODE_AUTO_COMPACT_WINDOW is set to 1,000,000 (greater than 200k), compaction triggers at the hardcoded 200k limit.

What Should Happen?

CLAUDE_CODE_AUTO_COMPACT_WINDOW should be honored even if it exceeds the hardcoded default window size, especially when using custom base URLs where the model's physical limit might be higher than Claude's standard 200k.

Error Messages/Logs

Steps to Reproduce

  1. Use a custom API and model that supports > 200k tokens.

``bash
export ANTHROPIC_BASE_URL=http://your-custom-endpoint
export ANTHROPIC_DEFAULT_OPUS_MODEL=your-1m-context-model
``

  1. Launch Claude Code with a large compaction window:

``bash
CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 claude
``

  1. Monitor the token usage and compaction behavior.

Claude Model

Other

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.138

Platform

Other

Operating System

Other Linux

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗