Skip to content

Validate --settings-json with zod - #3106

Merged
mifi merged 2 commits into
masterfrom
claude/settings-json-zod
Oct 15, 2026
Merged

mifi merged 2 commits into
masterfrom
claude/settings-json-zod

Conversation

@mifi

@mifi mifi commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Resolves the // @ts-expect-error todo use zod? in src/main/index.ts.

Previously every key/value from --settings-json was written straight into the config store, so a typo or invalid value could corrupt the config file (as the docs warned).

  • src/common/types.ts: Config and its member types (KeyboardAction, KeyBinding, CaptureFormat, โ€ฆ) are now defined as zod schemas, with the TS types inferred from them. The inferred types are identical to the old hand-written ones; I verified this with a strict type-equality check against the previous definitions. No importers needed changes.
  • src/main/util.ts: parseSettingsJson() = configSchema.partial().strict() on the JSON5 input.
  • src/main/index.ts: on invalid settings, log a readable error (z.prettifyError) and apply none of them; the app keeps starting normally.
  • docs/cli.md: replaced the "could corrupt your configuration file" warning.
  • Tests for valid subsets, unknown keys and invalid values.

Behaviour change: unknown keys (e.g. typos) are now rejected instead of silently stored.

๐Ÿค– Generated with Claude Code

https://claude.ai/code/session_0125XTBqSHMdXYaSLkahs1Xr


Generated by Claude Code

claude and others added 2 commits October 15, 2026 02:47
Previously any key/value from --settings-json was written straight into the
config store (with a `todo use zod?`), so a typo or bad value could corrupt
the config file. Define the config as a zod schema in common/types (Config and
its member types are now inferred from it, unchanged) and validate the CLI
settings against it: unknown keys or invalid values are logged and nothing is
applied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0125XTBqSHMdXYaSLkahs1Xr
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
A JSON5 syntax error threw out of init(), so the window was never created.
Parse inside the zod pipeline so it's logged and ignored like other invalid
settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0125XTBqSHMdXYaSLkahs1Xr
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
@mifi
mifi force-pushed the claude/settings-json-zod branch from f99ca0b to 4c2c047 Compare October 15, 2026 02:48
@mifi
mifi merged commit aa4cc8a into master Oct 15, 2026
6 checks passed
@mifi
mifi deleted the claude/settings-json-zod branch October 19, 2026 08:29
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