# CLI command reference

> Every Stacksync CLI command with its arguments, options, environment variables, files and exit codes.

Source: https://docs.stacksync.com/developers/getting-started-with-stacksync-cli/cli-command-reference

This page covers Stacksync CLI 1.0.11. Run `stacksync -v` to see your version. The CLI keeps itself up to date.

```bash
stacksync <command> [options]
stacksync <command> -h
```

`stacksync -h` lists every command, including the subcommands of `workflow-connector` and `workflow-module`. Each command's `-h` ends with a link to its section on this page.

## Summary

| Command                                                      | What it does                                                            | Run it from                               |
| ------------------------------------------------------------ | ----------------------------------------------------------------------- | ----------------------------------------- |
| `stacksync`                                                  | Show the welcome screen and the getting-started commands.               | Anywhere                                  |
| `stacksync login`                                            | Log in to Stacksync and choose a default workspace.                     | Anywhere                                  |
| `stacksync logout`                                           | Log this machine out.                                                   | Anywhere                                  |
| `stacksync hello`                                            | Show the welcome screen to confirm the CLI works.                       | Anywhere                                  |
| `stacksync update`                                           | Install the latest CLI release now.                                     | Anywhere                                  |
| `stacksync -v`, `-V`, `--version`                            | Print the installed version.                                            | Anywhere                                  |
| `stacksync <command> -h`, `--help`                           | Show a command's options and its link on this page.                     | Anywhere                                  |
| `stacksync workflow-connector create "<name>"`               | Create a connector project in a new folder.                             | The parent folder                         |
| `stacksync workflow-connector run`                           | Run the connector on your machine and make it usable in your workspace. | The connector folder                      |
| `stacksync workflow-connector deploy`                        | Submit the connector for review and deployment.                         | The connector folder                      |
| `stacksync workflow-connector deploy-status <deployment-id>` | Show where a deployment stands.                                         | Anywhere                                  |
| `stacksync workflow-connector replay <selector>`             | Send a recorded request to the running connector again.                 | The connector folder                      |
| `stacksync workflow-connector cdk [ref]`                     | Show or change the CDK version the connector uses.                      | The connector folder                      |
| `stacksync workflow-module create "<name>"`                  | Add a module to the connector.                                          | The connector folder                      |
| `stacksync workflow-module delete ["<name>"]`                | Remove a module from the connector.                                     | The connector folder or the module folder |

Commands that run in the connector folder read its `stacksync.yml`. Outside a connector they stop with `No stacksync.yml found`. Commands that talk to Stacksync need a login and otherwise stop with `Not authenticated. Run 'stacksync login' to set your API key.`

## login

```bash
stacksync login [--api-key <key>] [--workspace <id>] [--check]
```

Without options, `login` asks how to authenticate: **Log in via the web** opens the browser, and **Copy/Paste API key** takes a workspace API key. After a web login you choose the default workspace. If a login already exists on this machine, it offers to keep it.

| Option             | Environment variable  | Description                                                                                   |
| ------------------ | --------------------- | --------------------------------------------------------------------------------------------- |
| `--api-key <key>`  | `STACKSYNC_API_KEY`   | Save this API key and skip every prompt. Use it in CI, on remote machines and with AI agents. |
| `--workspace <id>` | `STACKSYNC_WORKSPACE` | Save this workspace id as the default. Use it with `--api-key`.                               |
| `--check`          |                       | Print `Logged in` or `Not logged in` and exit with `0` or `1`. Nothing changes.               |

Without a terminal and without an API key, `login` stops and tells you to pass `--api-key`.

```bash
stacksync login --api-key "$STACKSYNC_API_KEY" --workspace 1234
```

## logout

```bash
stacksync logout
```

Removes the saved API key and default workspace from this machine. The next command that talks to Stacksync asks you to log in again.

## hello

```bash
stacksync hello
```

Shows the welcome screen with the getting-started commands, the same as running `stacksync` on its own. Use it to confirm the CLI is installed and on your `PATH`.

## update

```bash
stacksync update [--force]
```

Installs the latest release now. It does nothing when you already have the latest version, unless you pass `--force`. The CLI keeps itself up to date, so you only need this on version 1.0.10 or earlier: run it once, and later updates are automatic.

## workflow-connector create

```bash
stacksync workflow-connector create "<name>"
```

Creates the folder `workflows-app-<name>` in the current folder from the official connector template. The name is turned into lowercase words joined by hyphens: `"Acme CRM"` creates `workflows-app-acme-crm`.

`create` fills in `stacksync.yml`:

