The DeployHQ CLI includes several utility commands for managing SSH keys, templates, deployment zones, shell completions, and more.

## SSH Keys

Manage account-level SSH keys used for server authentication.

### Listing SSH Keys

```bash
dhq ssh-keys list
```

### Creating an SSH Key

```bash
# Create an ED25519 key (default)
dhq ssh-keys create --title "Production Key"

# Create an RSA key
dhq ssh-keys create --title "Legacy Key" --type RSA
```

Keys are generated on the server. The CLI displays the public key, which you should add to your server's `authorized_keys` file. Once created, a key can be reused across servers and projects, so rotating it is a single change.

### Downloading a Private Key

```bash
# Save the private key to a file (written with owner-only permissions)
dhq ssh-keys download <id> --output key.pem
```

Downloading a private key is only available to account admins on a paid plan. Use `--output` to save the key to a file rather than redirecting the output of the command.

### Deleting an SSH Key

```bash
dhq ssh-keys delete <id>
```

## Templates

Templates are reusable project configurations.

### Listing Templates

```bash
# List your templates
dhq templates list

# List public templates
dhq templates public

# Filter public templates by framework
dhq templates public --framework rails
```

### Viewing a Template

```bash
# Show one of your templates
dhq templates show my-rails-template

# Show a public template (template ID, then public ID)
dhq templates public-show <template-id> <public-id>
```

### Creating a Template

```bash
dhq templates create --name "My Rails Template"

# Copy the configuration from an existing project and set up email notifications
dhq templates create --name "Rails Standard" \
  --project my-app \
  --description "Our standard Rails setup" \
  --email-notify \
  --notification-email deploys@example.com
```

### Updating a Template

```bash
dhq templates update my-rails-template --name "Updated Template" --description "New description"
```

### Deleting a Template

```bash
dhq templates delete my-rails-template
```

### Configuring a Template

Each part of a template's configuration has its own command group. All of them take the template's permalink with `-t, --template`.

| Command group | What it manages | Subcommands |
|---|---|---|
| `servers` | Servers | list, show, create, update, delete |
| `server-groups` | Server groups | list, create, update, delete |
| `build-commands` | Build commands | list, create, update, delete |
| `build-cache-files` | Build cache paths | list, create, update, delete |
| `build-known-hosts` | Known hosts for builds | list, create, delete |
| `build-languages` | Language versions used by builds | set |
| `build-configuration` | Default build environment (read-only) | none |
| `commands` | SSH commands | list, create, update, delete |
| `config-files` | Config files | list, show, create, update, delete |
| `excluded-files` | Excluded file patterns | list, create, update, delete |
| `integrations` | Integrations | list, create, update, delete |

```bash
# Add a server
dhq templates servers create -t my-rails-template \
  --name "Production" --protocol-type ssh --server-path /var/www/app

# Add a server group that deploys to its servers in parallel
dhq templates server-groups create -t my-rails-template \
  --name "Web servers" --transfer-order parallel

# Add build commands and cache paths
dhq templates build-commands create -t my-rails-template \
  --command "bundle install" --description "Install gems"
dhq templates build-cache-files create -t my-rails-template --path vendor/bundle

# Pin a language version for builds
dhq templates build-languages set ruby -t my-rails-template --version 3.3

# Run an SSH command on every deployment
dhq templates commands create -t my-rails-template \
  --command "touch tmp/restart.txt" --timing all

# Exclude files and add a config file
dhq templates excluded-files create -t my-rails-template --path "spec/*"
dhq templates config-files create -t my-rails-template \
  --path config/settings.yml --body "environment: production"

# Review the default build environment
dhq templates build-configuration -t my-rails-template
```

