# CLAUDE_CODE_MAX_CONTEXT_TOKENS

> It tells Claude Code the model's real context size.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CLAUDE_CODE_MAX_CONTEXT_TOKENS environment variable

## Think of it like

It is like you tell a friend the real size of a box. The label on it was wrong.

## Definition

CLAUDE_CODE_MAX_CONTEXT_TOKENS tells Claude Code the real size of the model's context window. Claude Code guesses the size from the model's name. But through a gateway, a name can hide a model of a different size. Set this so the squeeze point and the meter fit the real model.

## Example

Emma's gateway serves a model with a 128,000 token window under a Claude name. Chats crashed when full. She sets the real size, and they squeeze in time.

## Example code

```bash
export ANTHROPIC_BASE_URL=https://llm.example.com
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=128000
claude
```

Match a gateway model's real window.

## Why it matters

If Claude Code thinks the window is too big, a chat can spill over before it is squeezed.

## Common mistake

Setting it on a direct link to fit more in. It only describes the model. It cannot make the window bigger.

## Three principles

- **Says the real size.** Not a bigger one.
- **For gateways.** Odd model names.
- **Fixes the squeeze point.** And the meter.

## Related terms

- [Context Window](https://learn.benibix.com/term/ai/context-window)
- [ANTHROPIC_BASE_URL](https://learn.benibix.com/term/ai/anthropic-base-url-variable)
- [CLAUDE_CODE_AUTO_COMPACT_WINDOW](https://learn.benibix.com/term/ai/claude-code-auto-compact-window-variable)

---

Source: https://learn.benibix.com/term/ai/claude-code-max-context-tokens-variable
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
