MCPcopy Index your code
hub / github.com/ClickHouse/clickhousectl

github.com/ClickHouse/clickhousectl @v0.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.1 ↗ · + Follow
2,173 symbols 5,205 edges 77 files 414 documented · 19%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

clickhousectl

Beta: clickhousectl is currently in beta. Features and behavior may change.

clickhousectl is the CLI for ClickHouse: local and cloud.

With clickhousectl you can: - Install and manage local ClickHouse versions - Launch and manage local ClickHouse servers - Execute queries against ClickHouse servers - Setup ClickHouse Cloud and create cloud-managed ClickHouse clusters - Manage ClickHouse Cloud resources - Create and manage ClickPipes for data ingestion (S3, Kafka, Kinesis, Postgres, MySQL, MongoDB, BigQuery) - Install the official ClickHouse agent skills into supported coding agents - Push your local ClickHouse development to cloud

clickhousectl helps humans and AI-agents to develop with ClickHouse.

Installation

Quick install

curl https://clickhouse.com/cli | sh

The install script will download the correct version for your OS and install to ~/.local/bin/clickhousectl. A chctl alias is also created automatically for convenience.

cargo binstall

If you already have cargo-binstall, this pulls the prebuilt binary from builds.clickhouse.com:

cargo binstall clickhousectl

npm

npm install -g clickhousectl

This installs an npm wrapper package that downloads the matching prebuilt binary from builds.clickhouse.com at install time. Both clickhousectl and chctl are exposed as commands. If you use npm install --ignore-scripts, the download is skipped — fall back to one of the other install paths.

pip

pip install clickhousectl
# or
pipx install clickhousectl
# or
uv tool install clickhousectl

This installs a prebuilt wheel containing the matching clickhousectl binary. Linux (glibc and musl, x86_64 and aarch64) and macOS (Intel and Apple Silicon) wheels are published to PyPI.

From crates.io

Builds from source:

cargo install clickhousectl

From this repo

cargo install --path crates/clickhousectl

Direct download

Prebuilt archives for each release are hosted at https://builds.clickhouse.com/clickhousectl/. Archives are named clickhousectl-{target}-v{version}.tar.gz and contain a single directory of the same name with the clickhousectl binary inside. Supported targets: x86_64-unknown-linux-musl, aarch64-unknown-linux-musl, x86_64-apple-darwin, aarch64-apple-darwin. Example: https://builds.clickhouse.com/clickhousectl/clickhousectl-aarch64-apple-darwin-v0.3.0.tar.gz.

Local

Installing and managing ClickHouse versions

clickhousectl downloads ClickHouse binaries from builds.clickhouse.com, falling back to packages.clickhouse.com (Linux) or GitHub releases (macOS) when a build isn't available there.

# Install a version
clickhousectl local install latest          # Latest master build
clickhousectl local install stable          # Latest stable release
clickhousectl local install lts             # Latest LTS release
clickhousectl local install 25              # Latest 25.x.x.x
clickhousectl local install 25.12           # Latest 25.12.x.x
clickhousectl local install 25.12.5.44      # Exact version

# List versions
clickhousectl local list                    # Installed versions
clickhousectl local list --remote           # Available for download

# Manage default version
clickhousectl local use stable              # Latest stable (installs if needed)
clickhousectl local use lts                 # Latest LTS (installs if needed)
clickhousectl local use 25.12               # Latest 25.12.x.x (installs if needed)
clickhousectl local use 25.12.5.44          # Exact version
clickhousectl local use stable --no-global  # Set default but don't touch ~/.local/bin/clickhouse
clickhousectl local which                   # Show current default

# Remove a version
clickhousectl local remove 25.12.5.44

local use also creates a symlink at ~/.local/bin/clickhouse pointing to the selected version's binary, so the plain clickhouse command (e.g. clickhouse local, clickhouse client) is on PATH. Pass --no-global to skip. If a regular file already exists at that path it is left alone with a warning. local remove of the active default version also clears the symlink.

ClickHouse binary storage

ClickHouse binaries are stored in a global repository, so they can be used by multiple projects without duplicating storage. Binaries are stored in ~/.clickhouse/:

~/.clickhouse/
├── versions/
│   └── 25.12.5.44/
│       └── clickhouse
└── default              # tracks the active version

Initializing a project

clickhousectl local init

init bootstraps your current working directory with a standard folder structure for your ClickHouse project files. It is optional; you are welcome to use your own folder structure if preferred.

It creates the following structure:

