Unlock Claude Code's 1M Token Context Window: Two Lines in settings.json Eliminate Auto-Compaction
Set ANTHROPIC_DEFAULT_HAIKU_MODEL and ANTHROPIC_DEFAULT_SONNET_MODEL to claude-sonnet-4-6-1m in .claude/settings.json to run all Claude Code tasks on the 1M token context window. Build an entire SaaS in one session without auto-compaction interrupting your flow.
A two-line addition to .claude/settings.json expands Claude Code’s context window from 200K to 1M tokens, eliminating auto-compaction during long coding sessions.
The Configuration
Add the following to .claude/settings.json (create if it doesn’t exist):
{
"env": {
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-6-1m",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6-1m"
}
}
After adding this, restart Claude Code and switch to the Sonnet model for the settings to take effect.
What Changes
Claude Code internally routes tasks across multiple models. Haiku handles sub-tasks and lightweight processing; Sonnet handles the primary reasoning work. These environment variables override those defaults with claude-sonnet-4-6-1m, which means all tasks run on the 1M token context window.
In standard operation, Claude Code runs auto-compaction as codebases grow—summarizing and truncating older conversation history and code references. With 1M context enabled, this compaction threshold moves dramatically further out, allowing you to maintain the full development context across long sessions.
Practical effects:
- Reference codebases with thousands of files simultaneously
- Retain all change history and decision context throughout a session
- Build entire SaaS projects in a single session without context loss
- Eliminate the “memory loss” problem from mid-session compaction
Technical Background
According to Anthropic’s official documentation, Claude Opus 4.6 and Sonnet 4.6 support 1M token context windows via the context-1m-2025-08-07 beta header. The claude-sonnet-4-6-1m model ID is a dedicated endpoint that automatically applies this beta header.
1M token context translates to approximately:
- 750,000 words (English)
- 3.4 million Unicode characters
Cost Implications
An important caveat: Anthropic applies long context pricing to requests exceeding 200K tokens. Extended sessions will cost more than standard usage.
Cost-effectiveness considerations:
- Short tasks and simple queries: 200K context is sufficient, no additional cost
- Large codebase long-form development sessions: 1M context provides clear value
- Cost-conscious users: Combining with the multi-model optimization strategy covered yesterday—applying 1M context only where it’s genuinely needed—is the rational approach
Setting File Location
.claude/settings.json can be placed in the project root (per-repository settings) or home directory ~/.claude/settings.json (system-wide default).
If the settings file doesn’t exist:
mkdir -p ~/.claude && cat > ~/.claude/settings.json << 'EOF'
{
"env": {
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-6-1m",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6-1m"
}
}
EOF
Summary
This is a practical technique made viable by the 1M context support in Claude Sonnet 4.6. By overriding Claude Code’s internal model assignments, it significantly reduces one of the biggest obstacles to agentic coding—context loss from mid-session compaction.
For developers working on large-scale projects, particularly those who need sustained coherence across long development sessions, this configuration is worth testing. The long context pricing is the primary tradeoff to evaluate against your use case.
Related articles:
- Claude Sonnet 4.6 Release: Opus-Level Intelligence at Sonnet Price
- Cut OpenClaw API Costs by Up to 90%
Source:
- Anthropic official model documentation
- Claude Code settings reference
関連記事
Claude Code 1Mトークンコンテキスト解放——settings.json 2行で自動圧縮なしにSaaS全体を一気に構築
.claude/settings.jsonにANTHROPIC_DEFAULT_HAIKU_MODELとANTHROPIC_DEFAULT_SONNET_MODELをclaude-sonnet-4-6-1mに設定するだけで、Claude Codeの全タスクが1Mトークンコンテキストウィンドウで動作する。自動圧縮なしでコードベース全体を保持しながら開発できる実用的なテクニック。
「LLMは厳格なLintで品質が劇的に向上する」——TypeScript Go・Oxlint・Oxfmtで構築するAI時代のフロントエンド開発環境
MetaエンジニアでOpenClaw開発者のChristoph Nakazawa氏が公開した技術記事が注目を集めている。TypeScript Goによる10倍速型チェック、OxlintとOxfmtの導入、そして厳格なガードレールがLLMコード品質を劇的に改善するという実証データを紹介。
2026年2月版:用途別おすすめAIツールガイド - 開発・業務・クリエイティブ
結局どれがおすすめなの?に答える。人気度と実績で厳選したAIツール15選を、開発者向け・業務改善向け・クリエイティブ向けの3カテゴリで紹介。Claude Sonnet 4.6、Cursor、OpenClawなど、2026年2月時点で最も注目すべきツールを網羅。
人気記事
Claude Code v2.1.93 リリース - PreToolUseフック延期決定やフリッカーFREE渲染など
AnthropicがClaude Code v2.1.93をリリース。PreToolUseフックの延期決定機能、フリッカー-freeレンダリングオプション、PermissionDeniedフック、名前付きサブエージェントのタイプアヘッド対応などを含む。
Claude Code v2.1.92 リリース - forceRemoteSettingsRefreshやBedrockセットアップウィザードなど
AnthropicがClaude Code v2.1.92をリリース。forceRemoteSettingsRefreshポリシー設定、Bedrockセットアップウィザード、costコマンドの改善など多数の機能追加とバグ修正を含む。
Claude Code v2.1.84 リリース - PowerShellツールプレビューと環境設定の強化
Claude Code v2.1.84がリリース。Windows向けのPowerShellツール、環境変数によるモデル選択のカスタマイズアイドルセッション処理の改善などが含まれる。
最新記事
Claude Code v2.1.93 リリース - PreToolUseフック延期決定やフリッカーFREE渲染など
AnthropicがClaude Code v2.1.93をリリース。PreToolUseフックの延期決定機能、フリッカー-freeレンダリングオプション、PermissionDeniedフック、名前付きサブエージェントのタイプアヘッド対応などを含む。
Claude Code v2.1.92 リリース - forceRemoteSettingsRefreshやBedrockセットアップウィザードなど
AnthropicがClaude Code v2.1.92をリリース。forceRemoteSettingsRefreshポリシー設定、Bedrockセットアップウィザード、costコマンドの改善など多数の機能追加とバグ修正を含む。
Claude Code v2.1.91 リリース - MCPツール結果の永続化とEditツールの最適化
Claude Code v2.1.91ではMCPツールの結果サイズの上書き、シェル実行の制御強化、Editツールの効率改善などが行われた。