A directory containing .clickhouse/ is a project root, as a directory containing .git/ is for Git. Run clickhousectl local init once in your project directory; project-local commands then work from that directory and any subdirectory below it, and act on the same servers, saved API keys and UDF sources.
- The nearest
.clickhouse/wins, so a project nested inside another is its own project. Equally, one in a shared parent directory (for example created by an earliercloud auth login --api-keyor server start in~/code) becomes the project for every directory beneath it that has none of its own. Runclickhousectl local initin the project directory to give it its own. .clickhouse/is git-ignored, so it does not travel with a repository. After cloning a project, runclickhousectl local initin its root once; it only creates what is missing. Until then, a subdirectory of the clone is not inside a project.~/.clickhouse/is the global directory for installed binaries, tokens and configs. It is never a project for the directories under your home directory, although running commands in your home directory itself still uses it.- A
.clickhouse/in a parent directory counts only when it is a directory you own, not a symlink, so one created by another user (in/tmp, for example) is ignored. - Outside any project, commands use the current directory. Commands that list, stop, remove or connect to servers then report an empty project and create nothing, unless a server started from that directory is still running, which they recover as usual. Server starts create
.clickhouse/in the current directory, so starting withoutlocal initstill works.
ClickHouse binaries are shared globally in ~/.clickhouse/, while each project's server data is isolated.
Set CLICKHOUSECTL_PROJECT_DIR to make one directory the project root wherever commands run, for example in a script or CI job that changes directory, or a monorepo whose subdirectories have their own .clickhouse/:
export CLICKHOUSECTL_PROJECT_DIR=~/code/app
clickhousectl local init # initializes ~/code/app, not the current directory
clickhousectl local clickhouse start # state in ~/code/app/.clickhouse/Discovery does not run: the directory is the root whether or not it holds .clickhouse/ yet, and local init initializes it. A relative path is resolved against the current directory. The value must be an existing directory and not your home directory, whose .clickhouse/ is the global one; any other value fails every command that uses the project, including Cloud commands reading saved API keys; local --json errors use code invalid_project_dir. Saved API keys, .env fallback, UDF sources and shell completion all follow the named root. An empty value counts as unset. The variable is read from the environment only, not from .env. With --json, project_scope.kind is env_override.
clickhousectl local init
clickhousectl local clickhouse start dev --version latest
clickhousectl local client dev --query "SELECT version()"
clickhousectl local clickhouse listlocal ch is short for local clickhouse, and local pg for local postgres. The earlier name local server still works as an alias for local clickhouse.
local init marks the current directory as the project root and scaffolds clickhouse/ and postgres/ directories for schemas, queries, seed data, UDF sources, and server config applied on every start. It initializes the current directory, or CLICKHOUSECTL_PROJECT_DIR when set: run inside an existing project, it creates a nested project and names the enclosing one.
Named starts reuse the server's data. Background starts wait up to 30 seconds for HTTP and TCP readiness; --no-wait returns after spawning. Failures point to .clickhouse/servers/<name>/server.log. Default ports are HTTP 8123 and TCP 9000, with free ports assigned when occupied. Use --http-port and --tcp-port to request specific ports; they must differ, and an omitted port never takes the one the other listener uses.
Without a name, the first server is default; if it is already running, another start generates a new name. Use an explicit name for a repeatable workflow. Names ending in -pg and digits, such as dev-pg17, are how Postgres instances are stored on disk, so local clickhouse and local udf refuse them with a usage error (exit 2) unless an existing ClickHouse server already has that name.
| Selector | Meaning |
|---|---|
latest |
Rolling master build, checked remotely on each install/use/start |
stable |
Latest stable release |
lts |
Latest long-term support release |
26.8 |
Latest matching 26.8 release |
26.8.1.1760 |
Exact version |
clickhousectl local use stable
clickhousectl local which
clickhousectl local list
clickhousectl local list --remotelocal use installs if needed and sets the default for future server starts. clickhouse start --version chooses a version for that start without changing the default.
A bare start installs latest if no version or default is available, without setting a default. Pin a version or use local use stable to avoid tracking master. Reusing latest requires a successful remote freshness check; an unavailable server is an error, not a fallback to an unverified build.
To run a ClickHouse binary you built yourself, install it from its path:
clickhousectl local install --binary ~/ClickHouse/build/programs/clickhouseclickhousectl copies the file into ~/.clickhouse/versions/, runs the copy with --version, and installs it under the version it reports, such as 26.1.1.1. Select that version with local use or clickhouse start --version, and remove it with local remove, like any other install. A later rebuild usually reports the same version, so pass --force to replace the installed copy; servers already running keep the old binary until restarted. A file that does not run or does not report a ClickHouse version within 60 seconds is rejected and nothing is installed.
Connect to a running server by name. local client finds its TCP port and uses the same ClickHouse binary as the server. With no name, it picks a server by the selection rule.
# Open an interactive SQL session
clickhousectl local client dev
# Run a query, or several queries in order
clickhousectl local client dev --query "SELECT version()"
clickhousectl local client dev --query "SELECT 1" --query "SELECT 2"
# Run SQL from files
clickhousectl local client dev --queries-file schema.sql seed.sqlCreate schema.sql and seed.sql with your project's SQL before running the file example. --queries-file accepts multiple paths or repeated flags. Use either --query (-q) or --queries-file in a command; they cannot be combined. Repeated --query flags require ClickHouse 23.9.1.1854 or newer.
To connect by address, use --host and/or --port instead of a server name. Omitted values default to localhost and TCP port 9000. In this mode, --version selects an already installed numeric version, such as 26.8; it never downloads one or changes the default. Without --version, the client uses the default version, or the sole installed version if no default is set. Named connections cannot combine with --host, --port, or --version.
Query output and exit status come from the ClickHouse client, including under --json or agent detection. Set the result format in SQL when scripting:
clickhousectl local client dev --query "SELECT version() FORMAT JSONEachRow"Use clickhousectl to manage the binary, then run clickhouse directly. Select the rolling master build and put the managed binary on your shell's PATH:
clickhousectl local use latest
export PATH="$HOME/.local/bin:$PATH"
clickhouse client --versionlocal use installs the selected version if needed, sets it as the default, and creates or updates ~/.local/bin/clickhouse. Keep the PATH export in your shell startup file to use it in future sessions. An existing regular file at that path is preserved; --no-global skips creating or updating the symlink.
You can also run the native client against servers managed by clickhousectl. Choose a free TCP port, such as 9001:
clickhousectl local clickhouse start native-demo --tcp-port 9001
clickhouse client --host localhost --port 9001 \
--query "SELECT version()" --format CSV
clickhousectl local clickhouse stop native-demoFor an existing server, find its TCP port with clickhousectl local clickhouse list and pass that port to clickhouse client. The native client connects by host and port; clickhousectl manages the server's process, configuration, and data. All native client options are available directly.
Run local use latest again to check for a newer master build, or select stable, lts, or an exact version to switch the binary. Switching changes the binary used by subsequent clickhouse commands and the default for new servers. Running servers keep their existing version, and a stopped server restarts on the version it last ran successfully, shown by local clickhouse list; pass --version to local clickhouse start to move its data to another version. To match a running server, select its version from local clickhouse list with local use <version>.
Managed servers use embedded defaults. Partial XML, YAML, or YML configuration files override them from three locations:
| Location | Applies to | When |
|---|---|---|
~/.clickhouse/config.d/ |
every server on this machine | every start |
clickhouse/config.d/ in the project root |
every server in this project; check it in to share it | every start |
~/.clickhouse/configs/ |
the server you name it for | only with --config NAME |
Every local clickhouse start merges them in that order, later files winning: built-in defaults, then every file in ~/.clickhouse/config.d/, then every file in the project's clickhouse/config.d/, then the --config file, then the data path and ports the CLI manages. Files within a directory merge in name order. A file with the same name in both config.d directories applies twice, the project's last. Hidden files, other extensions and subdirectories are skipped. The CLI creates ~/.clickhouse/configs/ and ~/.clickhouse/config.d/, and local init creates clickhouse/config.d/.
cat > clickhouse/config.d/logging.xml <<'XML'
<clickhouse>
<logger><level>debug</level></logger>
</clickhouse>
XML
cat > ~/.clickhouse/configs/analytics.xml <<'XML'
<clickhouse>
<profiles>
<default><max_threads>4</max_threads></default>
</profiles>
</clickhouse>
XML
clickhousectl local clickhouse configs
clickhousectl local clickhouse stop dev
clickhousectl local clickhouse start dev --config analyticslocal clickhouse configs lists both config.d directories with their files, and the named configs. A named config must be directly inside ~/.clickhouse/configs/, not an arbitrary path; select its filename or unambiguous stem. Use a <clickhouse> root in XML; user profiles and query settings can be included there. The server does not automatically load /etc/clickhouse-server/config.xml or a separate users.xml.
Each start copies the files into .clickhouse/servers/<name>/data/config.d/ (as chctl-0-global-<file>, chctl-1-project-<file> and chctl-config.<ext>) after removing the copies from the previous start, so edits, deleted files and a dropped --config take effect on the next start. A file in ~/.clickhouse/config.d/ applies to every project, so a broken one breaks every start: a failed start lists each copied file and its source next to the server log path. Managed data paths and ports override config values, including after ClickHouse reloads its config. Referenced files, such as dictionaries or scripts, are not copied: give their paths as absolute paths or relative to the server's working directory, .clickhouse/servers/<name>/data/. Inspect the merged preprocessed_configs/config.xml there, but edit the source files rather than that generated file.
local udf deploys executable UDFs from the project root's clickhouse/udfs/ to a local server, from the same directory cloud udf uploads. See User-defined functions.
Docker must be running. Postgres 17 and 18, including image sub-tags, are supported; new instances default to 18. A random password is generated unless supplied.
clickhousectl local postgres start app --version 18
clickhousectl local postgres client app --query "SELECT version()"
clickhousectl local postgres client app --queries-file pg-schema.sql
clickhousectl local postgres dotenv app --local
clickhousectl local postgres list
clickhousectl local statusEach engine's list and stop-all cover only that engine. local status lists every ClickHouse server and Postgres instance in the project, running or stopped.
Create pg-schema.sql with your Postgres SQL before running the file example. File and piped stdin input stop at the first failed statement and exit 3; pass -- -v ON_ERROR_STOP=0 to run the remaining statements.
Starts wait for pg_isready, by default for 60 seconds; --wait-timeout accepts 1–600 seconds. local postgres client uses host psql or the container's psql. File input and stdin work with either, but paths inside SQL (\i, \copy) refer to the container filesystem in Docker mode. --json does not change psql output. When both are supplied, --query runs before --queries-file.
An instance is identified by name and major version. The name becomes part of the Docker container name, clickhousectl-pg-<project hash>-<name>-<major>, so it may use only letters, digits, _, ., and -. The short project hash lets different projects use the same instance name; containers created before it was added keep their old name. Pass --version when more than one major shares a name. Resuming an instance reuses its original port, user, password, database, and environment; new creation flags do not reconfigure it. If another process now holds that port, the resume fails with port_in_use instead of starting without it; free the port and start again. Every start also confirms Docker published the port, and stops the container if it did not. To recreate, first back up any needed data, then stop and remove the instance before starting again. Direct --host/--port client selectors cannot combine with managed name/version selectors.
The generated .env.local includes the password. Keep it out of version control. Both engines' dotenv commands write a file and print an informational preview: use your application's dotenv loader, never eval their stdout.
Commands that act on an existing server take its name: local client, local udf (as --server), and each engine's stop, client and dotenv. Without one, they select the server named default, else the project's only server of that engine (for Postgres, the only instance name; --version then picks its major). With several and none named default, they fail with server_selection_required and list the names. With none, stop succeeds as a no-op and the others report default as not found. remove deletes data, so it never guesses: without a name it removes only default. Scripts should pass names explicitly.
clickhousectl local clickhouse stop dev
clickhousectl local postgres stop app --version 18Stop preserves data. Stopping a server or instance that exists but is not running succeeds and reports already_stopped: true; an unknown name is an error. The following removals permanently delete the selected server's data, including Postgres container volumes:
clickhousectl local clickhouse remove dev
clickhousectl local postgres remove app --version 18Both require stopped servers. local clickhouse stop-all and local postgres stop-all each stop one engine's servers in the current project. Global ClickHouse operations (clickhouse list --global, stop --global, stop-all --global) span projects; confirm the project and name before stopping one. stop --global --project <project-root> disambiguates matching names.
local remove <exact-version> removes a shared ClickHouse binary, not server data. It refuses a default or a version used by running servers in any project, and refuses when the running processes cannot be read, since then other projects' servers are unknown. Its --force stops those servers across projects and removes the version even if it is the default; after a failed process scan it stops only this project's servers.
If metadata is corrupt, follow the reported recovery guidance. Confirm the running process with clickhouse list --global, or the Postgres container with Docker, before moving metadata aside. Do not delete state or force-remove an unverified server. A Docker inspection failure is an error, not evidence that Postgres is stopped.