Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model-hub): keep user Claude settings on Hub turns (#2230)
Call Whiteebe1fe952001
diff --git a/core/agent_auth_service.py b/core/agent_auth_service.pyindex 728092681..96a708f9e 100644--- a/core/agent_auth_service.py+++ b/core/agent_auth_service.py@@ -1557,6 +1557,7 @@ class AgentAuthService:# still get the key into the control-channel SDK client.from vibe.claude_config import (CLAUDE_MEMORY_DISABLED_SETTINGS,+ CLAUDE_SETTING_SOURCES,build_claude_subprocess_env,)@@ -1581,7 +1582,7 @@ class AgentAuthService:"cwd": working_path,"env": claude_env,"settings": CLAUDE_MEMORY_DISABLED_SETTINGS,- "setting_sources": ["user", "project", "local"],+ "setting_sources": CLAUDE_SETTING_SOURCES,"max_buffer_size": CLAUDE_SDK_MAX_BUFFER_SIZE,}permission_mode = getattr(self._resolve_backend_config("claude"), "permission_mode", None)@@ -2945,9 +2946,9 @@ class AgentAuthService:on_diagnostic: Callable[[str], None] | None = None,) -> str:"""Run an isolated turn through the same Claude Agent SDK transport."""- from modules.agents.model_hub import claude_setting_sources_for_launchfrom vibe.claude_config import (CLAUDE_MEMORY_DISABLED_SETTINGS,+ CLAUDE_SETTING_SOURCES,build_claude_subprocess_env,)@@ -2966,7 +2967,7 @@ class AgentAuthService:option_kwargs: dict[str, Any] = {"permission_mode": "bypassPermissions","cwd": cwd,- "setting_sources": claude_setting_sources_for_launch(None),+ "setting_sources": CLAUDE_SETTING_SOURCES,"sandbox": {"enabled": False},"tools": [],"max_turns": 1,diff --git a/core/handlers/session_handler.py b/core/handlers/session_handler.pyindex 0158513f6..a694b580b 100644--- a/core/handlers/session_handler.py+++ b/core/handlers/session_handler.py@@ -1528,7 +1528,6 @@ class SessionHandler(BaseHandler):effective_model = explicit_model or agent_modelfrom modules.agents.model_hub import (build_claude_hub_env,- claude_setting_sources_for_launch,claude_settings_for_launch,launch_for_context,)@@ -1578,6 +1577,7 @@ class SessionHandler(BaseHandler):# away from this site's auth_mode handling.from vibe.claude_config import (CLAUDE_MEMORY_DISABLED_SETTINGS,+ CLAUDE_SETTING_SOURCES,build_claude_subprocess_env,)from core.git_runtime import prepend_vendored_git_to_path@@ -1614,7 +1614,7 @@ class SessionHandler(BaseHandler):"fork_session": bool(fork_session and stored_claude_session_id),"extra_args": extra_args,"settings": claude_settings_for_launch(CLAUDE_MEMORY_DISABLED_SETTINGS, model_hub_launch),- "setting_sources": claude_setting_sources_for_launch(model_hub_launch),+ "setting_sources": CLAUDE_SETTING_SOURCES,"skills": [],"sandbox": CLAUDE_REMOTE_SANDBOX,# Disable interactive-only Claude Code tools that remote IM sessionsdiff --git a/modules/agents/model_hub.py b/modules/agents/model_hub.pyindex 8f84d5c99..9684f5ae2 100644--- a/modules/agents/model_hub.py+++ b/modules/agents/model_hub.py@@ -208,23 +208,19 @@ def bind_persisted_launch(context: Any, payload: object) -> ModelHubLaunch | Nonreturn launch-def claude_setting_sources_for_launch(launch: ModelHubLaunch | None) -> list[str]:- if launch is not None and launch.channel == "hub":- # Project/local settings remain available. Connection settings are- # pinned separately because HOME can also be the project directory.- return ["project", "local"]- return ["user", "project", "local"]--def claude_settings_for_launch(base_settings: str, launch: ModelHubLaunch | None) -> str:- """Pin Hub connection settings above every native settings source."""+ """Pin Hub connection settings above every native settings source.++ Launch settings outrank user, project, and local settings, so a Hub turn+ keeps the user's own Claude preferences while the Hub owns the connection.+ """if launch is None or launch.channel != "hub":return base_settingssettings = json.loads(base_settings)connection_env = build_claude_hub_env({}, launch)# Catalog limits assist planning through the subprocess environment. They- # must not become launch-settings overrides of native project/local choices.+ # must not become launch-settings overrides of native user/project/local choices.connection_env.pop("CLAUDE_CODE_MAX_CONTEXT_TOKENS", None)connection_env.pop("CLAUDE_CODE_MAX_OUTPUT_TOKENS", None)# Timeout defaults likewise yield to an explicit native choice.diff --git a/tests/e2e/test_model_hub_catalog_consumer.py b/tests/e2e/test_model_hub_catalog_consumer.pyindex 15e3dde9b..b929edab6 100644--- a/tests/e2e/test_model_hub_catalog_consumer.py+++ b/tests/e2e/test_model_hub_catalog_consumer.py@@ -21,17 +21,18 @@ from modules.agents.model_hub import (ModelHubLaunch,build_claude_hub_env,build_codex_hub_launch,- claude_setting_sources_for_launch,claude_settings_for_launch,)from tests.e2e.drivers.model_hub_app import ModelHubTestAppfrom tests.e2e.drivers.mock_llm_upstream import MockLLMUpstream+from tests.e2e.test_model_hub_routing import _request_credentialfrom vibe.backend_model_catalog import (CodexHubCatalog,_codex_hub_catalog_bytes,_codex_hub_catalog_path,_publish_codex_hub_catalog,)+from vibe.claude_config import CLAUDE_SETTING_SOURCESpytestmark = pytest.mark.e2e_model_hub@@ -424,7 +425,7 @@ def test_claude_consumer_preserves_explicit_limit_settings(tmp_path, rejected_ex[str(binary), "-p", "Reply with hello 中文.", "--output-format", "json","--model", launch.runtime_model, "--tools", "", "--max-turns", "1",- "--setting-sources", ",".join(claude_setting_sources_for_launch(launch)),+ "--setting-sources", ",".join(CLAUDE_SETTING_SOURCES),"--settings", claude_settings_for_launch("{}", launch),],cwd=project,@@ -444,3 +445,68 @@ def test_claude_consumer_preserves_explicit_limit_settings(tmp_path, rejected_ex# SessionHandler coverage separately checks delivery of that planning value.if fixture_settings is not None:assert json.loads(fixture_settings.read_text()) == {"env": selected_limits}+++def test_claude_hub_launch_applies_user_settings_but_not_their_connection(tmp_path, rejected_external_proxy):+ """MH-CLAUDE-LAUNCH-002: a Hub turn keeps the user's Claude preferences, not their transport."""+ import claude_agent_sdk++ binary = Path(claude_agent_sdk.__file__).parent / "_bundled" / "claude"+ if not binary.is_file():+ pytest.skip("The installed Claude SDK has no bundled CLI")+ runtime = _isolated_runtime(tmp_path, rejected_external_proxy)+ binary = _loopback_cli(binary, runtime)+ project = runtime.home / "project"+ project.mkdir(parents=True)+ runtime.env["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "1"+ runtime.env["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py"+ native_key = "native-user-settings-fixture"+ # Commit/PR attribution is the preference users see in their history. Custom+ # text makes its arrival observable in the prompt the CLI sends.+ attribution = {"commit": "User commit trailer 中文", "pr": "User PR footer 中文"}+ with MockLLMUpstream() as gateway, MockLLMUpstream() as native:+ gateway.configure(protocol="anthropic")+ native.configure(protocol="anthropic")+ user_settings = Path(runtime.env["CLAUDE_CONFIG_DIR"]) / "settings.json"+ user_settings.parent.mkdir()+ user_payload = json.dumps({+ "attribution": attribution,+ "env": {+ "ANTHROPIC_BASE_URL": native.url,+ "ANTHROPIC_AUTH_TOKEN": native_key,+ "ANTHROPIC_API_KEY": native_key,+ },+ }, ensure_ascii=False)+ user_settings.write_text(user_payload)+ launch = ModelHubLaunch(+ backend="claude",+ channel="hub",+ requested_model="hub-model",+ target_model="hub-model",+ runtime_model="hub-model",+ gateway_base_url=gateway.url,+ gateway_token="hub-user-settings-fixture",+ )+ result = subprocess.run(+ [+ str(binary), "-p", "Reply with hello.", "--output-format", "json",+ "--model", launch.runtime_model, "--max-turns", "1",+ "--setting-sources", ",".join(CLAUDE_SETTING_SOURCES),+ "--settings", claude_settings_for_launch("{}", launch),+ ],+ cwd=project,+ env=build_claude_hub_env(runtime.env, launch),+ capture_output=True,+ text=True,+ timeout=30,+ )+ assert result.returncode == 0, (result.stdout[-2000:], result.stderr[-2000:])+ native_calls = [request for request in native.requests() if request["path"] == "/v1/messages"]+ captured = [request for request in gateway.requests() if request["path"] == "/v1/messages"]+ assert native_calls == [], "Claude bypassed Model Hub using user settings"+ assert captured+ assert {_request_credential(request) for request in captured} == {launch.gateway_token}+ prompt = json.dumps([request["body"] for request in captured], ensure_ascii=False)+ assert attribution["commit"] in prompt+ assert attribution["pr"] in prompt+ assert user_settings.read_text() == user_payloaddiff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 1ed749a59..c774708ce 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -456,6 +456,14 @@ scenarios:test: tests/e2e/test_model_hub_routing.py::test_mh_claude_launch_001_settings_cannot_bypass_the_configured_routerelated_tests:- tests/e2e/test_model_hub_catalog_consumer.py::test_claude_consumer_preserves_explicit_limit_settings+ - id: MH-CLAUDE-LAUNCH-002+ name: Claude Hub turns apply the user's own Claude settings without letting them change Hub transport+ status: covered+ kind: injection+ layer: e2e+ test: tests/e2e/test_model_hub_catalog_consumer.py::test_claude_hub_launch_applies_user_settings_but_not_their_connection+ related_tests:+ - tests/test_claude_cli_path.py::test_session_handler_pins_hub_connection_in_launch_settings- id: MH-CODEX-LAUNCH-001name: Native Codex provider settings preserve the configured Hub Source and upstream modelstatus: covereddiff --git a/tests/test_claude_cli_path.py b/tests/test_claude_cli_path.pyindex 242db6dd1..0e823594f 100644--- a/tests/test_claude_cli_path.py+++ b/tests/test_claude_cli_path.py@@ -608,7 +608,7 @@ def test_session_handler_preserves_explicit_limits_and_passes_alias_planning_metexpected = explicit if explicit is not None else fallback if has_metadata else Noneassert options.env.get(key) == expectedassert key not in json.loads(options.settings).get("env", {})- assert options.setting_sources == (["project", "local"] if channel == "hub" else ["user", "project", "local"])+ assert options.setting_sources == ["user", "project", "local"]def test_session_handler_pins_hub_connection_in_launch_settings(monkeypatch, tmp_path: Path) -> None:@@ -646,7 +646,7 @@ def test_session_handler_pins_hub_connection_in_launch_settings(monkeypatch, tmpassert settings["env"]["ANTHROPIC_AUTH_TOKEN"] == "hub-settings-fixture-token"assert settings["env"]["ANTHROPIC_API_KEY"] == ""assert settings["autoMemoryEnabled"] is False- assert options.setting_sources == ["project", "local"]+ assert options.setting_sources == ["user", "project", "local"]assert options.extra_args["model"] == "claude-opus-5"diff --git a/tests/test_model_hub_injection.py b/tests/test_model_hub_injection.pyindex 7c847d1d9..2d82614c2 100644--- a/tests/test_model_hub_injection.py+++ b/tests/test_model_hub_injection.py@@ -21,7 +21,6 @@ from modules.agents.model_hub import (build_codex_hub_launch,bind_launch,bind_persisted_launch,- claude_setting_sources_for_launch,claude_settings_for_launch,launch_for_context,opencode_model_for_overlay,@@ -118,7 +117,6 @@ def test_direct_launch_does_not_inject_provider_credentials():base_env = {"ANTHROPIC_AUTH_TOKEN": "user-token", "PATH": "/bin"}assert build_claude_hub_env(base_env, launch) == base_envassert build_codex_hub_launch(["--flag"], {"OPENAI_API_KEY": "user-key"}, launch) == (["--flag"], None)- assert claude_setting_sources_for_launch(launch) == ["user", "project", "local"]def test_hub_launch_masks_inherited_claude_auth_and_injects_gateway():@@ -142,7 +140,6 @@ def test_hub_launch_masks_inherited_claude_auth_and_injects_gateway():assert env["CLAUDE_CODE_MAX_CONTEXT_TOKENS"] == "999999"assert env["CLAUDE_CODE_MAX_OUTPUT_TOKENS"] == "999999"assert env["CLAUDE_CODE_OAUTH_TOKEN"] == ""- assert claude_setting_sources_for_launch(launch) == ["project", "local"]def test_claude_hub_settings_own_connection_after_native_and_sdk_env_merges():diff --git a/vibe/claude_config.py b/vibe/claude_config.pyindex 659c230ec..0eb5006ed 100644--- a/vibe/claude_config.py+++ b/vibe/claude_config.py@@ -43,6 +43,12 @@ MANAGED_ENV_VALUES = {# the user's Claude Code settings.CLAUDE_MEMORY_DISABLED_SETTINGS = '{"autoMemoryEnabled":false}'+# Every Avibe launch reads all native settings sources, so the user's own Claude+# preferences (commit attribution, hooks, permissions) apply as they do in a+# terminal. Anything Avibe must own is pinned in the process-local ``--settings``+# override, which outranks each of these sources.+CLAUDE_SETTING_SOURCES = ["user", "project", "local"]+# Keys we recognise inside ``~/.claude/settings.json``'s ``env`` block.# Claude Code assigns header semantics from the selected variable, independently# from ``ANTHROPIC_BASE_URL``. Avibe preserves that native distinction instead