PowerSync CLI on NPM
Install globally or run via npx
Source Code
PowerSync CLI repo on GitHub
Changelog
Changelog for the CLI
The CLI is currently in beta. We recommend it for
new and existing projects.
What changed in 0.9.0?
What changed in 0.9.0?
Main improvements:
-
Project-based config — A
powersync/directory in your repo holdsservice.yamlandsync-config.yaml, so you version and review config with your app code. -
Self-hosted support — Most commands work against any linked instance, PowerSyncCloud and self-hosted. You can also use
powersync docker configureto scaffold a local PowerSync stack with no manual setup. -
Better validation —
powersync validatechecks your config before deploy and reports errors with line and column numbers. -
Config Studio —
powersync edit configopens a built-in editor with schema validation, autocomplete, inline errors, and more. See the Config Studio README. -
Browser login —
powersync loginopens a browser to create or paste a PAT and stores it; in CI usePS_ADMIN_TOKEN. -
Plugins — npm-based plugin system (OCLIF); install with
powersync plugins install <package>or build with@powersync/cli-core. - Open source — Source and advanced docs are in the PowerSync CLI repo. See Migrating From the Previous CLI if you used the older flow.
Installation
Install globally or run vianpx:
Authentication (Cloud)
Cloud commands require a PowerSync personal access token (PAT). Interactive login (recommended for local use):PS_ADMIN_TOKEN environment variable. The CLI uses PS_ADMIN_TOKEN when set; otherwise it uses the token from powersync login.
powersync logout.
Config Files
The CLI uses a config directory (defaultpowersync/) with YAML files:
Developer Notes
- Use the
!envtag for secrets, e.g.uri: !env PS_DATABASE_URI(or!env VAR::number/!env VAR::booleanfor types). - Edit files in your IDE, then run
powersync validateandpowersync deploy. For schema validation and!envsupport in your editor, runpowersync configure ide; or runpowersync edit configto open Config Studio (built-in web-based editor). - To run commands against several instances from one config directory, define named targets in
cli.yaml. See Named Targets. The CLI usage docs cover other layouts, such as one directory per instance. - For Cloud secrets in
service.yaml, usepassword: secret: !env VARto supply the value from an environment variable at deploy time; after the first deploy you can switch tosecret_ref: default_passwordto reuse the stored secret. Details cli.yamlrecords the instance ID along with the organization and project IDs. The organization and project IDs act as a cache: when both are present, the CLI uses them directly instead of looking them up from the instance, saving an API request. If they are missing, the CLI resolves them automatically from the instance ID. If they are present but incorrect for the instance, the CLI reports an error rather than overriding them.
Cloud Workflows
You can create instances, deploy and pull config, run all Cloud commands.Create a New Instance
1
Log in and scaffold
2
Edit config
Edit
powersync/service.yaml (name, region, replication, auth) and sync config; use !env for secrets.3
Create and link
--org-id=<org-id> if your token has multiple orgs.4
Deploy
--directory=<path> for a different config folder.
Use an Existing Instance (Pull)
Pull config from an instance that already exists (e.g. created in the Dashboard):service.yaml and sync-config.yaml as needed, run powersync validate, and powersync deploy. Run powersync pull instance again (no IDs if already linked) to refresh from the cloud.
Preview a Deploy
Add--dry-run to powersync deploy, powersync deploy service-config, or powersync deploy sync-config to see what a deploy would do without changing the instance:
service.yaml sections that differ from the deployed config, and a diff of the sync config. Nothing is deployed, even when the instance is not provisioned yet.
The service config summary lists section names only, because service.yaml holds connection strings and other secrets. To compare the full file, run powersync pull instance without --overwrite. It writes the deployed config to service-fetched.yaml next to your service.yaml, so you can diff the two files locally.
Connections that pass a password with
secret always show replication as
changed, because the value is sent again on every deploy.Run Commands Without Local Config
To run commands (e.g.powersync generate schema, powersync status) against an instance managed elsewhere (e.g. Dashboard):
- Link once:
powersync link cloud --instance-id=<id>(writescli.yaml); later commands use that instance. - Or pass each time:
--instance-id, or setINSTANCE_IDin the environment.
The CLI resolves the instance in a fixed order: flags first, then
cli.yaml
(the selected target, then the top-level fields), then environment
variables. For details, see supplying linking information for Cloud and
self-hosted
commands
in the CLI usage docs.Named Targets
Named targets let one config directory point at more than one Cloud instance, such as staging and production. Each target is an entry undertargets in cli.yaml with its own instance, organization, and project IDs. The top-level fields stay the default when you do not select a target.
Link an existing instance under a target name, or create a new instance and link it under one:
cli.yaml:
--target on a command, or set POWERSYNC_TARGET for scripts and CI:
--instance-id takes precedence over POWERSYNC_TARGET. You cannot combine --target with --instance-id in one command. powersync fetch instances lists the targets of each linked directory. Before deploy, stop, destroy, and compact change anything, the CLI prints the instance name and IDs, plus the target name when one is selected.
Deploy writes the
name from service.yaml to the instance it targets.
Instances deployed from one service.yaml end up with the same name in the
Dashboard, so tell them apart by target name or instance ID rather than
by instance name.Self-Hosted Workflows
Support is limited: you link to an existing PowerSync API and run a subset of commands. The CLI does not create, deploy to, or pull config from your server; you manage the server and its config yourself. For local development, use Docker to run a PowerSync Service (and optional DB/storage) in containers.Authenticate
1
On the server
In your PowerSync instance config, define API tokens in
service.yaml:2
Link the CLI
cli.yaml with the API URL.3
Set the API key
In
cli.yaml set api_key: !env PS_ADMIN_TOKEN (or a literal value matching a server token), or set the PS_ADMIN_TOKEN environment variable. If both are set, the environment variable takes precedence.Scaffold and Link (No Docker)
When you already have a running PowerSync API:--directory=<path> for a different config folder.
Supported Commands (Self-Hosted)
Only these commands apply to self-hosted instances:powersync status, powersync generate schema, powersync generate token, powersync validate, powersync fetch instances (scans current directory for folders with cli.yaml).
Cloud-only commands (powersync deploy, powersync pull instance, powersync fetch config, powersync destroy, powersync stop, powersync compact) do not apply.
Docker (Local Development)
Run a PowerSync Service (and optional DB/storage) in containers on your machine—no remote server.powersync status, powersync generate schema, etc.). To stop: powersync docker stop (add --remove to remove containers, --remove-volumes to reset so init scripts run again). For a clean setup: powersync docker reset (stop and remove, then start).
Common Commands
Run
powersync --help or powersync <command> --help for flags. Full command reference in the CLI repo.
Deploying From CI (e.g. GitHub Actions)
You can automate sync config (and full config) deployments using the CLI in CI. Use the config directory as the source of truth: keepservice.yaml and sync-config.yaml in the repo (with secrets via !env and CI secrets), then run powersync deploy (or powersync deploy sync-config).
Secrets: Set PS_ADMIN_TOKEN to your PowerSync personal access token. If the workflow does not use a linked directory, also set INSTANCE_ID. If the linked directory defines targets, set POWERSYNC_TARGET to pick one. For self-hosted, API_URL can specify the PowerSync API base URL.
The CLI prints the target instance name and IDs before a deploy starts, so the job log shows which instance changed. For pull request checks, run powersync deploy --dry-run to validate the config and preview the changes without deploying.
GitHub Actions Demo
Example: deploy sync config on push to main
Migrating From the Previous CLI
If you used the older PowerSync CLI (e.g.npx powersync init to set token and org/project, then powersync instance set, powersync instance deploy, etc.), the new CLI uses a different flow. Version 0.9.0 and above are not backwards compatible with 0.8.0. If you are not ready to migrate, you can stay on the old CLI:
Summary: Authenticate with
powersync login (or PS_ADMIN_TOKEN in CI). Use a config directory with service.yaml and sync-config.yaml as the source of truth. Link with powersync link cloud or powersync pull instance, then run powersync deploy or powersync deploy sync-config. No more setting “current instance” separately from config—the directory and cli.yaml define the target.
Additional Documentation (CLI Repository)
More information is available in the PowerSync CLI repository.Known Issues and Limitations
- When secure storage is unavailable,
powersync loginmay store the token in a plaintext config file after explicit confirmation. - Self-hosted: the CLI does not create or manage instances on your server, or deploy config to it; it only links to an existing API and runs a subset of commands (status, generate schema/token, validate). The sole exception is Docker: it starts a local PowerSync Service (and optional DB/storage) in containers on your machine for development — not a remote or production instance.
- Some validation checks require a connected instance to complete successfully; validation of an unprovisioned instance may show errors that resolve after the first deployment.
Reference
npm: powersync
Package and version history
Manage your access tokens
Create or revoke tokens in the PowerSync Dashboard
PowerSync CLI Repo
Source code, usage docs, Docker usage, and examples