How to Configure Claude Code CockroachDB Guardrails

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code cockroachdb guardrails by pairing read-only database roles with manual tool approvals. This stops the coding agent from changing tables or running unsafe shell commands. Many teams start by giving the agent a standard developer database string. That quick setup gives the agent the same write powers as a human engineer. If the model misreads a prompt, it can drop tables or alter live rows. A safe setup limits both how the agent connects and what privileges it holds. How t

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 cockroachdb guardrails by pairing read-only database roles with manual tool approvals. This stops the coding agent from changing tables or running unsafe shell commands. Many teams start by giving the agent a standard developer database string. That quick setup gives the agent the same write powers as a human engineer. If the model misreads a prompt, it can drop tables or alter live rows. A safe setup limits both how the agent connects and what privileges it holds.

How to set up claude code cockroachdb guardrails

Claude Code reaches external systems and databases through two main paths. The first path uses Model Context Protocol servers, also called MCP servers. MCP servers give Claude Code access to your tools, databases, and APIs. Because CockroachDB speaks the PostgreSQL wire protocol, teams use a database MCP server like DBHub. You pass a database string to the MCP server so the agent can query tables. The official docs advise using a read-only database user in that string. With a read-only user, the queries Claude runs cannot modify data. You also need to verify that you trust each MCP server before connecting it.

The second path uses the built-in Bash tool inside Claude Code. Through the Bash tool, the agent can launch database client commands from your shell. In Manual mode, the Bash tool needs your approval before running shell commands. Only a built-in set of read-only commands, like listing files or checking git status, skip this step. When you keep Manual mode active, you review every database command before it runs. Together, a read-only CockroachDB role and Manual mode form your baseline guardrails.

What native roles and tool prompts solve

A read-only CockroachDB role stops the agent from running write statements. The database engine blocks any attempt to insert, update, or delete rows. It also prevents the agent from dropping tables or changing schemas. Manual mode in the Bash tool adds a human check for local shell commands. You can spot an unsafe script before the agent sends it to your cluster.

Still, database roles and local prompts leave a big gap in daily operations. A database role only checks who logs in and which tables they can read. It does not inspect what individual queries do in flight. If the agent has read rights on a customer table, it can still fetch sensitive rows. A broad select query will pull raw emails, phone numbers, card numbers, and national IDs. The MCP server then sends those results straight into the model context.

Claude Code Security + AI Guardrails: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why static database strings create risk

Using a static database string in an MCP setup also creates key handling issues. Each developer must store a database password or key on their own machine. If a team shares one read-only account, database logs show every query under that single user. You cannot tell which engineer or agent session ran a specific query. Also, humans get tired of clicking approve on every single prompt in Manual mode. Over time, developers often approve commands fast without reading the full SQL query. Real safety requires controls that check every query and mask sensitive fields in results.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How does Claude Code query a CockroachDB cluster?

Claude Code queries databases through an MCP server like DBHub or via its Bash tool. Both methods use a database string to log in and run SQL queries.

Why should I use a read-only user for Claude Code?

A read-only database user ensures that queries from the agent cannot modify or delete your data. The database rejects any write or schema change commands right away.

Does a read-only CockroachDB role stop sensitive data leaks?

No, a read-only role still lets the agent read all columns in permitted tables by default. Without field masking, queries will return raw emails, phone numbers, and card numbers to the agent.

The query runs. The emails stay hidden.