`--transfer-order` accepts `sequential` (each server's whole deployment runs as one unit) or `parallel` (each step finishes on every server before any server starts the next). To update or delete an item, pass its ID, for example `dhq templates build-commands delete <id> -t my-rails-template`. Run `dhq templates <group> --help` to see every flag.

## Deployment Zones

View available deployment zones:

```bash
dhq zones list
```

Zones determine the geographic location of your deployment infrastructure.

## Account Administration

These commands manage your account, your own profile, and the people who use the account. Some require an account admin or a specific permission, and DeployHQ returns a permission error if your key does not have it.

### Account

```bash
# Show the current account
dhq account get

# Show billing status
dhq account billing

# Update account settings
dhq account update --name "Acme Ltd" --time-zone "London"
dhq account update --two-factor-required --strong-password-required
```

`dhq account update` also accepts `--permalink`, `--cname`, `--ip-restricted` and `--ai-features-disabled`.

### Your Profile

```bash
dhq profile get
dhq profile update --first-name Alex --last-name Smith --time-zone "London"

# Preferences: sort projects alphabetically, receive promotional emails
dhq profile update --alphabetic-sort --promotions-enabled
```

### API Keys

```bash
# Create a read-only key
dhq api-keys create --description "CI reporting" --read-only

# Delete a key
dhq api-keys delete <identifier>
```

The plaintext key is shown once, when it is created. Store it securely, because it cannot be retrieved again.

### Teams

Teams are permission groups. A team bundles a set of permissions with a list of member users.

```bash
dhq teams list
dhq teams show <id>

# Create a team that can create projects and manage users
dhq teams create "Developers" --can-create-projects --can-manage-users --user-ids 12,15

# Rename a team, or remove all of its members
dhq teams update <id> --name "Engineering"
dhq teams update <id> --clear-members

dhq teams delete <id>
```

Other permission flags are `--admin`, `--all-projects`, `--can-manage-billing` and `--can-manage-agents`. Setting `--admin` also enables every other permission and grants access to all projects. Membership is only changed when you pass `--user-ids` (or `--clear-members` on update); otherwise it is left as it is.

### Users

```bash
dhq users list
dhq users show <identifier>

# Invite a user
dhq users create --email alex@example.com --first-name Alex --last-name Smith --all-projects

# Change a user, resend their invitation, or remove them
dhq users update <identifier> --can-manage-billing
dhq users resend-invitation <identifier>
dhq users delete <identifier>
```

The `--admin`, `--can-create-projects`, `--can-manage-agents`, `--can-manage-billing` and `--can-manage-users` flags can only be set by an admin.

### Folders

Folders organise your projects into groups for display. Deleting a folder does not delete its projects; they are simply ungrouped.

```bash
dhq folders list
dhq folders create "Client Sites"
dhq folders update <identifier> --name "Agency Clients"
dhq folders delete <identifier>
```

### Invoices

```bash
# List invoices
dhq invoices list

# Download an invoice as a PDF
dhq invoices download <number> --output march.pdf
```

Invoices require an API key belonging to a billing manager. Without `--output`, the file is saved as `invoice-<number>.pdf`.

### Plans

```bash
dhq plans
```

Shows DeployHQ's subscription plans, with prices in the currency inferred from your location. Add `--json` to include each plan's features. This command is also available as `dhq pricing`.

## Managed Hosting

DeployHQ's managed hosting (Static Hosting and Managed VPS) is currently in beta.

```bash
# Enroll your account (Managed VPS by default)
dhq beta enroll

# Enroll in Static Hosting instead
dhq beta enroll --protocol static_hosting
```

Enrolling requires an account admin. A Managed VPS also needs a payment method on the account. Static Hosting does not: an account that is not paying yet can have one site, and paying accounts can have more. Once enrolled, you can browse what is available and manage your hosted resources:

```bash
# List the regions and sizes available for Managed VPS
dhq managed-hosting regions
dhq managed-hosting sizes

# List and inspect your hosted resources
dhq hosted-resources list
dhq hosted-resources show <id>

# Request a re-sync of a resource's provisioning state
dhq hosted-resources sync <id>

# Retry provisioning for a resource in the error state
dhq hosted-resources retry-provision <id>
```

Use the region and size values with `dhq launch` or `dhq servers create --region <region> --size <size>`. The hosted resource commands require both admin permissions and the beta.

## Firewall IP Ranges

Show the IP addresses and ports DeployHQ connects from, so you can allow them in your server's firewall:

```bash
dhq ip-ranges

# Full detail, including per-zone and network agent ranges
dhq ip-ranges --json
```

## Detecting Your Framework

Scan a project directory and ask DeployHQ to detect the framework, the suggested deployment protocol, and a build pipeline:

```bash
# Scan the current directory
dhq detect

# Scan another directory
dhq detect ~/code/my-app
```

The scan uploads the list of file names in the directory and the contents of a limited set of manifest files, such as `package.json`, `Gemfile`, `requirements.txt` and `go.mod`. The `.git` and `node_modules` directories are skipped.

## Parsing DeployHQ URLs

Break a DeployHQ URL into its project, resource, and identifier:

```bash
dhq url parse https://myco.deployhq.com/projects/my-app/deployments/abc123
```

## Testing Server Access

Check that DeployHQ can connect to the servers in a project:

```bash
# Test every server in the project
dhq test-access -p my-app

# Test one server, waiting up to 60 seconds for results
dhq test-access -p my-app --server production --timeout 60

# Look up the results of an earlier test run
dhq test-access show <run-id> -p my-app
```

## Shell Completions

The CLI supports tab completion for bash, zsh, fish, and PowerShell. Completions include dynamic suggestions for project names, server names, and other resource identifiers when using flags like `--project`, `--server`, `show`, and `open`.

### Zsh

Add to your `~/.zshrc`:

```bash
source <(dhq completion zsh)
```

### Bash

Add to your `~/.bashrc`:

```bash
source <(dhq completion bash)
```

### Fish

```bash
dhq completion fish | source
```

To make it persistent, save to the Fish completions directory:

```bash
dhq completion fish > ~/.config/fish/completions/dhq.fish
```

### PowerShell

```powershell
dhq completion powershell | Out-String | Invoke-Expression
```

## Health Check

Run a diagnostic check to verify your CLI setup:

```bash
dhq doctor
```

This checks:
- CLI version and available updates
- Authentication status
- API connectivity
- Configuration file validity

If you are not signed in, it tells you to run `dhq auth login`, or `dhq signup` if you do not have a DeployHQ account yet.

## Self-Update

Update the CLI to the latest version:

```bash
dhq update
```

If you installed via Homebrew, this runs `brew upgrade dhq`. Otherwise, it downloads the latest release from GitHub.

## Account Signup

Create a new DeployHQ account from the terminal:

```bash
dhq signup
```

Sign-up asks you to accept the DeployHQ [Terms of Service](https://www.deployhq.com/terms); an empty answer counts as a no. Your credentials are saved automatically. Afterwards, open the verification link DeployHQ emails you, because API requests are refused until your email address is verified. The next steps the CLI suggests are for once you have verified it.

Signing up switches the CLI to the new account. If the `DEPLOYHQ_ACCOUNT` environment variable or the `.deployhq.toml` in the current folder (or a parent folder) still names a different account, the CLI warns you that it is still using that account; unset the variable, or change or remove the account line in `.deployhq.toml`, to use the new one.

Without a terminal, for example in a script, `dhq signup` also needs `--email` and `--password`, plus `--accept-terms` to confirm that the person creating the account has read and accepted the terms. `--full-name` and `--account-name` are optional; `--account-name` sets the account subdomain and is generated for you if omitted. Run `dhq signup` yourself in a terminal rather than from an automated tool, so that your password is not placed on a command line. When it cannot prompt for a password, `dhq signup` stops and says that the person creating the account has to run it themselves in a separate terminal window.

## Account Activity

View recent account activity:

```bash
# List activity events
dhq activity list

# View deployment statistics
dhq activity stats
```

## Quick Dashboard

View a summary of deployments across all projects:

```bash
dhq status
```

This shows deployments this week, success rate, average duration, active servers, and recent activity.

## Feedback

Send feedback or report issues:

```bash
dhq feedback
```

## Opening DeployHQ in the Browser

Open the DeployHQ dashboard, or a specific project:

```bash
# Open dashboard
dhq open

# Open a specific project
dhq open my-app
```

## Telemetry

The CLI collects anonymous usage telemetry to help improve the product. It records the command name, exit code, duration, CLI version, operating system, architecture, and a sanitized one-line error summary on failure (home paths, emails, identifiers, and secrets are redacted). It never records your account, project, command arguments, full stack traces, or credentials.

Check the current status:

```bash
dhq telemetry status
```

Opt out:

```bash
dhq telemetry disable
```

Opt back in:

```bash
dhq telemetry enable
```

## Output Options

Two global flags are useful when scripting:

```bash
# Print only the identifier of each row, one per line
dhq projects list --quiet

# Force table output even when piped
dhq projects list --table | less
```

List commands that support paging (such as `dhq teams list`, `dhq servers list` and `dhq deployments list`) accept `--page` and `--per-page`.

## Command Catalog

Output the full list of commands as JSON, used by AI agents and scripts to discover what the CLI can do:

```bash
dhq commands
```

## Version

Check the installed CLI version:

```bash
dhq version

# The global flag works too
dhq --version
```
