# CLI

Connect from your terminal with Shopify approval and no manual tokens.

Source: https://littleworks.app/docs/cli

## Install and sign in

Use Node.js 22 or newer. The development CLI is distributed directly from Littleworks as an npm-compatible package; it is not listed in the npm registry.

### Install the CLI

```bash
npm install -g https://littleworks.app/downloads/littleworks-cli-0.2.0.tgz
littleworks login
```

Login opens your browser. Enter your store’s myshopify.com domain and approve access inside Shopify. The CLI then shows the connected store. Use `littleworks login --no-browser` to open the printed authorization link yourself on the same computer.

## Inspect before making changes

### Read the connected store

```bash
littleworks context
littleworks list
littleworks get notes.save --env preview
```

## Build and run a work

### Use your own source and manifest

```bash
littleworks check handler.ts
littleworks deploy manifest.json handler.ts
littleworks invoke notes.save '{"message":"Hello"}' --env preview
littleworks runs
```

These are command examples, not instructions to create a sample work. Deploy uses the environment in the manifest. Other environment-specific commands default to Preview; use `--env production` for Live. Source is bundled locally with esbuild, then checked by the server. Packages cannot bypass runtime restrictions.

Each invoke generates an idempotency key. Supply `--idempotency-key <key>` when deliberately retrying the same invocation. Check for partial effects before retrying mutations.

## Use the full tool interface

### Inspect with MCP tools through the CLI

```bash
littleworks call list_collections '{}'
littleworks call get_run '{"runId":"RUN_ID"}'
```

`littleworks call` accepts the exact tools and arguments in the [MCP reference](https://littleworks.app/docs/mcp). Friendly commands also cover pause, resume, rollback, runs, and records. Run `littleworks help` for the complete command list.

## Connect another store

### Separate named connections

```bash
littleworks login --profile second-store
littleworks context --profile second-store
littleworks logout --profile second-store
```

Each profile holds one connection. OAuth credentials are saved in a private file under `~/.littleworks`, outside your project. Commands using the same profile run one at a time to avoid refresh-token races. Do not share or commit these files. Logout revokes the connection and removes its local credentials.

## Export your data

### Write a new backup file

```bash
littleworks export backup.json
```

Export includes documents and up to the latest 50 saved versions for each registered work and environment. It excludes credentials and Shopify tokens. Pause writes if a consistent snapshot is required. Existing output files are never overwritten. Restore is not yet implemented.