* `app_type` is the name in lowercase with underscores, for example `acme_crm`.
* `app_name` and `app_type_display` are the name as you typed it.
* `deployment_settings.workspace` is your default workspace. If none is set, `create` asks for one. It is where `run` tests the connector and where `deploy` submits it from; it doesn't limit who can use the deployed connector.

When `git` is installed, it also starts a Git repository with a first commit. It stops if the folder already exists. The project layout is described in [Workflow Connector Development Kit](/developers/stacksync-cdk/workflow-connector-development-kit).

## workflow-connector run

```bash
stacksync workflow-connector run [--port <n>] [--sync-build | --no-sync-build]
```

Runs the connector on your machine and adds it to your workspace as a temporary private connector, so you can use its modules in the workflow builder while you develop.

What `run` does, in order:

1. Validates `stacksync.yml`.
2. Copies the project into `.stacksync_build/`.
3. Uses the active virtual environment, or creates `.venv/` in the project, and installs `requirements.txt`. When the CDK requirement follows a moving version (`@v1`, `@v2`, `@prod`), it reinstalls the CDK so you always have the latest release of that line.
4. Prints the installed CDK version, for example `Stacksync CDK 1.1.1 (tracking @v1)`.
5. Starts the connector on `http://127.0.0.1:<port>`.
6. Registers the temporary connector in your workspace, in the `region` of `stacksync.yml`, and forwards its requests to your machine through a secure connection.

