# How to Configure 1M Context Window for Opus and Sonnet Models in Claudian

> Learn to configure the 1M context window for Claude Opus and Sonnet models in Claudian. Discover how the three-tier resolution system manages custom limits, suffix variants, and default settings for optimal performance.

- Repository: [YishenTu/claudian](https://github.com/YishenTu/claudian)
- Tags: how-to-guide
- Published: 2026-03-17

---

**Claudian supports 1 million token context windows for Claude Opus and Sonnet models through a three-tier resolution system that checks custom limits, `[1m]` suffix variants, and standard defaults in the `getContextWindowSize` function.**

Claudian is an open-source Obsidian plugin that integrates Claude AI with advanced model control features. Understanding how to configure the 1M context window for Opus and Sonnet models allows you to process significantly larger documents without truncation.

## Understanding the Context Window Hierarchy

The plugin determines token limits using a prioritized three-layer mechanism implemented in [`src/core/types/models.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/models.ts) (lines 100-114). The `getContextWindowSize` function evaluates limits in this strict order:

1. **Custom context limits** — If the model name exists in `settings.customContextLimits`, that value is used (must be a positive finite number).
2. **1M variant detection** — If the model name ends with `[1m]` (e.g., `opus[1m]` or `sonnet[1m]`), the function returns `CONTEXT_WINDOW_1M` (1,000,000 tokens).
3. **Standard fallback** — All other models receive `CONTEXT_WINDOW_STANDARD` (200,000 tokens).

## Enabling the 1M Variant in Settings

The simplest configuration method uses the built-in UI toggles to expose extended context models.

### Activating Extended Context Models

Navigate to the Claudian settings panel and enable **"Enable Opus 1M"** or **"Enable Sonnet 1M"**. This UI logic resides in [`src/features/settings/ClaudianSettings.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/settings/ClaudianSettings.ts) (lines 545-551). When activated, the model selector displays `opus[1m]` and `sonnet[1m]` variants alongside standard options.

Once selected, these variants trigger the 1 million token limit via the suffix detection branch in `getContextWindowSize` (lines 110-112 of [`src/core/types/models.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/models.ts)).

## Setting Custom Token Limits

For non-standard token allocations, configure specific values through the **custom context limits** map.

### Editing via Settings JSON

The `customContextLimits` schema is defined in [`src/core/types/settings.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/settings.ts) (lines 254-273). Add entries to your plugin [`data.json`](https://github.com/YishenTu/claudian/blob/main/data.json) or through the Custom Context Limits UI:

```json
{
  "customContextLimits": {
    "opus[1m]": 500000,
    "sonnet[1m]": 750000
  }
}

```

When `getContextWindowSize` encounters a model name matching a key in this map, it returns the specified value instead of the default constants. The UI validates these entries as positive finite integers, displaying warnings defined in [`src/i18n/types.ts`](https://github.com/YishenTu/claudian/blob/main/src/i18n/types.ts) (lines 208-210) for invalid inputs.

### Programmatic Configuration

You can also configure limits programmatically within plugin code:

```typescript
import { type ClaudianPlugin } from 'src/main';

async function setCustomLimits(plugin: ClaudianPlugin) {
  // Configure Opus 1M with a 500k token limit
  plugin.settings.customContextLimits = {
    ...plugin.settings.customContextLimits,
    'opus[1m]': 500_000,
  };
  await plugin.saveSettings();
}

```

## Where Context Limits Are Enforced

The configured window size propagates through two critical execution paths in the codebase.

In [`src/features/chat/ClaudianView.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/chat/ClaudianView.ts) (line 83), the chat view retrieves the limit when constructing API requests:

```typescript
const contextWindow = getContextWindowSize(model, this.plugin.settings.customContextLimits);

```

Simultaneously, [`src/core/sdk/transformSDKMessage.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/sdk/transformSDKMessage.ts) (line 157) uses the same helper to enforce limits on SDK payloads before transmission to Anthropic's API, ensuring the 1M configuration is respected end-to-end.

## Summary

- **Three-tier resolution**: Custom limits take precedence, followed by `[1m]` suffix detection, then the 200,000 token standard default.
- **UI activation**: Enable "Enable Opus 1M" or "Enable Sonnet 1M" toggles in settings to expose extended variants in the model selector.
- **Custom allocations**: Use `customContextLimits` in settings to specify exact token counts (e.g., 500,000 instead of 1,000,000).
- **Core implementation**: Resolution logic lives in [`src/core/types/models.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/models.ts), settings schema in [`src/core/types/settings.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/settings.ts), and UI controls in [`src/features/settings/ClaudianSettings.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/settings/ClaudianSettings.ts).

## Frequently Asked Questions

### What is the default context window for standard Opus and Sonnet models?

Standard models without the `[1m]` suffix default to 200,000 tokens (`CONTEXT_WINDOW_STANDARD`), as defined at line 114 of [`src/core/types/models.ts`](https://github.com/YishenTu/claudian/blob/main/src/core/types/models.ts).

### Can I set a custom limit lower than 1 million tokens for the 1M variants?

Yes. Add an entry to `customContextLimits` using the specific model name (e.g., `"opus[1m]": 400000`). The custom limit overrides the default 1 million token constant returned by the suffix detection logic.

### Why does my model selector not show the 1M variants?

You must enable the **"Enable Opus 1M"** or **"Enable Sonnet 1M"** toggle in Claudian settings. These boolean flags control visibility in the model selector UI implemented in [`src/features/settings/ClaudianSettings.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/settings/ClaudianSettings.ts) (lines 545-551).

### How does Claudian validate custom context limit entries?

The UI enforces positive finite integers through validation logic tied to [`src/i18n/types.ts`](https://github.com/YishenTu/claudian/blob/main/src/i18n/types.ts) (lines 208-210). Invalid entries trigger localized warning messages and prevent application of non-numeric or infinite limits.