Claude Code 100萬 context window 是雙刃劍,需妥善管理以避脈絡污染
Claude Code 100萬 context window 是雙刃劍,需妥善管理以避脈絡污染。
Claude Code 的 1M context window 雖能處理更複雜任務,卻易因會話管理不善導致脈絡污染,作者強調這是雙刃劍,並分享透過 autocompact 門檻自訂調整,例如設為 400k 作為良好折衷。
脈絡視窗管理技巧
作者修正引言以突出要點,指出 1M context window 允許 Claude 執行更複雜任務,但若未善加管理會話,則會產生更多脈絡污染。解決之道包括自訂 autocompact 門檻,有效降低 context window 大小,例如執行指令 CLAUDE_CODE_AUTO_COMPACT_WINDOW=400000,這是 400k context 的良好折衷方案,相關文件見 https://code.claude.com/docs/en/settings#environment-variables。
配置範圍系統
Claude Code 採用範圍(scope)系統決定配置適用位置與分享對象,幫助個人、團隊或企業部署時選擇合適方式。
可用範圍如下:
- Managed:伺服器管理設定、plist/registry 或系統級 managed-settings.json,影響機器上所有使用者,與團隊分享(IT 部署)。
- User:~/.claude/ 目錄,僅影響個人、跨所有專案,不分享。
- Project:程式庫內 .claude/,影響程式庫所有合作者,與團隊分享(git 提交)。
- Local:.claude/settings.local.json,僅影響個人於此程式庫,不分享(git 忽略)。
各範圍適用情境
- Managed scope:用於組織全域強制安全政策、不可覆寫的合規需求、IT/DevOps 標準化配置。
- User scope:個人偏好如主題、編輯器設定;跨專案工具與 plugin;安全儲存 API 金鑰與認證。
- Project scope:團隊共享設定如權限、hooks、MCP 伺服器;全團隊 plugin;合作者標準化工具。
- Local scope:特定專案個人覆寫;團隊分享前測試配置;僅適用單機設定。
範圍互動優先順序
相同設定於多範圍時,更特定範圍優先:
- Managed(最高)-不可被任何設定覆寫。
- 命令列參數-臨時會話覆寫。
- Local-覆寫 project 與 user 設定。
- Project-覆寫 user 設定。
- User(最低)-無其他指定時適用。
例如,使用者設定允許權限,但專案設定拒絕,則專案設定優先,權限被封鎖。
設定檔案機制
settings.json 是官方階層式配置機制:
- User 設定於 ~/.claude/settings.json,適用所有專案。
- Project 設定存於專案目錄:.claude/settings.json(git 控管、團隊分享);.claude/settings.local.json(不 git 控管,用於個人偏好與實驗,Claude Code 自動設定 git 忽略)。
Managed 設定支援多種傳遞機制(如 JSON 格式),不可被 user 或 project 覆寫。其他配置存於 ~/.claude.json,包括偏好(主題、通知、編輯模式)、OAuth 會話、user/local 範圍 MCP 伺服器配置、專案狀態(允許工具、信任設定)與快取;專案範圍 MCP 伺服器另存 .mcp.json。Claude Code 自動建立設定檔時間戳備份,保留最近五個以防資料遺失。
I edited the intro because I realized I buried the lede originally-
— Thariq (@trq212) April 16, 2026
The 1M context window is a double-edged sword. It allows Claude to do more complex tasks but it can also leads to more context pollution if you don't manage your session well.
This is how you do that: https://t.co/nVWS6cIwO2
You can also set your autocompact threshold yourself and effectively lower your context window if you'd prefer.
— Thariq (@trq212) April 16, 2026
For example, 400k context is a good compromise:
CLAUDE_CODE_AUTO_COMPACT_WINDOW=400000 claude
see docs here: https://t.co/NuhBuTSSDt
