From ac054c31f646c22cf36fe8173fe9d2fec6281106 Mon Sep 17 00:00:00 2001 From: majdyz Date: Mon, 13 Apr 2026 12:15:39 +0000 Subject: [PATCH] perf(copilot): trigger compaction at 100K tokens instead of 140K Set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 to compact at 50% of 200K context window (100K) instead of the default 70% (140K). Context >200K accounts for 54% of cost despite being only 3% of calls. Earlier compaction keeps context smaller and reduces cache creation. --- autogpt_platform/backend/backend/copilot/sdk/env.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autogpt_platform/backend/backend/copilot/sdk/env.py b/autogpt_platform/backend/backend/copilot/sdk/env.py index b1f232e5d1..bd03391888 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/env.py +++ b/autogpt_platform/backend/backend/copilot/sdk/env.py @@ -100,6 +100,11 @@ def build_sdk_env( # that OpenRouter rejects. Safe for all modes — direct Anthropic ignores it. env["CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS"] = "1" + # Trigger context compaction earlier — default is 70% of 200K = 140K. + # Set to 50% = 100K to keep context smaller and reduce cache creation costs. + # Context >200K accounts for 54% of total cost despite being only 3% of calls. + env["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] = "50" + # Disable gzip on API responses to prevent ZlibError decompression # failures (see oven-sh/bun#23149, anthropics/claude-code#18302). # Appended to any existing ANTHROPIC_CUSTOM_HEADERS (OpenRouter mode