Skip to content

Bug: /model command silently removes manually-added models from settings.json #2454

@tanzhenxin

Description

@tanzhenxin

What happened?

When the CLI app is already running and you manually edit settings.json to add new models to the modelProvider configuration, then use the /model slash command inside the CLI to switch models, all the newly added models are silently removed from settings.json without any warning or notice.

Steps to reproduce:

  1. Launch the CLI app (qwen)
  2. While the app is running, manually edit your settings.json file to add new model entries under the modelProvider config
  3. Inside the running CLI, use the /model command to switch to a different model
  4. Check settings.json — the manually added models are gone

Why this happens:

The /model command calls setValue() on the in-memory LoadedSettings, which only tracks the specific key being changed (model.name). When it saves back to disk via saveSettings(), it passes the incomplete in-memory originalSettings object to updateSettingsFilePreservingFormat(). The applyUpdates() merge function then overwrites sections of the file with this incomplete data, silently dropping any entries that were added to the file after the app loaded its settings into memory.

What did you expect to happen?

The /model command should only update the model.name key in settings.json and preserve all other settings, including any models manually added to the modelProvider config while the app was running.

Client information

Client Information

To be filled in.

Anything else we need to know?

Relevant code paths:

  • packages/cli/src/config/settings.tssetValue() (line ~309) and saveSettings() (line ~710)
  • packages/cli/src/utils/commentJson.tsapplyUpdates() (line ~43) where data is lost
  • packages/cli/src/ui/components/ModelDialog.tsxpersistModelSelection() triggers the save

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/settingsSettings and preferencestype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions