Skip to content

Add restore command to undo Claude Code/opencode settings changes#4

Closed
felipegaudio wants to merge 1 commit into
add-opencode-supportfrom
add-restore-command
Closed

Add restore command to undo Claude Code/opencode settings changes#4
felipegaudio wants to merge 1 commit into
add-opencode-supportfrom
add-restore-command

Conversation

@felipegaudio

Copy link
Copy Markdown
Contributor

Summary

Stacked on #1 (opencode support) — targets add-opencode-support, not main, since it needs the opencode constants added there.

  • There was no way to undo what update_claude_settings()/update_opencode_settings() write to ~/.claude/settings.json / ~/.config/opencode/opencode.json. config_reset only cleared the local ~/.olist-code-adapter/config.json — the actual harness settings stayed patched. Found this the hard way while manually testing Add opencode provider support alongside Claude Code settings #1 against a fake gateway: pointed my real Claude Code at a throwaway upstream with no way to revert except a manual backup.
  • Adds restore_claude_settings() / restore_opencode_settings() to config.py: each removes only the specific keys olist-code itself adds (the ANTHROPIC_* env vars / the olist-ai-gateway provider entry), leaving any other settings/providers the user already had untouched. If removing our keys leaves the env/provider object (or the whole opencode file) empty, that empty shell is cleaned up too.
  • Adds an olist-code restore CLI command that runs both plus removes the local adapter config, mirroring init's "write everything" with a single "undo everything".

Test plan

  • New tests in tests/test_config.py: no-op when file missing, removes only our keys/provider while preserving unrelated ones, cleans up empty env/provider containers, deletes the opencode file entirely if we created it from scratch.
  • pytest — full suite passes (56 passed).
  • ruff check / mypy on touched files — no new issues (one pre-existing unrelated line-length warning in cli.py).
  • Manual end-to-end: seeded a fake ~/.claude/settings.json with unrelated keys, ran olist-code init (pointed at a local fake gateway) to pollute it + create opencode.json from scratch, then ran olist-code restore — settings.json came back byte-for-byte identical to the pre-init version, opencode.json was deleted (didn't exist before), local adapter config removed.

There was no way to undo what update_claude_settings() and
update_opencode_settings() write, short of manually editing the
JSON files or restoring a manual backup. Adds
restore_claude_settings()/restore_opencode_settings(), which remove
only the keys olist-code itself added (leaving any pre-existing
settings/providers untouched), plus an `olist-code restore` command
that runs both and clears the local adapter config.
@felipegaudio

Copy link
Copy Markdown
Contributor Author

Recriado como #6 — a base (add-opencode-support) foi apagada no merge do #1 e o GitHub não deixa reabrir/repontar esse PR. Fechando em favor do #6.

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.

1 participant