Skip to content

clash-cli: read and edit profiles, override rules, and per-domain DNS - #102

Open
zifengjiang wants to merge 2 commits into
ProjectClash:mainfrom
zifengjiang:app-control-p0
Open

zifengjiang wants to merge 2 commits into
ProjectClash:mainfrom
zifengjiang:app-control-p0

Conversation

@zifengjiang

Copy link
Copy Markdown

Why

clash-cli controls the runtime but not the app's configuration store: a profile's override rules and per-domain DNS can only be edited in the UI. This adds the client half so those settings can be scripted, and makes the app pick the change up on the next connect without a manual rebuild.

Depends on the kernel side (ProjectClash/Clash#13), which serves /clash/v1/app/* and advertises capability app-store-v1.

What

New commands:

clash-cli profiles
clash-cli rules append  'DOMAIN-SUFFIX,corp.example.com,DIRECT' [--profile <id|label>]
clash-cli rules remove  'DOMAIN-SUFFIX,corp.example.com,DIRECT' [--profile <id|label>]
clash-cli dns policy [--profile <id|label>]
clash-cli dns policy set '+.example.com=10.0.0.1,10.0.0.2'
clash-cli dns policy clear [--fake-ip-filter]
  • --profile defaults to the active profile, by id or label.
  • DNS writes are read-merge-write, because the endpoint replaces the keys it is given.
  • Against an app without the capability the commands print what is missing and exit with code 5, the same way the other commands handle an unsupported server.

App side: the published config is derived from the profile store, and was only regenerated when the app decided to. ProfileInputsStamp records a fingerprint of the inputs a published revision was built from; prepareForStart compares it before validating and rebuilds when it differs, so an edit made through the controller lands on the next connect. A missing stamp is treated as a change once, and recorded.

Verification

  • go build ./... && go test ./... — 25 tests for the new commands (parsing, profile resolution, merge semantics, capability-missing path).
  • End to end against a running app on macOS and on iPhone over the LAN controller: rules append and dns policy set, then reconnect — clash-cli rule match <domain> reports the new rule and clash-cli dns query returns the address from the policy's nameserver.

jeffjiang added 2 commits November 16, 2026 19:44
profiles, rules append/remove and dns policy drive the App's configuration
store through the new app-store-v1 controller capability.
The app-store endpoints write config inputs (override rules and the
runtime DNS patch) straight into the profile store. Without this, the
derived files (published rules, the resolved runtime config) are only
rebuilt when the app decides to regenerate them, so an edit made over
the controller stayed invisible until an unrelated change forced a
rebuild.

A stamp keeps a fingerprint of the inputs the published revision was
built from, and the activation preflight compares it before starting.
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