While it runs, every request from Stacksync is handled by the code on your machine and recorded for [replay](#workflow-connector-replay). A request that takes longer than 10 seconds locally times out. Saved file changes are copied into the build and reloaded. Added files are picked up too; after you delete or rename a file, restart `run`.

Press **Ctrl+C** to stop. `run` then removes the temporary connector from the workspace.

| Option                             | Default        | Description                                                            |
| ---------------------------------- | -------------- | ---------------------------------------------------------------------- |
| `--port <n>`                       | `2323`         | Local port. If it is taken, `run` uses the next free port and says so. |
| `--sync-build` / `--no-sync-build` | `--sync-build` | Copy changed files into `.stacksync_build/` while running.             |

`run` needs Python 3.10 or later. If `.venv/` was created with an older Python, delete it and run again.

## workflow-connector deploy

```bash
stacksync workflow-connector deploy
```

Packages the connector's source and submits it to Stacksync. Unlike `run`, which keeps the connector on your computer and links it to your workspace only while it runs, a deployed connector is hosted by Stacksync and is available in every Stacksync workspace: see [Who can use a deployed connector](/developers/getting-started-with-stacksync-cli/deploy-a-workflow-connector#who-can-use-a-deployed-connector). A Stacksync reviewer approves each deployment before it is built, so `deploy` returns as soon as the source is accepted:

```text
Deployment 3f2a9c0e8b7d4e1fa6c5b4d3e2f1a0b9 submitted for review.
It is built and deployed once a Stacksync reviewer approves it. You will get an email when it ends.
```

The source package is `.stacksync_deployment/source.zip`. It leaves out `.git`, `.venv`, `venv`, `__pycache__`, `.stacksync_build`, `.stacksync_deployment`, `.logs`, `.DS_Store` and every `.env` file except `.env.example`, `.env.sample` and `.env.template`. It must be smaller than 32 MiB: list dependencies in `requirements.txt` instead of including them.

Stacksync refuses the submission when the connector does not meet the [connector standard](/developers/getting-started-with-stacksync-cli/deploy-a-workflow-connector#the-connector-standard) or a deployment rule, and `deploy` prints the reason. Only one deployment of a connector can wait for review or be in progress at a time. The whole process is described in [Deploy a workflow connector](/developers/getting-started-with-stacksync-cli/deploy-a-workflow-connector).

## workflow-connector deploy-status

```bash
stacksync workflow-connector deploy-status <deployment-id>
```

Prints the current state of a deployment. The id is the 32-character id that `deploy` printed. Only the person who submitted the deployment can see its status.

| Printed                                | Meaning                                                                                                                      |
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `Waiting for approval by Stacksync...` | A Stacksync reviewer has to approve it. This can take hours.                                                                 |
| `Building...`                          | Approved and being built.                                                                                                    |
| `Deploying...`                         | Being started.                                                                                                               |
| `Registering modules...`               | Its modules are being added to the workflow builder.                                                                         |
| `Live`                                 | Deployed and usable in workflows.                                                                                            |
| `Failed`                               | It could not be completed. The command exits with code `1` and asks you to contact Stacksync support with the deployment id. |

## workflow-connector replay

```bash
stacksync workflow-connector replay <selector> [--port <n>]
```

Sends a request recorded during `run` to the connector running locally, and prints the status and response. Use it to debug a module without running the workflow again. `run` keeps the last 100 requests in `.logs/<app name>.json`.

| Selector        | Request                                               |
| --------------- | ----------------------------------------------------- |
| `<trace-id>`    | The request with this trace id (a UUID from the log). |
| `first`, `last` | The oldest or the newest request.                     |
| `first+n`       | The request `n` places after the oldest.              |
| `last-n`        | The request `n` places before the newest.             |

`--port` is the port of the running connector, `2323` by default.

The log contains the request bodies, including connection credentials. It stays on your machine and is never deployed. Keep `.logs/` out of version control, as the template's `.gitignore` does.

## workflow-connector cdk

```bash
stacksync workflow-connector cdk [ref]
```

Shows or changes the [CDK version](/developers/stacksync-cdk/workflow-connector-development-kit#cdk-versions) in `requirements.txt`.

| Command                                   | Effect                                                                    |
| ----------------------------------------- | ------------------------------------------------------------------------- |
| `stacksync workflow-connector cdk`        | Print the version line the connector follows, for example `tracking @v1`. |
| `stacksync workflow-connector cdk v1`     | Follow the latest `v1.x` release. Recommended.                            |
| `stacksync workflow-connector cdk v1.1.1` | Pin one exact release.                                                    |
| `stacksync workflow-connector cdk v2`     | Move to the next major version when it exists.                            |
| `stacksync workflow-connector cdk prod`   | Follow the newest unreleased changes.                                     |

Run `stacksync workflow-connector run` afterwards to install the new version.

## workflow-module create

```bash
stacksync workflow-module create "<name>"
```

Adds the module folder `modules/<name>/v1/` with `schema.py`, `content.py`, `execute.py`, `config.py` and `context.md`. The name is turned into lowercase words joined by underscores: `"Create Records"` creates `modules/create_records/`. It stops if the module exists. The new files contain `TODO` placeholders, which you replace before deploying. Modules are found on disk, so there is nothing to register.

## workflow-module delete

```bash
stacksync workflow-module delete ["<name>"]
```

Deletes `modules/<name>/` and all its versions after you confirm. Run it from the connector folder, or from inside the module's folder and leave out the name.

## Environment variables

| Variable                    | Used by                     | Description                                                                                                                                                                  |
| --------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `STACKSYNC_API_KEY`         | `login`                     | API key to log in with, the same as `--api-key`.                                                                                                                             |
| `STACKSYNC_WORKSPACE`       | `login`                     | Default workspace id, the same as `--workspace`.                                                                                                                             |
| `STACKSYNC_NO_UPDATE_CHECK` | every command               | Any value turns off the check for a newer release.                                                                                                                           |
| `STACKSYNC_INSTALL_DIR`     | `install.sh`, `install.ps1` | Folder for the `stacksync` command. Default `~/.local/bin` on macOS and Linux, `%LOCALAPPDATA%\stacksync` on Windows. An update keeps the folder of the install it replaces. |
| `STACKSYNC_VERSION`         | `install.sh`, `install.ps1` | Version to install, for example `v1.0.11`.                                                                                                                                   |
| `STACKSYNC_SKIP_PATH_SETUP` | `install.sh`, `install.ps1` | Set to `1` to leave your shell startup files and `PATH` unchanged.                                                                                                           |

## Files

| Path                                           | Contents                                                              |
| ---------------------------------------------- | --------------------------------------------------------------------- |
| `~/.stacksync/env.json`                        | Your login (API key) and default workspace. Treat it like a password. |
| `~/.stacksync/cache.json`                      | The result of the last check for a newer release.                     |
| `~/.stacksync/path.sh`                         | Adds the CLI to your `PATH`.                                          |
| `<connector>/.venv/`                           | The Python environment `run` creates when none is active.             |
| `<connector>/.stacksync_build/`                | The copy of the project that `run` serves.                            |
| `<connector>/.stacksync_deployment/source.zip` | The package `deploy` submits.                                         |
| `<connector>/.logs/`                           | Requests recorded by `run`, for `replay`. Contains credentials.       |

All of these except the files in `~/.stacksync` are in the template's `.gitignore`.

## Exit codes

Every command exits with `0` on success and `1` on an error, and prints the reason. `login --check` exits with `1` when you are not logged in, and `deploy-status` exits with `1` when the deployment failed.