How to Configure Claude Code ClickHouse Audit Log
You set up a claude code clickhouse audit log by giving the agent its own database user. Then you track every query that user runs inside the database system tables. Many teams start by giving AI coding agents a shared admin user for speed. That wide role lets the agent read sensitive columns or drop whole tables by mistake. A dedicated role stops unwanted writes and ties every query to the AI agent. How to set up a claude code clickhouse audit log Claude Code reaches outside systems through
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 a claude code clickhouse audit log by giving the agent its own database user. Then you track every query that user runs inside the database system tables. Many teams start by giving AI coding agents a shared admin user for speed. That wide role lets the agent read sensitive columns or drop whole tables by mistake. A dedicated role stops unwanted writes and ties every query to the AI agent.
How to set up a claude code clickhouse audit log
Claude Code reaches outside systems through Model Context Protocol servers or its local shell tool. Both paths need a database connection string with a username and password. Vendor guides say you should use a read-only database user in this string. That rule ensures the queries Claude Code runs cannot change or delete your data.
ClickHouse manages users, roles, row policies, settings profiles, and quotas through SQL access control. To turn this on, an admin sets a storage directory in the server settings. You also need at least one admin user with access management turned on. Once active, an admin with the right privilege can create a new user for the agent. Remember that a user can only grant privileges that they hold themselves.
When you create the agent user, you set its login method and allowed client hosts. You also attach default roles and specific user settings to that account. For tight security, grant read access only on specific columns instead of whole tables. If the agent runs a query on other columns, the database blocks the request. A wildcard query on all columns also fails unless the user owns every column.
What native roles solve and what they miss
Giving the agent its own ClickHouse user solves the basic tracking problem right away. Every query the agent sends logs under that specific username in the database. Your security team can check the query history to see when the agent ran a statement. Column grants also keep the agent away from tables it should never touch.
Still, native database setup only decides who logs in and which columns they can read. It does not check what individual queries return in flight before data reaches the agent. If an allowed column holds emails, phone numbers, or card numbers, the agent reads them. Those raw values then travel back into the model prompt context. Also, the connection string still holds a static password on the developer machine.
Claude Code Security + Audit Log Integrity: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Why static credentials and raw results create risk
When you put a database user password in a local file, anyone on that laptop can read it. If a developer runs Claude Code through the shell tool, manual approval helps catch bad commands. Yet once you approve a database call, the database returns every matching row in full. Column grants are all or nothing for each column you open up.
You might need the agent to check a support table to fix a bug. That table often mixes safe metadata with customer emails or national IDs in the same column. Native grants cannot rewrite matched fields in results on the fly. Teams need a way to mask sensitive fields and tie each agent query to a human user.
Check ClickHouse queries and result columns on the wire
ClickHouse users and row policies decide who connects. They do not check each statement on the wire or redact sensitive string columns in query results. With hoop.dev, you run an open-source proxy, a sidecar for your ClickHouse, inline in ClickHouse's native TCP protocol. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Multi-statement queries and table mutations are split and checked by hoop.dev guardrails, which refuse banned actions with a native ClickHouse error or hold risky ones for approval. On returned rows, hoop.dev data masking rewrites String and FixedString columns in memory, and the audit trail logs each query and verdict. See the MIT-licensed source on GitHub.
Frequently asked questions
How does Claude Code connect to a ClickHouse database?
Claude Code reaches databases through Model Context Protocol servers or by running commands in its shell tool. Both methods use a database connection string that should point to a read-only user.
Can ClickHouse restrict an AI agent to specific columns?
Yes, ClickHouse lets you grant read access on specific columns of a table to a user. If the agent queries ungranted columns or runs a full wildcard select, the query fails.
Why is a separate database user needed for an AI audit log?
If the agent shares a login with a developer, all queries look the same in the log. A dedicated user lets you filter the query log to see only what the agent ran.
Related guides
In this post