How to Configure Claude Code CockroachDB Prevent Delete
To set up claude code cockroachdb prevent delete controls, you must assign a scoped database role to the agent. You also need to restrict how the coding agent runs shell commands on your machine. Many engineering teams start by giving the agent their own local database login. That approach creates high risk because broad roles allow the agent to drop rows or wipe tables by mistake. A safer setup removes delete permissions from the database user before the agent ever logs in. How to set up clau
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.
To set up claude code cockroachdb prevent delete controls, you must assign a scoped database role to the agent. You also need to restrict how the coding agent runs shell commands on your machine. Many engineering teams start by giving the agent their own local database login. That approach creates high risk because broad roles allow the agent to drop rows or wipe tables by mistake. A safer setup removes delete permissions from the database user before the agent ever logs in.
How to set up claude code cockroachdb prevent delete roles
Claude Code reaches external systems and databases through the Model Context Protocol, also known as MCP. Official docs state that MCP servers give the agent access to your tools, databases, and APIs. You can also let the agent run local shell commands through its built-in Bash tool. In both paths, the database login you provide sets the hard boundary for what the agent can do.
The vendor docs for database queries uses the DBHub MCP server with a database login string. Those docs advise teams to use a read-only database user in that login string. With a read-only role, the queries that Claude Code runs cannot change or remove your data. CockroachDB speaks the PostgreSQL wire protocol, so this exact role pattern works well here.
If your workflow requires the agent to add new records or update rows, a read-only user is too strict. Instead, you create a custom role inside CockroachDB for the coding agent. You grant that role permission to read tables and insert or update rows. You leave out permission to delete rows or drop tables. Then you place that scoped user into the MCP login string on the developer workstation. When the agent tries to run a delete statement, CockroachDB blocks the query at the database level.
Why local tool controls also matter for database safety
Setting up a scoped user in the MCP login string only covers one path into your cluster. Claude Code can also run terminal commands through its Bash tool. In Manual mode, the Bash tool asks for human approval before it runs most commands. Only a small built-in set of read-only file and git checks run without a prompt.
If a developer approves a shell command that calls a local database client, the agent might use another login stored on the laptop. If that local login has admin rights, the agent bypasses your safe MCP user. Teams must make sure that local shell profiles do not store admin database keys in plain text. You should also review every MCP server before you use it, just as the vendor docs warn.
Claude Code Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native CockroachDB roles solve the basic access problem well. They decide who can log in and which broad statement types a user can run. If a role lacks delete rights, no query from that login can remove rows from a table.
Still, static database roles leave an operational gap open during daily work. A role is an all-or-nothing switch for an entire session. It cannot inspect what an individual statement does in flight. For example, an agent with update rights can still overwrite every row in a table with blank values. A static role also cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs in query results. Also, putting long-lived database keys inside local MCP config files spreads secrets across developer laptops. When you need to allow a single safe delete or hide sensitive columns, static roles fall short.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.
First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
How does Claude Code talk to a CockroachDB database?
The agent connects through a Model Context Protocol server such as DBHub using a database login string. It can also run database CLI commands through its local Bash tool if a user approves them.
What is the safest user role to put in the MCP login string?
Official Claude Code docs recommends using a read-only database user in the login string. If the agent must write data, grant only select, insert, and update rights while leaving out delete rights.
Can a static CockroachDB role stop bad updates or hide sensitive data?
No, a database role only checks broad command types at login and execution time. It cannot block an update that wipes out column values, and it cannot rewrite emails or card numbers in results.
Related guides
In this post