Skip to content

fix(claude): stop restoring stale local env after external provider switch - #80

Open
yan-6 wants to merge 1 commit into
freestylefly:mainfrom
yan-6:fix/claude-stale-original-env
Open

fix(claude): stop restoring stale local env after external provider switch#80
yan-6 wants to merge 1 commit into
freestylefly:mainfrom
yan-6:fix/claude-stale-original-env

Conversation

@yan-6

@yan-6 yan-6 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The __wesight_managed.claudeCode.originalEnv snapshot in ~/.claude/settings.json is captured once ("first seen wins") and never updated.
  • When the local Claude Code provider is changed outside WeSight — e.g. by a config switcher (cc-switch) that rewrites settings.json while preserving the __wesight_managed block — restarting WeSight or switching the config source to "local CLI config" (本机配置) restores the outdated snapshot, silently reverting the user's provider/model to a previously used one.
  • Fix: record the overlay env WeSight last wrote as managedEnv in the managed metadata. On merge/cleanup, if the live env no longer matches that overlay, treat it as an external change: keep the live values and refresh the snapshot instead of restoring the stale one. Legacy metadata without managedEnv keeps the previous behavior.

Reproduction

  1. Configure a local Claude Code provider A (e.g. via a config switcher), let WeSight manage settings once (WeSight model mode), then switch back to local config — snapshot now contains A.
  2. Switch the local provider to B outside WeSight (config switcher rewrites settings.json, preserving __wesight_managed with snapshot A).
  3. Restart WeSight with config source = local CLI config → removeWesightManagedClaudeSettings restores provider A into env; the UI and launched Claude Code use A instead of B.

Test plan

  • npx vitest run src/main/libs/externalAgentConfigSync.test.ts — 27/27 pass (4 new cases: managedEnv recording, external switch preserved on cleanup, snapshot refresh on next merge, legacy metadata backward compatibility)
  • Full npx vitest run — no new failures (1 pre-existing environment-dependent failure in externalAgentEnvironment.test.ts, also fails on clean main)
  • npx tsc --noEmit clean; npx eslint on changed files clean
  • Manual: switch local provider via an external tool, restart WeSight with 本机配置, verify the current provider is kept

…witch

The __wesight_managed.claudeCode.originalEnv snapshot was captured once
("first seen wins") and never updated. When the local Claude Code provider
was changed outside WeSight (e.g. by a config switcher that rewrites
settings.json), switching to or restarting with "local CLI config" restored
the outdated snapshot and silently reverted the user's provider/model.

Record the overlay env WeSight last wrote as managedEnv. On merge/cleanup,
if the live env no longer matches that overlay, treat it as an external
change: keep the live values and refresh the snapshot instead of restoring
the stale one. Legacy metadata without managedEnv keeps the old behavior.
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@yanyanyanyan0918-cmyk is attempting to deploy a commit to the canghe's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants