anomalyco / anomalyco/opencode
Bug: /model command does not persist agent model change to .jsonc config (1.18.10)
@jlongster is already working on this.
Since Jul 31, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
The /model slash command updates the in-memory agent model immediately (behavior changes live), but the change is not persisted to disk when the config file uses the .jsonc extension. After restart, the old model is loaded from the unchanged config file.
Steps to Reproduce
- Start opencode with config at
~/.config/opencode/opencode.jsonc - Run
/model, select an agent (e.g.,plan), pick a different model - Observe: agent behavior changes immediately (in-memory update works)
- Check config file mtime:
stat --format='%n | mtime: %y' ~/.config/opencode/opencode.jsonc - Observe: mtime does not change — the file on disk was not written
- Restart opencode
- Observe: agent reverts to the old model from disk
Root Cause
In internal/config/config.go, the UpdateAgentModel function (line ~874) calls updateCfgFile (line ~836) to persist the change. updateCfgFile resolves the config file path via:
configFile := viper.ConfigFileUsed()
if configFile == "" {
configFile = filepath.Join(homeDir, ".opencode.json")
}
Problem 1: Viper is configured to look for .opencode.json (line ~218: viper.SetConfigType("json")), but the user's file is .opencode.jsonc. If opencode loads .jsonc via custom logic, viper.ConfigFileUsed() returns "", so the write falls back to ~/.opencode.json — a different file than the real config.
Problem 2: updateCfgFile parses the file with json.Unmarshal, which is not JSONC-aware. If the .jsonc file contains // comments, the parse fails and the write is silently skipped.
Expected Behavior
/model should persist the model change to the same config file that was loaded, regardless of extension (.json or .jsonc).
Workaround
Edit opencode.jsonc directly: set agent.<name>.model to the desired model, then restart opencode.
Version
opencode 1.18.10
Suggested Fix
updateCfgFileshould resolve the config file path identically to the initial config loader (which handles.jsonc)- Use a JSONC-aware parser instead of
json.Unmarshalfor reading/writing - The fallback path should match the actual loaded config location, not a hardcoded
~/.opencode.json
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.