clickhouse/
├── tables/                 # Table definitions (CREATE TABLE ...)
├── materialized_views/     # Materialized view definitions
├── queries/                # Saved queries
└── seed/                   # Seed data / INSERT statements
postgres/
├── tables/                 # Table definitions (CREATE TABLE ...)
├── views/                  # View definitions (CREATE VIEW ...)
├── functions/              # Function / procedure definitions (CREATE FUNCTION ...)
├── queries/                # Saved queries
└── seed/                   # Seed data / INSERT statements

Running queries

# Connect to a running server with clickhouse-client
clickhousectl local client                           # Connects to "default" server
clickhousectl local client --name dev                # Connects to "dev" server
clickhousectl local client --query "SHOW DATABASES"  # Run a query
clickhousectl local client --queries-file schema.sql # Run queries from a file
clickhousectl local client --host remote-host --port 9000  # Connect to a specific host/port

Creating and managing ClickHouse servers

Start and manage ClickHouse server instances. Each server gets its own isolated data directory at .clickhouse/servers/<name>/data/.

# Start a server (runs in background by default)
clickhousectl local server start                          # Named "default"
clickhousectl local server start --name dev               # Named "dev"
clickhousectl local server start --version stable         # Use a specific version (installs if needed, doesn't change default)
clickhousectl local server start --foreground             # Run in foreground (-F / --fg)
clickhousectl local server start --http-port 8124 --tcp-port 9001  # Explicit ports
clickhousectl local server start --config-file analytics  # Apply a custom config (see "Custom config files" below)

# List custom config files available to --config-file
clickhousectl local server configs

# List all servers (running and stopped)
clickhousectl local server list
clickhousectl local server list --global                  # List servers across all projects

# Stop servers
clickhousectl local server stop default                   # Stop by name
clickhousectl local server stop default --global          # Stop from any project
clickhousectl local server stop default --global --project /path/to/project  # Disambiguate
clickhousectl local server stop-all                       # Stop all running servers
clickhousectl local server stop-all --global              # Stop all servers system-wide

# Remove a stopped server and its data
clickhousectl local server remove test

# Write connection env vars to .env file
clickhousectl local server dotenv                        # From "default" server → .env
clickhousectl local server dotenv --name dev             # From "dev" server → .env
clickhousectl local server dotenv --local                # Write to .env.local instead
clickhousectl local server dotenv --user default --password secret --database mydb  # Include credentials

Server naming: Without --name, the first server is called "default". If "default" is already running, a random name is generated (e.g. "bold-crane"). Use --name for stable identities you can start/stop repeatedly.

Ports: Defaults are HTTP 8123 and TCP 9000. If these are already in use, free ports are automatically assigned and shown in the output. Use --http-port and --tcp-port to set explicit ports.

Orphaned server recovery: If server metadata files are lost while the ClickHouse process is still running, the CLI automatically recovers them via process discovery. Running server list, server start, or any server command will detect orphaned processes belonging to the current project and bring them back under management.

Global server management: Use --global with list, stop, and stop-all to operate across all projects system-wide. server list --global shows all running ClickHouse servers with a Project column indicating which directory each belongs to.

Custom config files

Drop ClickHouse config files into ~/.clickhouse/configs/ and apply one by name when starting a server:

mkdir -p ~/.clickhouse/configs
cat > ~/.clickhouse/configs/analytics.xml <<'EOF'
<clickhouse>
    <query_log>
        <database>system</database>
        <table>query_log</table>
    </query_log>
</clickhouse>
EOF
clickhousectl local server configs                          # List available config files
clickhousectl local server start --config-file analytics    # Start a server with it

The named file is overlaid on top of ClickHouse's built-in defaults (it is staged into the server's config.d/ directory), so it only needs to contain the settings you want to change — you don't have to reproduce a full config. Files may be .xml, .yaml, or .yml; reference them by name with or without the extension (e.g. --config-file analytics or --config-file analytics.xml). --config-file takes a name within ~/.clickhouse/configs/ not a path.

The managed data directory (.clickhouse/servers/<name>/data/) and the HTTP/TCP ports are always forced as command-line overrides, which take precedence over the config file. This means a custom config can never break the managed server lifecycle (list, stop, remove, dotenv) regardless of its contents. Starting a server again without --config-file reverts it to plain defaults.

Local Postgres (Docker-backed)

When you also need a local Postgres alongside ClickHouse — e.g. for testing CDC pipelines or ingesting from Postgres — use local postgres. Each instance is keyed on (name, major version) so the same name can host multiple Postgres majors with isolated data: data lives at .clickhouse/servers/<name>-pg<major>/data/, metadata at .clickhouse/servers/<name>-pg<major>.json, and the container is clickhousectl-pg-<name>-<major>. ClickHouse paths (<name>/data/, <name>.json) stay separate, so a name can be used by both engines. Requires Docker to be installed and running.

