How to Configure Claude Code SQL Server Approval
You set up claude code sql server approval by pairing local agent prompts with read-only database roles. First, require user consent for shell commands and assign a restricted SQL Server user to the agent. Many teams start by giving their coding agent a broad database login. That approach creates big risks if the agent runs a bad query. A strong setup limits both what the agent can run and what the database allows. How claude code sql server approval works Claude Code reaches outside systems
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 sql server approval by pairing local agent prompts with read-only database roles. First, require user consent for shell commands and assign a restricted SQL Server user to the agent. Many teams start by giving their coding agent a broad database login. That approach creates big risks if the agent runs a bad query. A strong setup limits both what the agent can run and what the database allows.
How claude code sql server approval works
Claude Code reaches outside systems in two main ways. It can use the Model Context Protocol, known as MCP, to reach tools and databases. It can also run shell commands through its built-in Bash tool. In manual mode, the Bash tool asks for human approval before it runs most commands. Only a small set of safe, read-only shell commands run without a prompt.
When teams link Claude Code to a database through MCP, they pass a connection string. Vendor docs tell users to put a read-only database user in that string. This step makes sure the queries from the agent cannot change data. Users must also check and trust each MCP server before they link it.
How SQL Server logins and roles control the session
On the database side, SQL Server manages identity through logins and database users. A login lives in the master database and lets a person or agent reach many databases. A database user is the identity of that login inside one specific database. Teams can also create a contained database user with its own password for a single database. An admin must enable contained databases on the server and database first.
After you create the database user, you assign it to a fixed database role. You cannot change the permissions built into these fixed roles. The reader role lets the user read all data from all user tables and views. A deny-write role stops the user from adding, changing, or deleting any data. You should never give an agent the owner role. The owner role can change settings and even drop the whole database.
Claude Code Security + Approval Chains & Escalation: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native controls solve and what they miss
Combining local manual mode with a read-only SQL Server role solves two basic problems. First, the developer sees shell commands on their screen before the agent runs them. Second, the database blocks write statements if the agent only has the reader role. Even if the agent tries to delete a table, SQL Server rejects the query.
Still, native database roles only check who logs in at the start of a session. They do not inspect what individual queries do while they run. A read-only user can still read every table and view in the database. That includes tables with emails, phone numbers, card numbers, or national IDs. Also, local prompts only ask the developer who is running the agent. They do not ask a team lead or security owner to review risky queries. Finally, storing a database password in a local file leaves that secret on the developer machine.
Add runtime guardrails beside SQL Server
Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.
With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.
Frequently asked questions
Does Claude Code ask for approval before running database commands?
In manual mode, the Bash tool asks for approval before running non-basic shell commands. If you use an MCP server, query behavior depends on that server and your database user.
Which SQL Server role is safest for an AI coding agent?
Use the fixed reader role paired with the deny-write role for the agent database user. This setup lets the agent read user tables while blocking all data changes.
Can the fixed SQL Server reader role hide sensitive columns?
No, the fixed reader role grants read rights to all user tables and views. You cannot alter the permissions of a fixed role to hide specific columns like emails or card numbers.
Related guides
In this post