Skip to content

fix(claude): preserve user-defined settings on provider switch#75

Open
zj1123581321 wants to merge 1 commit intoSaladDay:mainfrom
zj1123581321:fix/preserve-user-settings-on-switch
Open

fix(claude): preserve user-defined settings on provider switch#75
zj1123581321 wants to merge 1 commit intoSaladDay:mainfrom
zj1123581321:fix/preserve-user-settings-on-switch

Conversation

@zj1123581321
Copy link

Summary

  • When switching providers, write_claude_live() previously overwrote the entire settings.json, causing user-defined fields to be lost
  • Now preserves known user-configurable top-level keys (statusLine, hooks, permissions, apiKeyHelper) from the existing file when writing new provider config
  • This fixes the issue where HUD plugins (e.g. claude-hud) stop working after a provider switch because statusLine config is dropped

Details

The root cause is in write_claude_live() (src-tauri/src/services/provider/claude.rs): it constructs the new config from the provider's settings_config + common config snippet, then writes it directly to settings.json without reading the existing file. Any fields not stored in the provider's database record are lost.

The fix reads the existing settings.json before writing and carries over user-defined fields that are not present in the new provider config. A whitelist approach (PRESERVE_KEYS) is used instead of preserving all unknown keys, to avoid conflicts with common config management (e.g. clearing a common config snippet should still remove its fields).

Test plan

  • All 946+ existing tests pass (0 failures)
  • Manual test: switch claude-official → zhipu → claude-official, statusLine preserved throughout
  • Manual test: env correctly switches between providers
  • The previously failing test clear_updates_live_config_even_without_apply_flag passes (common config fields are correctly removed when cleared)

🤖 Generated with Claude Code

When switching providers, write_claude_live() previously overwrote
the entire settings.json, causing user-defined fields like statusLine
(used by HUD plugins) and hooks to be lost. Now preserves known
user-configurable top-level keys (statusLine, hooks, permissions,
apiKeyHelper) from the existing file when writing new provider config.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
@SaladDay
Copy link
Owner

这一部分的逻辑目前我们在考虑怎么做,暂时不准备合入

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants