---
url: /runcobo/cli.md
description: >-
  The cobo command-line tool — routes, development server, console, tasks,
  database and code generation.
---

# cobo CLI

`cobo` is Runcobo's command-line toolchain for development and deployment. It's a separate binary: your compiled application never loads it.

```text
cobo [--root PATH] COMMAND [arguments...]
```

`--root PATH` runs a command against another project directory.

## Installing

`shards install` builds it into your project's `bin/cobo` when Runcobo is installed or upgraded:

```sh
shards install
bin/cobo --help
```

Or install it globally from a framework checkout with `make install INSTALL_DIR=...`, which also installs a pinned `runcobo-dbmate`. See [Installation](/guide/installation#the-cobo-cli).

## Commands at a glance

| Command | What it does | Needs `runcobo.yml` |
| --- | --- | :---: |
| [`init`](#cobo-init) | Set up a project created by `crystal init app` | |
| [`routes`](#cobo-routes) | Print the application's route table | |
| `version` | Print the framework version | |
| [`dev`](#cobo-dev) | Prepare the database, then run the server and restart it on changes | ✓ |
| [`console`](#cobo-console) | Interactive Crystal console with the app loaded | ✓ |
| [`runner FILE`](#cobo-runner) | Run a Crystal script with the app loaded | ✓ |
| [`task list` / `task run NAME`](#cobo-task) | Run project tasks defined in `runcobo.yml` | ✓ |
| [`test`](#cobo-test) | Run specs against the local test database | ✓ |
| [`db ...`](/cli/database) | Local databases, migrations, verification | ✓ |
| [`generate`](/cli/codegen) | Generate typed SQL query code | ✓ |

Commands marked ✓ read the development configuration in [`runcobo.yml`](/cli/configuration).

## `cobo init`

```sh
bin/cobo init [--database postgresql|mysql|sqlite|none]
```

Run once, in a project created by `crystal init app` with Runcobo installed — see [Installation](/guide/installation#create-a-project). It writes the [standard layout](/guide/project-structure) with a home endpoint at `/`, adds the database driver to `shard.yml`, runs `shards install` and, with a database, generates the query code (this needs sqlc; if it's missing, install it and run `bin/cobo generate`).

`--database` defaults to `postgresql`; `none` leaves out `sqlc.yaml`, `db/` and the store. Placeholder files from `crystal init` are replaced only while unchanged, and any other existing file stops the command before it writes anything.

## `cobo routes`

Compiles your route-registration file and prints every route:

```sh
bin/cobo routes
bin/cobo routes --require src/route_loader.cr   # use another entry file
bin/cobo routes --no-color > routes.txt
```

By default it loads `src/app.cr`. The file must register actions **without** starting the server — see [Project Structure](/guide/project-structure#app-cr-and-main-cr). It doesn't need `runcobo.yml` or a database.

Colors are on for terminals and off when output is redirected, when `NO_COLOR` is set, or for `TERM=dumb`. Force either way with `--color` / `--no-color`.

## `cobo dev`

```sh
bin/cobo dev
```

Runs the application and restarts it whenever you change it:

1. Ensures the local development database exists and applies pending migrations (`db prepare development`).
2. Runs `seed_command`, if configured.
3. Builds `src/main.cr` and starts it with the development environment:
   * `DATABASE_URL` pointing at the local development database,
   * each `development_environment` variable that isn't already set,
   * optionally a generated secret and a public base URL (see [configuration](/cli/configuration)).
4. Watches for changes and rebuilds.

* **A change that doesn't compile** prints the error and leaves the previous server running. Fix it and save again.
* **What's watched:** `.cr`, `.jbuilder` and `.water` files under `src/`, and `shard.lock`. Files in `public/` are read from disk, so changes there need no restart. After changing `db/queries/`, run [`cobo generate`](/cli/codegen); the generated code is in `src/`, so the server restarts.
* **Not applied automatically:** new migrations (run `bin/cobo db migrate`) and changes to `runcobo.yml` or `sqlc.yaml` (`cobo dev` tells you to restart it).
* **If the server exits on its own,** `cobo dev` waits for the next change.
* **Ctrl-C** stops the server gracefully, then `cobo dev`.

A project without a `sqlc.yaml` has no database: `cobo dev` skips step 1 and sets no `DATABASE_URL`.

## `cobo console`

```sh
bin/cobo console
```

Opens the Crystal interpreter (`crystal i`) with your application entry loaded and the development environment set. Requires a Crystal build that includes the interpreter. The entry is `application_entry` from `runcobo.yml`, or `src/app.cr` if present.

## `cobo runner`

```sh
bin/cobo runner scripts/backfill.cr -- --dry-run
```

Compiles and runs a Crystal script after loading your application entry, with the development environment. Arguments after `--` are passed to the script. The database is not prepared or seeded.

## `cobo task`

Register reusable commands in `runcobo.yml`:

```yaml [runcobo.yml]
tasks:
  rebuild-search:
    description: Rebuild the local search index
    command: [crystal, run, src/jobs/rebuild_search.cr, --]
```

```sh
bin/cobo task list
bin/cobo task run rebuild-search -- books
```

Tasks run from the project root with the development environment. Each element of `command` and each extra argument is passed as a separate argument — no shell is involved.

## `cobo test`

```sh
bin/cobo test                 # crystal spec
bin/cobo test --prepare       # create/migrate the test database first
bin/cobo test spec/models -- --verbose
```

Runs `crystal spec` with `DATABASE_URL` and `TEST_DATABASE_URL` set to the project's local test database (left unset in a project without a `sqlc.yaml`).
