CLI

The Keel CLI is your primary tool for developing, testing, and deploying Keel applications. It handles everything from project initialization to local development, testing, and self-hosted deployments.

Installing Keel CLI

The Keel CLI can be installed from NPM:

npm install -g keel

To verify the installation and check your version:

keel --version

Global flags

These flags are available on all commands:

FlagShortDescription
--dir-dDirectory containing a Keel project (defaults to current directory)
--version-vPrint the Keel CLI version

Commands overview

CommandDescription
keel initInitialize a new Keel project
keel runStart a local development server
keel generateGenerate SDK and scaffold functions
keel validateValidate your schema and config
keel testRun your test suite
keel clientGenerate a TypeScript client SDK
keel seedApply seed data to the database
keel secretsManage local development secrets

keel init

Initialize a new Keel project with an interactive setup wizard.

keel init

The init command guides you through:

  1. Directory — Choose where to create your project
  2. Template — Start with a blank project or a starter template
  3. Package Manager — Select npm or pnpm
  4. Version Control — Optionally initialize a Git repository

What gets created

For a blank project, keel init creates:

my-keel-app/
├── schema.keel        # Your Keel schema
├── keelconfig.yaml    # Project configuration
├── .gitignore         # Git ignore rules
├── package.json       # Node.js dependencies
└── node_modules/      # Installed packages

The command also runs keel generate automatically to create the @teamkeel/sdk and @teamkeel/testing packages.

Starter templates

When you select "Starter template", the CLI downloads templates from the teamkeel/starter-templates (opens in a new tab) repository and lets you choose from available options.


keel run

Start a local development server for your Keel project.

keel run

The run command

This command:

  • Sets up a local PostgreSQL database using Docker
  • Runs any pending database migrations
  • Validates your schema
  • Sets up your functions
  • Starts a development server on port 8000
  • Watches for changes to your schema and function files

Flags

FlagDescriptionDefault
--portPort to run the development server on8000
--hostnameCustom hostname to handle HTTP requests
--resetReset the database on startup (deletes all data)false
--private-key-pathPath to a private key .pem file for JWT signing
--database-urlPostgreSQL connection string to use instead of Docker

Examples

Run on a different port:

keel run --port 3000

Reset the database and start fresh:

keel run --reset
⚠️

Using --reset will delete all data in your local database. This cannot be undone.

Use an external PostgreSQL database instead of Docker:

keel run --database-url postgresql://user:password@localhost:5432/mydb

This is useful if you prefer to manage your own PostgreSQL instance during local development or need to connect to a specific database setup.

GraphiQL playground

While the development server is running, you can access a GraphiQL playground at:

http://localhost:8000/api/graphiql

This provides an interactive environment to explore and test your GraphQL API.


keel generate

Generate the @teamkeel/sdk package and scaffold missing function files.

keel generate

The generate command

This command:

  • Generates @teamkeel/sdk with TypeScript types from your schema
  • Generates @teamkeel/testing for writing tests
  • Creates stub files for any custom functions defined in your schema

When running keel run, code generation happens automatically when your schema changes. Use keel generate when you need to regenerate manually.


keel validate

Validate your Keel schema and configuration files.

keel validate

The validate command

If your project is valid, you'll see:

✨ Everything's looking good!

If there are errors, they're displayed with context showing exactly where the problem is in your schema or config files.

Flags

FlagDescriptionDefault
--jsonOutput validation errors as JSONfalse
--schemaBase64-encoded schema (for tooling integration)
--configBase64-encoded config (for tooling integration)

JSON output

For integration with editors and CI pipelines, use --json to get structured output:

keel validate --json

This returns a JSON object with validationErrors and configErrors arrays.


keel test

Run your test suite using Vitest (opens in a new tab).

keel test

Keel's test runner:

  • Starts a sandboxed database for test isolation
  • Builds your project and starts a test server
  • Runs Vitest with your test files
  • Cleans up resources after tests complete

Flags

FlagShortDescriptionDefault
--pattern-pRegex pattern to filter which tests run(.*)
--private-key-pathPath to a private key .pem file

Examples

Run all tests:

keel test

Run only tests matching a pattern:

keel test --pattern "createOrder"

Learn more about writing tests in Keel in the Testing documentation.


keel client

Generate a TypeScript client SDK for your Keel API.

keel client

This creates a fully-typed TypeScript client that you can use in frontend applications, scripts, or other services to interact with your Keel API.

Flags

FlagShortDescriptionDefault
--api-aName of the API to generate a client for
--output-oDirectory to output the generated client.
--packageGenerate as a package (with package.json) instead of a single filefalse
--watchWatch for schema changes and regeneratefalse

Examples

Generate a client for your default API:

keel client

Generate a client for a specific API into a lib directory:

keel client --api web --output ./lib

Generate as a standalone package:

keel client --package --output ./packages/api-client

Watch mode for development:

keel client --watch --output ./src/lib

Single file vs package

By default, keel client generates a single TypeScript file. This works well for most use cases.

With --package, it generates a complete npm package structure with its own package.json. This is useful when you want to:

  • Share the client across multiple projects
  • Publish the client to a private npm registry
  • Keep the client in a monorepo package

keel seed

Apply seed data to your local database.

keel seed

This command executes SQL files in your project's seed/ directory to populate your database with initial data.

Snapshot

Create a database snapshot after seeding:

keel seed snapshot

This is useful for creating a known database state that you can restore to later.

Seed directory structure

Create a seed/ directory in your project root with SQL files:

my-keel-app/
├── seed/
│   ├── 001_categories.sql
│   ├── 002_products.sql
│   └── 003_users.sql
├── schema.keel
└── keelconfig.yaml

Files are executed in alphabetical order, so prefix them with numbers to control the order.


keel secrets

Manage secrets for local development and testing.

keel secrets

Secrets are stored in your CLI config at ~/.keel/config.yaml and are available to your Keel app during local development.

Subcommands

secrets list

List all secrets for an environment:

keel secrets list
keel secrets list --env test

secrets set

Set a secret value:

keel secrets set MY_API_KEY "sk-secret-value"
keel secrets set STRIPE_KEY "sk_test_..." --env test

secrets remove

Remove a secret:

keel secrets remove MY_API_KEY
keel secrets remove STRIPE_KEY --env test

Flags

FlagShortDescriptionDefault
--env-eEnvironment (development or test)development

The keel secrets command manages secrets for local development only. For deployed environments, use the Keel Console (opens in a new tab) for Keel-hosted projects.


Troubleshooting

Docker not running

If you see errors about Docker, ensure Docker Desktop is running:

docker ps

Port already in use

If port 8000 is already in use, specify a different port:

keel run --port 3001

Package manager issues

The CLI auto-detects your package manager from lockfiles. If you're having issues, ensure you have either package-lock.json (npm) or pnpm-lock.yaml (pnpm) in your project or a parent directory.