How to Configure Claude Code ClickHouse Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code clickhouse read only access by creating a restricted database user. Then you link that user to the agent through a Model Context Protocol server. Teams often start by handing an agent their own local database login. That shortcut creates risk when the user role holds broad write or admin rights. An automated tool can run fast queries and alter tables before a human notices. Setting up a dedicated read-only user stops the agent from changing or deleting data. How to set u

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up claude code clickhouse read only access by creating a restricted database user. Then you link that user to the agent through a Model Context Protocol server. Teams often start by handing an agent their own local database login. That shortcut creates risk when the user role holds broad write or admin rights. An automated tool can run fast queries and alter tables before a human notices. Setting up a dedicated read-only user stops the agent from changing or deleting data.

How to set up claude code clickhouse read only access

First, you need to set up SQL-driven access control inside your ClickHouse server. The server uses a storage directory and an admin user with access management turned on. Once enabled, you manage users, roles, row policies, settings profiles, and quotas with SQL. A database admin can only grant privileges that they already hold themselves. When creating the new user, you set the login method and allowed client hosts. You also assign default roles and specific user settings during this step.

Next, you grant read permissions to the new database account or its role. You can grant select rights on a full table or on specific columns. If you grant select on two columns, the user can only query those columns. The database refuses wildcard select queries unless the table holds only those granted columns. Since version 24.10, a trailing asterisk lets you grant select by table name prefix. This rule helps teams group read permissions across related tables with ease.

Finally, you connect the coding agent to the database using this restricted user. Claude Code reaches external tools and databases through Model Context Protocol servers. It can also run local shell commands through its built-in Bash tool. In manual mode, the Bash tool asks for human approval before running most commands. Only a small built-in list of safe read commands runs without a prompt. Official vendor docs advise using a read-only database user in the connection string. This step ensures the queries the agent runs cannot modify your stored data. You should also verify that you trust any MCP server before connecting it.

What native database roles solve and what they leave open

Native ClickHouse users and column grants solve the basic problem of write risk. A user with only select rights cannot drop tables or insert bad rows. Column grants also let you block access to known sensitive columns from the start. When the agent runs a query, the database engine checks those static rules first.

Auditor Read-Only Access + Claude Code Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, native database setup only decides who logs in and which columns they read. It does not inspect what individual statements return while the query runs in flight. If an allowed text column holds emails or phone numbers, the agent gets them. Card numbers or national IDs inside allowed columns also flow straight into the prompt. Also, storing a static database password on a laptop creates a key rotation burden. If multiple developers share one read-only account, audit logs lose individual user names. Every query in the database log looks like it came from the same shared account.

Why runtime query checks matter for coding agents

Coding agents build queries fast when they debug code or explore schema shapes. Even a read-only query can pull millions of rows or expose private customer data. Teams need a way to tie each agent query back to a real person. They also need a way to mask sensitive fields like emails or card numbers. Masking rewrites matched fields in results before the output reaches the agent context window. Combining native read-only grants with runtime checks gives teams full visibility and safer data handling.

Add runtime guardrails and masking beside ClickHouse

Database grants and network rules control who can reach ClickHouse. Even so, an allowed client or agent can send an alter mutation that deletes rows or read raw personal data. In practice, hoop.dev sits inline in the native TCP protocol beside the server as a sidecar for your ClickHouse. For every production query an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev ClickHouse support, guardrails refuse banned queries before they run or hold risky calls for approval, and data masking rewrites matched string columns in results in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How does Claude Code connect to a ClickHouse database?

The agent connects through a Model Context Protocol server or runs CLI tools via Bash. Vendor docs recommend placing a read-only database user in the MCP server connection string.

What happens if an agent runs a wildcard query on column-restricted tables?

ClickHouse blocks wildcard select queries when a user only has grants on specific columns. The query returns no data unless the table contains only the granted columns.

Can native ClickHouse grants redact emails inside a text column?

No, native select grants work at the table or column level, not inside text values. If a user can read a column, they receive all raw text stored there.

The query runs. The emails stay hidden.