Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/copilot): disable Claude Code system prompt (#14163)

Toran Bruce Richards7c5baa5bf54b
diff --git a/autogpt_platform/backend/backend/copilot/config.py b/autogpt_platform/backend/backend/copilot/config.py
index ac9292e6de..b80280150f 100644
--- a/autogpt_platform/backend/backend/copilot/config.py
+++ b/autogpt_platform/backend/backend/copilot/config.py
@@ -504,13 +504,12 @@ class ChatConfig(BaseSettings):
"(429, 5xx, ECONNRESET) before surfacing the error to the user.",
)
claude_agent_cross_user_prompt_cache: bool = Field(
- default=True,
- description="Enable cross-user prompt caching via SystemPromptPreset. "
- "The Claude Code default prompt becomes a cacheable prefix shared "
- "across all users, and our custom prompt is appended after it. "
+ default=False,
+ description="Include the Claude Code default prompt as a cacheable prefix "
+ "shared across all users, with our custom prompt appended after it. "
"Dynamic sections (working dir, git status, auto-memory) are excluded "
- "from the prefix. Set to False to fall back to passing the system "
- "prompt as a raw string.",
+ "from the prefix. Set to True to opt in. When False, our system prompt "
+ "is passed as a raw string and replaces the Claude Code default prompt.",
)
baseline_prompt_cache_ttl: str = Field(
default="1h",
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py
index 8b80d1b565..43af253ed8 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service.py
@@ -2353,9 +2353,10 @@ def _build_system_prompt_value(
the single source of truth — no external install needed.
When *cross_user_cache* is disabled, the raw *system_prompt* string is
- returned. Note this causes the CLI to REPLACE its built-in prompt via
- ``--system-prompt`` (vs ``--append-system-prompt`` for the preset),
- which loses Claude Code's default prompt and its cache markers entirely.
+ returned. This intentionally replaces the CLI's built-in prompt via
+ ``--system-prompt`` (vs ``--append-system-prompt`` for the preset).
+ Per-session prompt caching remains available; only the shared Claude Code
+ preset prefix and its cross-user cache reuse are removed.
An empty *system_prompt* is accepted: the preset dict will have
``append: ""`` which the SDK treats as no custom suffix.
@@ -4869,9 +4870,9 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
sid,
)
- # Use SystemPromptPreset with exclude_dynamic_sections=True on
- # every turn — including resumed ones — so all turns share the
- # same static prefix and hit the cross-user prompt cache.
+ # When cross-user caching is enabled, use SystemPromptPreset with
+ # exclude_dynamic_sections=True on every turn — including resumed
+ # ones — so all turns share the same static prefix.
#
# Requires CLI ≥ 2.1.98 (older CLIs crash when excludeDynamicSections
# is combined with --resume). claude-agent-sdk >= 0.1.64 bundles
@@ -5367,8 +5368,8 @@ async def stream_chat_completion_sdk( # pyright: ignore[reportGeneralTypeIssues
delete_stale_cli_session_file(sdk_cwd, session_id, log_prefix)
sdk_options_retry.resume = None
sdk_options_retry.session_id = session_id
- # Recompute system_prompt for retry — the preset is safe on
- # every turn (requires CLI ≥ 2.1.98, bundled in
+ # Recompute system_prompt for retry. When enabled, the preset
+ # is safe on every turn (requires CLI ≥ 2.1.98, bundled in
# claude-agent-sdk >= 0.1.64).
sdk_options_retry.system_prompt = _build_system_prompt_value(
system_prompt,
diff --git a/autogpt_platform/backend/backend/copilot/sdk/service_test.py b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
index 7fe0c75025..8cdff18c11 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/service_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/service_test.py
@@ -1005,9 +1005,10 @@ class TestSystemPromptPreset:
assert isinstance(fresh, dict)
assert fresh.get("exclude_dynamic_sections") is True
- def test_default_config_is_enabled(self, _clean_config_env):
- """The default value for claude_agent_cross_user_prompt_cache is True."""
+ def test_default_config_disables_claude_code_system_prompt(self, _clean_config_env):
+ """The default config passes only AutoGPT's Copilot system prompt."""
cfg = cfg_mod.ChatConfig(
+ _env_file=None,
use_openrouter=False,
api_key=None,
base_url=None,
@@ -1016,11 +1017,11 @@ class TestSystemPromptPreset:
thinking_advanced_model="anthropic/claude-opus-4-7",
aux_api_key="or-aux-key",
)
- assert cfg.claude_agent_cross_user_prompt_cache is True
+ assert cfg.claude_agent_cross_user_prompt_cache is False
- def test_env_var_disables_cache(self, _clean_config_env, monkeypatch):
- """CHAT_CLAUDE_AGENT_CROSS_USER_PROMPT_CACHE=false disables caching."""
- monkeypatch.setenv("CHAT_CLAUDE_AGENT_CROSS_USER_PROMPT_CACHE", "false")
+ def test_env_var_enables_cache(self, _clean_config_env, monkeypatch):
+ """CHAT_CLAUDE_AGENT_CROSS_USER_PROMPT_CACHE=true enables caching."""
+ monkeypatch.setenv("CHAT_CLAUDE_AGENT_CROSS_USER_PROMPT_CACHE", "true")
cfg = cfg_mod.ChatConfig(
use_openrouter=False,
api_key=None,
@@ -1030,7 +1031,7 @@ class TestSystemPromptPreset:
thinking_advanced_model="anthropic/claude-opus-4-7",
aux_api_key="or-aux-key",
)
- assert cfg.claude_agent_cross_user_prompt_cache is False
+ assert cfg.claude_agent_cross_user_prompt_cache is True
class TestStreamErrorCodePrefix: