As long horizon tasks become the new norm, auto compaction strategies and long term memory are becoming a lot more important. Get a wrong and Claude Code gets lost and destroys your codebase. Get it right and it can do a days work in an hour while you AFK. I saw many discussions on whether to use the standard 200k context vs 1m context when it first came out, and seems many people still prefer 200k, as 1m causes way too much context rot. That said, auto compacting at 200k can cause the same degraded output on long running tasks. Claude Code unfortunately doesn’t give us much control over auto compaction, when it occurs, or how it compacts, but they do give us a few env variables to play with. The one I found most effective is CLAUDE_CODE_MAX_CONTEXT_TOKENS, which lets you control the effective context window size. I have mine set to auto compact at 300k, which seems like the sweet spot for me. That in combination with a CLAUDE .md that directs long term memory features (memory, task list, git history, doc creation, etc.) has resulted in strong reliable performance for most of my projects. Would love to hear others strategies for this. And hope Anthropic adds some additional controls for us to fine tune our compaction strategies moving forward. submitted by /u/JCodesMore
Originally posted by u/JCodesMore on r/ClaudeCode
