CLI
Install OpenPolicy and generate an agent prompt in one command
@openpolicy/cli sets up OpenPolicy in your project. Run it once — it installs the right packages for your stack, scaffolds a starter openpolicy.ts, and prints a prompt you can paste into a coding agent (Claude Code, Cursor, etc.) to finish filling in your config from your codebase.
Run it
From the root of your project:
bunx @openpolicy/cli init
# or: npx @openpolicy/cli init
# or: pnpm dlx @openpolicy/cli initThat's the whole flow. The CLI is meant for one-time setup — once it's done, uninstall or ignore it.
What it does
- Detects your package manager from lockfiles (
bun.lock,pnpm-lock.yaml,yarn.lock,package-lock.json) or thepackageManagerfield inpackage.json. Falls back tonpm. - Detects frameworks by reading your
package.jsondependencies and installs the matching OpenPolicy integration:vite→@openpolicy/vite(devDependency)react→@openpolicy/reactvue→@openpolicy/vuesvelte→@openpolicy/svelte@openpolicy/sdkis always installed.
- Writes a starter
openpolicy.tstosrc/openpolicy.tsif asrc/directory exists, otherwise to the project root. - Prints an agent prompt between delimiters so you can copy it into a coding agent and have the rest of your config filled in automatically from your codebase.
Flags
| Flag | Default | Description |
|---|---|---|
--cwd <path> | . | Working directory |
--pm <bun|pnpm|yarn|npm> | auto-detected | Override package-manager detection |
--skip-install | false | Skip installation; only print the prompt |
--dry-run | false | Show planned actions without executing |
--yes, -y | false | Skip the confirmation prompt |
--out <path> | auto-detected | Output path for the starter openpolicy.ts |
--force | false | Overwrite an existing openpolicy.ts |
Why a prompt instead of a wizard?
A coding agent reading your actual codebase can fill in data.collected, data.context, thirdParties, jurisdictions, and cookie usage more accurately than a series of prompts ever could — it infers from your ORM schemas, imports, environment variables, and existing legal copy. The CLI gives you the scaffolding, the agent supplies the content.
See Configuration for the shape of openpolicy.ts and Auto-collect for declaring data collection inline in your source.