Use the CLI

Install and use the Stackhero CLI to manage your stacks and services from the command line, scripts, CI, and AI agents

The Stackhero CLI is a lightweight, self-contained command-line tool that helps you manage your stacks and services right from your terminal. You can use it to create and delete services, access credentials, update configurations, and handle many other everyday tasks.

The CLI works on Linux (glibc and musl), macOS, and Windows. It ships as a single binary of less than 3 MB with no extra dependencies, which makes installation and updates simple.

Whether you are working interactively or automating workflows with scripts, CI pipelines, or AI agents, the Stackhero CLI is built for both people and automation. Every command supports the --format=json flag for machine-readable output, along with --format=script when you want to capture raw values in shell variables.

You can install the latest version by running:

curl -fsSL https://www.stackhero.io/install.sh | sh

This command downloads the correct binary for your platform and installs it as stackhero. The CLI also keeps itself up to date automatically.

Run stackhero with no argument in a terminal, and the CLI opens a full screen interface that you drive with the keyboard. It is organized like your dashboard, so you find your way at once:

  • Home: your organizations with their stacks, services, and available updates, plus your account and the store.
  • Updates: every service that has an update waiting, in one list. Select one and press Enter to install it.
  • Organization and stack: their stacks and services, with the actions that fit, such as creating a stack or adding a service.
  • Service: its status, its CPU, RAM, and disk usage, and its logs, refreshed live, next to the actions you can run on it.

Every change asks for a confirmation first. At the bottom of the screen, the CLI always shows the equivalent command line: run something once in the interactive mode, then copy the command into your scripts.

The interactive mode starts only when there is a terminal and no argument. With an argument, in a pipe, in a CI job, or with an AI agent, the CLI works as a regular command line tool. To see the list of commands, run stackhero --help.

You have two main options for authentication:

stackhero login

When you run this command, the CLI gives you a URL and also opens it automatically in your browser. From there, you can approve access directly from your Stackhero dashboard, where you are already signed in.

Two-factor authentication is fully supported, and you do not need to enter your password in the CLI.

For automated workflows, you can create an access token in your dashboard under Account > Access tokens and provide it to the CLI with the STACKHERO_TOKEN environment variable.

export STACKHERO_TOKEN="usr-xxxxxx:your-token"
stackhero organizations-list

When STACKHERO_TOKEN is set, it takes precedence over interactive sessions, so a browser is optional. This approach works well for non-interactive use cases. You can review and revoke tokens from your dashboard at any time.

Every CLI command accepts a global --format option:

  • human (default): Shows readable tables and text for interactive use.
  • json: Returns machine-readable JSON, which is helpful for scripts and AI agents.
  • script: Returns only raw value(s), which makes it easy to assign output to shell variables.

For example:

stackhero organizations-list --format=json
stackId=$(stackhero --format=script stack-create --name="My stack")

If you want to see the full list of available commands, you can run stackhero --help. If you want details for a specific command, you can try stackhero COMMAND --help.

Some commonly used commands include:

  • Organizations: organizations-list
  • Stacks: stacks-list (add --organization to show the stacks of one organization), stack-create, stack-rename, stack-delete
  • Services: services-list (add --stack to show the services of one stack), service-get, service-add, service-wait-for, service-logs, service-metrics, service-rename, service-restart, service-delete
  • Configuration: service-configuration-get, service-configuration-set, service-configuration-example
  • Firewall: service-firewall-get, service-firewall-set
  • Version updates: service-updates-list, service-update
  • Backups: service-backups-list, service-backup-rollback
  • Store: services-store-list, instances-store-list, regions-list
  • Upgrades: service-upgrade-instances-store-list, service-upgrade-instance
  • Account: login, logout, whoami
  • Maintenance: self-update

The commands that restart, update, restore, or delete something ask for a confirmation. In scripts, add --confirm to skip it.

Here is a sample script that shows how you can create a stack, add a service, wait for it to be ready, and retrieve its credentials. This example is fully non-interactive and uses the STACKHERO_TOKEN environment variable.

#!/bin/bash
set -e

export STACKHERO_TOKEN="usr-xxxxxx:your-token"

serviceStore="directus"   # A service store name. See: `stackhero services-store-list`
instance="20"             # An instance (size) name. See: `stackhero instances-store-list --service-store=directus`
region="europe"           # A region name. See: `stackhero regions-list`

# Create a stack (uses your only organization, add `--organization` if you have several)
stackId=$(stackhero --format=script stack-create \
  --name="My stack")
echo "Stack: ${stackId}"

# Add a service (names are resolved automatically, and the stack ID above also works)
serviceId=$(stackhero --format=script service-add \
  --stack="My stack" \
  --service-store="${serviceStore}" \
  --instance="${instance}" \
  --region="${region}")
echo "Service: ${serviceId}"

# Wait for the service to be running
stackhero service-wait-for --service="${serviceId}"

# Retrieve credentials and configuration
stackhero service-configuration-get --service="${serviceId}" --format=json

Each service documentation page includes a ready-to-run Automate with the CLI guide tailored to that service, so you have everything you need to get started.

Your tests can run against a real Stackhero service instead of a mock: your GitHub Actions or GitLab CI pipeline adds the service, runs the tests, and deletes it when the run ends. It takes a few lines:

  1. Create an access token, and store it as the STACKHERO_TOKEN secret of your CI.
  2. Create a stack for your CI, once: stackhero stack-create --name="CI". Each run adds its own service to it, so runs can overlap safely.
  3. In the job, run service-add, then timeout 15m stackhero service-wait-for, then service-configuration-get to read the credentials.
  4. In a step that always runs (if: always() on GitHub Actions, after_script on GitLab CI), run service-delete --confirm. You are never billed for a service your tests no longer use.

Each database, cache, message broker, and search engine has a complete guide with ready-to-copy YAML for both platforms and a real smoke test. For example: PostgreSQL, MySQL, Redis, RabbitMQ, and Elasticsearch.

service-updates-list shows the version of your service, the updates available, and the severity of each one (normal, critical, or critical, internet blocked). Add --changelog to read what each version brings.

Some versions cannot be skipped, so the updates are grouped in steps: each service-update installs the next step. This script applies every step, one after the other:

#!/bin/bash
set -e

service="My service"   # A service name or ID. See: `stackhero services-list`

stackhero service-updates-list --service="${service}" --changelog

while [ "$(stackhero service-updates-list --service="${service}" --format=json | jq .steps)" != "0" ]; do
  stackhero service-update --service="${service}" --confirm
  stackhero service-wait-for --service="${service}"
done

Before an update, a backup of your service is taken automatically. If you need to go back, stackhero service-backups-list --service="${service}" lists the backups, and stackhero service-backup-rollback --service="${service}" --backup=BACKUP_ID restores one.

The CLI keeps itself up to date automatically. If you ever want to force an update manually, you can run:

stackhero self-update

If you want to uninstall the CLI, you can simply delete the stackhero binary from your system.