# Pre-pull a Postgres image (optional; start will pull on demand). Supported: 17, 18 (and any sub-tag like 17-alpine, 17.0, 18-bookworm).
clickhousectl local install postgres@17

# Start a Postgres instance (defaults: postgres:18, port 5432, user "postgres", db "postgres")
clickhousectl local postgres start
clickhousectl local postgres start --name dev --version 17 --port 5433
clickhousectl local postgres start --user app --password s3cret --database myapp
clickhousectl local postgres start -e POSTGRES_INITDB_ARGS=--data-checksums

# List everything (ClickHouse + Postgres are merged in `server list`)
clickhousectl local server list

# Connect with psql (uses host psql if installed; otherwise falls back to docker exec)
clickhousectl local postgres client --name dev
clickhousectl local postgres client --name dev --query "SELECT 1"

# Write POSTGRES_HOST/PORT/USER/PASSWORD/DATABASE into .env
clickhousectl local postgres dotenv --name dev

# Stop / remove. Pass --version when more than one major shares a name.
clickhousectl local postgres stop dev
clickhousectl local postgres stop dev --version 17        # disambiguate
clickhousectl local postgres stop-all                     # Stop all Postgres instances in this project
clickhousectl local postgres remove dev

local postgres start --name dev (no --version) resumes the existing instance when there's exactly one for that name; if multiple majors share the name, you'll be asked to pick. Stop preserves the container and metadata so the next start resumes it; only remove tears down the container and deletes the data directory.

Containers are tagged with clickhousectl.engine=postgres, clickhousectl.name=<name>, clickhousectl.major=<major>, clickhousectl.project=<cwd>, and created_by=clickhousectl_<version> labels. server list recovers orphaned containers belonging to the current project via these labels, so deleting .clickhouse/servers/<name>-pg<major>.json is non-destructive — the next list/start rediscovers it.

Project-local data directory

All server data lives inside .clickhouse/ in your project directory:

.clickhouse/
├── .gitignore              # auto-created, ignores everything
├── credentials.json        # cloud API credentials (if configured)
└── servers/
    ├── default/
    │   └── data/           # ClickHouse data files for "default" server
    └── dev/
        └── data/           # ClickHouse data files for "dev" server

Each named server has its own data directory, so servers are fully isolated from each other. Data persists between restarts — stop and start a server by name to pick up where you left off. Use clickhousectl local server remove <name> to permanently delete a server's data.

Authentication

Authenticate to ClickHouse Cloud using OAuth (browser-based) or API keys. OAuth provides read-only access; API keys provide full read/write access.

If you don't have a ClickHouse C

Core symbols most depended-on inside this repo

get
called by 109
crates/clickhousectl/src/dotenv.rs
request
called by 104
crates/clickhouse-cloud-api/src/client.rs
convert_error
called by 69
crates/clickhousectl/src/cloud/client.rs
api
called by 65
crates/clickhousectl/src/cloud/client.rs
resolve_org_id
called by 62
crates/clickhousectl/src/cloud/commands.rs
as_str
called by 58
crates/clickhousectl/src/local/server.rs
assert_write
called by 54
crates/clickhousectl/src/cloud/cli.rs
start
called by 31
crates/clickhousectl/src/local/postgres.rs

Shape

Function 1,238
Class 376
Enum 283
Method 276

Languages

Rust98%
Python2%
TypeScript1%

Modules by API surface

crates/clickhouse-cloud-api/src/models.rs513 symbols
crates/clickhousectl/src/cloud/commands.rs138 symbols
crates/clickhouse-cloud-api/src/client.rs129 symbols
crates/clickhouse-cloud-api/tests/client_test.rs125 symbols
crates/clickhousectl/src/cloud/client.rs108 symbols
crates/clickhouse-cloud-api/tests/models_test.rs104 symbols
crates/clickhouse-cloud-api/tests/common/support.rs89 symbols
crates/clickhousectl/src/local/output.rs65 symbols
crates/clickhousectl/src/cloud/postgres.rs65 symbols
crates/clickhousectl/src/version_manager/resolve.rs47 symbols
crates/clickhousectl/src/local/mod.rs47 symbols
crates/clickhousectl/src/local/server.rs45 symbols

Datastores touched

(mongodb)Database · 1 repos
mydbDatabase · 1 repos
dbDatabase · 1 repos

For agents

$ claude mcp add clickhousectl \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact