Flux CLI
Add Flux to your app with one command. The CLI detects your setup, installs the packages, generates the engine, wires the service worker and lets you pick which pages work offline. It can also scaffold a brand new app, wire dynamic routes, print your database migration, check your setup and take Flux out again.
- Node 18+.
- (Optional)An existing Next.js 14+ App Router project or a Vite + React project. With no project yet, the CLI creates one for you.
- (Optional)A clean version control state, or run with --dry-run first. The CLI edits files in your project.
Install the CLI, or run it once
Every command on this page is written as flux-cli <command>, for example flux-cli routes. That short name exists only after you install the CLI globally (below). If you have not, your terminal says flux-cli is not recognized. Without the install, put npx @tsworldtech/flux-cli@latest in front instead, for example npx @tsworldtech/flux-cli@latest routes.
Option A: install it once (recommended)
flux-cli ... command on this page works from any folder. Open a new terminal after installing, then check it:Option B: run it without installing
@latest always runs the newest version. Use this for a one off setup, in CI, or from an AI coding agent. Add the command you want after @latest, for example routes or doctor.Close the terminal and open a new one, because the list of installed commands is read when a terminal starts. If it still fails, the folder where your package manager puts global commands is not on your PATH. npm prefix -g prints the folder npm uses. With pnpm, run pnpm setup once and restart the terminal. Until you fix it, the npx form always works.
--cwd in a monorepo). In a terminal it asks a few questions. Without a terminal, or with --yes, it never prompts, so it is safe for scripts and AI coding agents. The CLI has no license key.Add --dry-run to any command to print the full plan and change nothing. The plan lists every file it would create, edit or skip, and every package it would install. The questions are still asked, so you can see what each answer changes.
Existing app or new app
package.json and detects Next.js (App Router, 14 or newer) or Vite with React. It never installs, upgrades or reinstalls your framework. It only adds the Flux packages, so your next, react and vite versions stay exactly as they are. Create React App is deprecated and not supported.package.json, and it asks which framework you plan to use:create-next-app@latest or create-vite@latest), installs it and continues with the normal setup. If the current folder is not empty it asks for a new folder name, so it never scaffolds over your files. To skip the questions:What init changes
init does appears in the plan before it runs. Every generated file starts with a marker comment, so re-running never overwrites a file you edited and changes nothing at all when nothing changed. A file with a shape the CLI cannot edit safely is left untouched and the exact snippet to paste is printed instead.| Next.js (App Router) | Vite + React | |
|---|---|---|
| Creates | lib/flux.ts, components/FluxClientWrapper.tsx, config/precache-routes.ts, app/offline/page.tsx (only if missing) | src/lib/flux.ts, src/config/precache-routes.ts |
| Edits | next.config.* (wraps the config with withFlux), app/layout.* (wrapper, the flux-sw-init script and the manifest link in metadata) | src/main.* (wraps <App /> in FluxProvider), vite.config.* (adds fluxVitePlugin), index.html (manifest link) |
| Both | public/manifest.json and placeholder icons in public/icons/. Skipped when a manifest already exists or with --no-manifest. Replace the icons with your own artwork. | Same |
| Offers | To add public/sw.js to .gitignore, because it is regenerated on every build. | Not applicable |
| Installs | @tsworldtech/flux, @tsworldtech/flux-next, plus the adapter packages you choose | @tsworldtech/flux, @tsworldtech/flux-react, plus the adapter packages you choose |
The CLI never reads, writes or creates any .env file. It prints variable names only, and the generated code references names, never values. It also never overwrites an existing file without --force, and package managers are started with an argument list, never a shell string.
Choose your adapter and routes with flags
init asks which backend you use and which pages should work offline. Every question has a flag, so you can answer them up front. --adapter takes supabase, sse, socketio, websocket or none, repeated or comma separated.| Flag | What it does |
|---|---|
--adapter <list> | Realtime backends to wire: supabase, sse, socketio, websocket or none. |
--url <name=url> | Endpoint for a provider, for example --url sse=/api/flux/stream. |
--primary <name> | Which engine FluxProvider receives. Defaults to the first adapter. |
--routes <list> | Routes to cache offline, for example /,/pricing, or all-static. |
--dynamic-prefixes <list> | Vite only: URL prefixes of routes whose pages load data. |
--no-manifest | Do not create public/manifest.json, placeholder icons or the manifest link. |
--framework next|vite | Only when no project exists. Creates the app first. |
--name <folder> | Only when no project exists. Folder for the new app. |
--js | Only when no project exists. JavaScript instead of TypeScript. |
With --yes and no --adapter, every backend the CLI detects in your package.json is used. If it detects nothing, it exits with code 2 and lists the valid values. SSE and WebSocket cannot be detected from package.json, so they are never chosen for you.
Offline routes: routes, add-route, remove-route
routes rescans your app and lets you pick pages. When you just want to change one or two, add-route and remove-route edit the list directly without scanning everything.Rescan and choose
Add or remove specific routes
| Rule | Why |
|---|---|
| add-route checks that the page exists. | A typo would otherwise precache a 404. |
Dynamic routes such as /blog/[slug] are refused. | They need a shell page and data lookup, which is what add-dynamic sets up (Step 6). |
| Pages that read cookies or headers are refused unless you pass --force. | A cached copy of a per user page can show the wrong user's content, or stale content. |
Pages whose route name looks private are refused unless you pass --force: any segment named portal, dashboard, account, admin, billing, checkout, payment, login, signup, profile or settings (and similar). | These pages usually show signed in or payment content. The same rule leaves them unchecked in the routes list and out of --routes all-static. |
/offline is always kept. | It is the fallback when both cache and network are unreachable. |
--force is for pages that read a cookie or have a private sounding name but render the same thing for everyone, such as a theme or language cookie, or a public page that happens to live under a folder called settings. If the page shows account data, billing or anything tied to a signed in user, keep it out of the precache list and let Flux cache that data per user instead.
Dynamic routes: add-dynamic
/blog/[slug] has infinitely many URLs, so it cannot be precached page by page. Flux precaches one shell document per route and fills it from IndexedDB. add-dynamic wires all of that for one route in a single command.Next.js
/settings and /activity pages under app/projects/[id]/), then makes three changes. It edits withFlux in next.config.*, merging dynamicRoutePrefixes, dynamicRouteShapes and dynamicRouteIdbKeys without duplicates. It adds the build time export to every page of the route. And it creates a client view stub in components/.| Flag | What it does |
|---|---|
--route <path> | Next.js: /blog/[slug]. Vite: /blog/:id. Asked, or inferred when you only have one dynamic route. |
--channel <name> | The registered channel that holds the detail data. Its idbKey is looked up from your flux.register() calls. |
--idb-key <key> | Give the idbKey directly instead of a channel name. |
--list-key <key> | Optional idbKey of the whole list channel, used when the URL slug is not the detail key. |
--list-fields <list> | Fields of that list that match the URL slug. Defaults to the segment name and id. |
With Cache Components on, Next.js refuses an empty generateStaticParams, so pages use generateFluxShellParams(), which returns one sentinel shell param. Otherwise they use fluxDynamicRoute. Shell routes are never added to precacheRoutes, they are generated from dynamicRouteShapes. Pages that are 'use client', or that already export generateStaticParams, are left alone and the exact snippet is printed.
Vite
dynamicRoutePrefixes only. It warns if build.manifest is not true in your Vite config. Running the command again reports "Already wired" and changes nothing.Your database: sql
sql prints the Supabase migration for the tables you name. It never connects to a database, so you review the SQL and run it yourself. The shared parts are the canonical Flux schema: the changelog table, owner functions, the trigger, the delta and reconcile functions and locked down grants. Only the table specific parts are generated for your tables. See the Supabase and Postgres guide for what each part does.| Table spec | Meaning |
|---|---|
table:global | The same rows for everyone. |
table:user | Each row belongs to one user, owner stored in user_id. |
table:user:column | Owner stored in another column. Use id when the row is the user's own record. |
table:parent:parentTable:fkColumn:ownerColumn | The owner is found on a parent table through a foreign key. |
| Flag | What it does |
|---|---|
--out <file> | Write the migration to a file. Never overwrites. In a terminal with supabase/migrations present, it offers to write a timestamped file there. |
--cleanup | Include the retention function. The pg_cron schedule is left commented out. |
--allow-anon-global | Let logged out visitors catch up on global tables. |
The migration is idempotent, so running it again is safe. Table and column names are validated as plain identifiers before they reach the SQL. Warnings are written as comments at the top of the output.
sql is for the Supabase adapter. If your project uses a Socket.io, SSE or WebSocket adapter, it prints a pointer to the matching guide instead, because those setups also need the bridge process that watches the database.
Check your setup: doctor
doctor checks packages, versions, storage prefixes, the wrapper, the service worker script, routes and the manifest. It also reads your own Flux code and reports problems that otherwise fail silently. All of it is static: nothing runs and nothing reads environment files.--strict makes warnings fail the run, so a drifting storage prefix or a missing scope: 'user' is caught in a pull request instead of in production.
Take Flux out again: remove
remove undoes what init did, and nothing else. It deletes the generated files you did not edit, unwraps withFlux, the layout wrapper and script, FluxProvider and the Vite plugin, removes the manifest and placeholder icons (only when they are still exactly what init wrote), removes the .gitignore entry and public/sw.js, and uninstalls the @tsworldtech/flux* packages.| Situation | What the CLI does |
|---|---|
| A generated file you edited | Kept. Use --force to delete it. |
| A file other code of yours still imports | Kept, so your app keeps building. |
| A file with a shape that cannot be edited safely | Prints exactly what to delete by hand and keeps the generated files until you rerun it. |
| zustand and the Supabase packages | Left installed, because other code may use them. |
| Environment variables and .env files | Never touched. |
| No terminal and no --yes | Refuses and exits with code 2. |
Flags, exit codes and agents
| Flag | What it does |
|---|---|
--cwd <dir> | Run in another directory. Use this in a monorepo. |
--yes, -y | Never prompt. Missing information is an error, not a hang. |
--dry-run | Show the plan and change nothing. |
--force | Overwrite files the CLI generated earlier and you edited. |
--json | Print one machine readable JSON report on stdout. |
--help, -h | Show help. |
--version, -v | Show the version. |
Exit codes
| Code | Meaning |
|---|---|
0 | Success. |
1 | Failure. |
2 | Invalid input, ambiguity or an unsupported project. |
Using it from an AI coding agent or a script
--yes. Missing information is an error with a clear message, never a hang. --json prints one report with the framework, package manager, engines, packages with requested and resolved versions, files created, edited and skipped (with reasons), environment variable names, snippets to paste and warnings.License key and testing offline
Only for your own custom domain in production. In development, and on free Vercel or Netlify domains, every feature is available without a license key.
It reads package.json, the lockfile, config files, layouts and route files, and writes only the files listed in the plan. The only network it uses is the npm registry. It has no telemetry, no install scripts and no runtime dependencies, because the code parser it uses to edit your files is compiled into the published file.
It does not install or upgrade your framework, does not touch .env files, does not connect to your database, and does not overwrite a file without --force. For the full manual setup it automates, see the Next.js guide or the React guide.