Claude Code for DevOps: skills, MCP and approvals
What Claude Code offers for operations work per Anthropic's docs (permission modes, rules, hooks, the sandbox, skills, MCP, plugins, CI), with a tested setup that stops it changing infrastructure and a read-only triage skill.
TL;DR
- Claude Code (opens in a new tab) is a general coding agent, but its controls make it usable for ops work: permission modes, allow, ask and deny rules, hooks that run before each tool call, an OS-level sandbox, skills, MCP servers, plugins and a headless mode for CI.
- Since v2.1.283 an interactive terminal session starts in auto mode, where a classifier reviews actions, and
claude -pstarts in Manual mode (v2.1.302 or later); Anthropic (opens in a new tab) says auto mode does not guarantee safety. - Deny rules match the command's text: in our test with Claude Code 2.1.316, a deny rule for
terraform applydid not stopterraform -chdir=infra apply, but aPreToolUsehook that read the whole command blocked it. - A skill turns a runbook into a command: set
disable-model-invocationfor anything with side effects, and remember thatallowed-toolsgrants permissions rather than restricting them.
On this page
Claude Code is a general coding agent, but it has the controls that operations work needs. Used with them, it is a capable DevOps assistant for a small team; used without them, it is a shell with your credentials. Below is each control from Anthropic's documentation, and a small setup we tested: rules and a hook that stop it from changing infrastructure, and a read-only triage skill.
It is part of the guide to AI DevOps agents for small teams. The documentation was read at code.claude.com on 11 November 2026, and the examples were run with Claude Code 2.1.316 that day. To get an app Claude Code built online, read Claude Code built your app. Here is how to put it online instead.
What Claude Code offers for DevOps work
| Feature | What it does | Ops use | Docs page |
|---|---|---|---|
| Permission modes | Decide which actions run without asking | Plan mode for investigating, Manual for anything near production | Permission modes |
| Allow, ask and deny rules | Pre-approve, force a prompt or block a tool or command | Block reading .env, ask before ssh | Configure permissions |
| Hooks | Run your command at points such as before each tool call; can block it | Refuse infrastructure-changing commands | Hooks reference |
| Sandbox | OS-level limits on files and network hosts for shell commands | Investigate untrusted repositories safely | Sandboxing |
| Skills | SKILL.md instructions you run as /name | Runbooks: triage, release checks | Skills |
| MCP servers | Give Claude (opens in a new tab) new tools from other programs | Read monitoring data, query a ticket system | MCP |
| Plugins | Package skills, agents, hooks and MCP servers as one unit | Share the team's ops setup | Plugins |
| Headless mode | claude -p for scripts and CI | Review a diff, triage a failed job | Run Claude Code programmatically |
| GitHub Actions (opens in a new tab) | anthropics/claude-code-action@v1 in workflows | @claude on issues and pull requests | Claude Code GitHub Actions |
Claude Code reads ~/.claude/settings.json (you, every project), .claude/settings.json (the project; commit it so teammates get it), .claude/settings.local.json (you, this project) and managed settings an organisation deploys, which override the rest. List settings such as permissions.allow merge across files instead of replacing each other.
Permission modes
| Mode | What it does |
|---|---|
default (Manual) | Asks before file edits and before shell commands outside a built-in read-only set such as ls, cat and git status |
acceptEdits | Accepts file edits and common filesystem commands in the working directory without asking |
plan | Reads files and explores, writes a plan, does not edit your source |
auto | A background classifier reviews actions instead of you |
dontAsk | Denies every call that would otherwise prompt; pre-approved tools still run |
bypassPermissions | Skips prompts except for a few actions no mode auto-approves |
Two facts matter for ops work:
- The starting mode. With Claude Code v2.1.283 or later, an interactive terminal or VS Code session starts in auto mode. From v2.1.302,
claude -pand the Agent SDK start in default (Manual), where any call that would need your approval is denied unless a rule, a hook or a flag approves it. You can setdefaultModein your settings, and an organisation can turn auto or bypass mode off withpermissions.disableAutoModeorpermissions.disableBypassPermissionsMode. - What auto mode is and is not. Its classifier blocks some actions by default, including production deploys and migrations, mass deletion on cloud storage, force pushes,
terraform destroyand granting IAM or repository permissions. Anthropic's own warning: "Auto mode reduces permission prompts but does not guarantee safety. Use it for tasks where you trust the general direction, not as a replacement for review on sensitive operations."
For bypassPermissions, Anthropic says to use it "only in isolated environments like containers, VMs, or dev containers without internet access, where Claude Code cannot damage your host system".
A practical split for a small team: plan mode when you ask "why is production slow?", so Claude reads and reports; Manual when the session can reach anything that matters; auto for local work on code you will review anyway.
Permission rules
Rules have the form Tool or Tool(specifier) and go in three lists: allow runs without asking, ask always prompts, deny blocks. Claude Code evaluates them in order, deny first, then ask, then allow, and the first match wins, so an allow rule cannot carve an exception out of a deny rule. MCP tools are matched as mcp__<server>__<tool>.
Three details are easy to miss:
Readdeny rules protect secrets.Read(./.env)stops Claude's file tools, and file commands Claude Code recognises in Bash such ascatandtail, from reading the file. It does not stop a script that opens the file itself.- Bash rules match text. Anthropic is explicit that a Bash rule "isn't a security boundary around the program":
Bash(rm *)stopsrm -rf build/but not/bin/rm -rf build/orbash -c 'rm -rf build/'. - Project allow rules wait for trust.
permissions.allowrules in a committed.claude/settings.jsonapply only after each person trusts the folder; deny and ask rules apply at once. Aclaude -prun never shows the trust dialog, so in a folder nobody has trusted these rules do not apply at all. We saw this in our headless test runs with Claude Code 2.1.316: its warning began "Ignoring 3 permissions.allow entries from .claude/settings.json: this workspace has not been trusted."
A tested setup: rules and a hook that refuse infrastructure changes
This setup keeps Claude Code from reading secret files and from applying infrastructure changes itself, while letting it format and validate infrastructure code. The idea is that changes go through a pull request and CI, as described in the safety article.
1. The rules
Save this as .claude/settings.json in your repository:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./**/*.tfstate)",
"Read(~/.ssh/**)",
"Read(~/.aws/**)",
"Bash(terraform apply *)",
"Bash(terraform destroy *)",
"Bash(tofu apply *)",
"Bash(tofu destroy *)"
],
"ask": ["Bash(ssh *)", "Bash(scp *)", "Bash(git push *)", "Bash(kubectl *)"],
"allow": ["Bash(terraform fmt *)", "Bash(terraform validate)", "Bash(docker compose config)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "node",
"args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/guard-infra.mjs"]
}
]
}
]
}
}The hook entry uses the exec form (command plus args), which Anthropic recommends for any hook that references a path placeholder: with no shell involved, the path needs no quoting on any platform. ${CLAUDE_PROJECT_DIR} is the project root where the session started.
2. The hook
A PreToolUse hook receives the tool call as JSON on stdin (the command is in tool_input.command); printing "permissionDecision": "deny" blocks the call and shows the reason to Claude. Save this as .claude/hooks/guard-infra.mjs:
// PreToolUse hook for Claude Code: refuses shell commands that change infrastructure.
// Claude Code passes the tool call as JSON on stdin; printing a "deny" decision blocks it.
import { readFileSync } from "node:fs";
const input = JSON.parse(readFileSync(0, "utf8"));
const command = String(input.tool_input?.command ?? "");
const changesInfrastructure = [
/\b(terraform|tofu)\b.*\b(apply|destroy|import|taint)\b/,
/\b(terraform|tofu)\b.*\bstate\s+(rm|mv|push)\b/,
/\bkubectl\b.*\b(apply|create|delete|drain|patch|replace|scale)\b/,
/\bhelm\b.*\b(install|upgrade|uninstall|rollback)\b/,
/\bdocker\b.*\b(system|volume|image|container)\s+prune\b/,
/\bdocker\s+compose\b.*\bdown\b.*(\s-v\b|--volumes)/,
/\b(hcloud|doctl)\b.*\b(delete|rebuild|reset)\b/,
];
if (changesInfrastructure.some((pattern) => pattern.test(command))) {
console.log(
JSON.stringify({
hookSpecificOutput: {
hookEventName: "PreToolUse",
permissionDecision: "deny",
permissionDecisionReason:
"This command changes infrastructure. Write the change as code and open a pull request; CI applies it after review.",
},
}),
);
}A hook that prints nothing has no decision, and the call goes on through the normal permission flow; Anthropic notes that "staying silent doesn't approve it". A deny from the hook blocks the call even when an allow rule matches it, so you could allow all Bash commands and block only these.
By default, a hook that fails (the script is missing, node is not on the PATH, the script crashes) is a non-blocking error, and the command runs. Adding "onFailure": "block" next to "args" (Claude Code v2.1.295 or later) makes a failed guard block the call instead. We did not use it in the runs below.
3. Test it without Claude
A destructive command prints a deny decision; a safe one prints nothing:
echo '{"tool_name":"Bash","tool_input":{"command":"tofu destroy"}}' | node .claude/hooks/guard-infra.mjs
echo '{"tool_name":"Bash","tool_input":{"command":"terraform plan"}}' | node .claude/hooks/guard-infra.mjsWe ran these commands through it in a node:22 container (Node.js (opens in a new tab) 22.23.4). It denied terraform -chdir=infra apply -auto-approve, terraform apply tfplan, /usr/bin/terraform apply, sh -c 'terraform apply', tofu destroy, kubectl -n prod delete deployment web, helm upgrade web ./chart, docker compose down -v, docker system prune -af and hcloud server delete web-1, and let through terraform plan -out=tfplan, terraform fmt -check, kubectl get pods, docker compose down (without -v), docker ps and git status.
4. What happened in a real session
We ran Claude Code 2.1.316 headless (claude -p) in a scratch repository with this setup, allowed the Bash tool on the command line so that only the hook stood in the way, and asked it to run terraform -chdir=infra apply -auto-approve. The command never ran: Claude Code refused the call and passed the hook's reason back to Claude.
In a second run, with the same rules and the same command-line allowance but without the hook, the deny rule Bash(terraform apply *) blocked terraform apply -auto-approve but did not match terraform -chdir=infra apply -auto-approve, because -chdir=infra sits between terraform and apply. That command went through to the shell and failed only because Terraform (opens in a new tab) was not installed where the test ran. The hook blocks both forms, because its pattern looks for apply anywhere after terraform in the whole command.
Warning
A hook like this is a guardrail, not a security boundary. It matches text, so a command written in a form it does not expect (a script that calls terraform for you, an alias, an encoded string) gets past it. For limits that do not depend on the command text, Anthropic's permissions page points to the sandbox, which covers file and network access. The boundary that holds best is the one around credentials: if the session has no token that can apply changes, no command can apply them.
The sandbox
Claude Code's sandbox is enforced by the operating system (Seatbelt on macOS, bubblewrap on Linux and WSL2) around the shell commands Claude runs. It is off by default; turn it on with /sandbox or sandbox.enabled in settings. By default sandboxed commands can write only to the working directory, a temp directory and folders you add, and they reach the network only through a local proxy whose allowed domains "start empty". Tools that ignore proxy settings, such as plain ssh and most database drivers, cannot connect at all.
Its limits, from the same page: it covers shell commands only, "Claude's file tools, MCP servers, and hooks run outside it"; reads are allowed on most of the machine, including ~/.ssh and ~/.aws/credentials, unless you deny them; and on native Windows commands run unsandboxed, so use WSL2 there. Set sandbox.failIfUnavailable to true if you want Claude Code to refuse to start rather than run without it, and allowUnsandboxedCommands to false to remove the escape hatch that retries a failing command outside the sandbox.
It is most useful when Claude reads things you do not control: a third-party repository, a vendor's install script, a web page.
Skills: runbooks as commands
A skill is a SKILL.md file with a short front matter and instructions, which Claude uses when relevant or you run with /skill-name. Project skills live in .claude/skills/<name>/SKILL.md, so the team shares them through Git. Two front matter fields matter for ops:
disable-model-invocation: truestops Claude from running the skill on its own. Anthropic recommends it for "workflows with side effects or that you want to control timing", such as/commitand/deploy: "You don't want Claude deciding to deploy because your code looks ready."allowed-toolspre-approves tools for the turn that runs the skill. It grants permissions; it "does not restrict which tools are available". To remove tools while a skill runs, usedisallowed-tools.
A read-only triage skill for a Docker (opens in a new tab) Compose app; save it as .claude/skills/triage/SKILL.md:
---
name: triage
description: Read-only first look at a failing Docker Compose app. Lists the containers, reads recent logs and checks disk space, then proposes a fix as a code change.
disable-model-invocation: true
allowed-tools: Bash(docker compose ps *) Bash(docker compose logs *) Bash(df -h)
---
Investigate without changing anything on this machine.
1. Run `docker compose ps --all` to see which services are running, restarting or exited.
2. For each service that is not running, run `docker compose logs --tail 50 <service>`.
3. Run `df -h` to check free disk space.
4. Report the most likely cause, quoting the log lines that show it.
5. Propose the fix as a change to files in this repository. Do not start, stop, restart, remove or rebuild anything.We tested it with Claude Code 2.1.316 on a Compose service built to fail at start (it printed Error: DATABASE_URL is not set and exited). claude -p "/triage" ran the three read-only commands, which the skill's allowed-tools approved, quoted the log line, pointed out that the service's command prints that error and exits every time and that no DATABASE_URL reaches the container, and proposed a change to compose.yaml without applying it.
Important
Anthropic's docs point out that workspace trust does not gate allowed-tools: a project skill's grants apply even in a claude -p run in a folder you never trusted. Review the skills in a repository you clone before you run Claude Code in it, as you would review its scripts.
MCP servers
The Model Context Protocol lets Claude Code use tools from other programs: your monitoring, your ticket system, a cloud API. You add a server with claude mcp add, at one of three scopes: local (the default, you in this project), project (a committed .mcp.json the team shares) or user (you, every project). In an interactive session Claude Code asks for approval before it uses servers from a project's .mcp.json; a -p session does not ask.
Three habits keep MCP safe:
- Trust the server first. Anthropic's advice is to write your own servers or use servers from providers you trust; it "does not security-audit or manage any MCP server", and servers that fetch external content can carry prompt injection.
- Prefer read-only tools. Allow the read tools of a server with rules such as
mcp__monitoring__query, and let the tools that change things prompt, or deny them. - Keep tokens out of the chat. Pass a server's credentials through its environment (
claude mcp add --env ...), not in a prompt.
Plugins
A plugin packages skills, agents, hooks and MCP servers as one installable unit, usually from a marketplace: the way to give a whole team the same ops setup. Anthropic's note applies to every plugin: "what the plugin runs, it runs as you". A plugin's hooks fire at their events and its MCP servers run alongside every session where it is enabled, so review a third-party plugin as you would any software you install.
Headless runs and CI
claude -p "prompt" runs Claude Code without the interactive interface, for scripts and CI. The options that matter:
--allowedToolspre-approves specific tools, for example"Bash(git diff *),Bash(git log *)".--permission-mode dontAskdenies everything that would otherwise prompt, which Anthropic calls "useful for locked-down CI runs".--bareskips the hooks, skills, plugins, MCP servers andCLAUDE.mdit would otherwise discover, so a run behaves the same on every machine. Without it, a-prun uses the project's hooks and.mcp.jsonservers even in a folder you never trusted. Note that bare mode also skips hooks you pass with--settings, so do not rely on a hook there.
In GitHub (opens in a new tab), anthropics/claude-code-action@v1 runs Claude Code in your workflows: it answers @claude in issues and pull requests, or runs a prompt or a skill on any event, including a schedule. Its documentation lists the guardrails: on issue and pull request events the person who triggers it must have write access to the repository, bot actors are rejected unless you allow them, and you should "grant the workflow only the permissions it needs, and review Claude's changes before merging". With Amazon Bedrock, Google Cloud (opens in a new tab)'s Agent Platform or Microsoft Foundry it authenticates through OpenID Connect, so no static cloud credentials are stored in the repository.
The job that runs Claude should not hold production credentials: let Claude write the pull request, and let a separate deploy job with its own secrets apply the merged result.
OpsCrew's Claude Code plugin
OpsCrew, the open-source tool this blog belongs to, ships a Claude Code plugin built on the same principles. Its MCP server gives Claude tools that never call a model, and every tool that changes something shows its plan, its hash and its cost in a dialog that Claude cannot answer for you; Claude Code also asks your permission before every such call, even in its auto modes. The read-only tools (opscrew_status, opscrew_logs, opscrew_advise) let Claude investigate a running app; tokens are read from the environment you start Claude Code in, and tool results never contain a token or a secret. The plugin's guide has the details, and Claude Code built your app shows how to install it.
Where to go next
- The risks this setup guards against: Is it safe to let AI run commands on your server?
- How Claude Code compares with agents built for operations: AI DevOps agents compared
- The whole picture for a small team: the guide to AI DevOps agents for small teams
Key facts
| Fact | Value | Source |
|---|---|---|
| Rule evaluation order | deny, then ask, then allow; the first match wins | Claude Code, Configure permissions (opens in a new tab)Verified on |
| Starting permission mode | auto in an interactive terminal or VS Code session (v2.1.283 or later); default (Manual) for claude -p (v2.1.302 or later) | Claude Code, Permission modes (opens in a new tab)Verified on |
| Sandbox platforms | macOS, Linux and WSL2; on native Windows commands run unsandboxed | Claude Code, Sandboxing (opens in a new tab)Verified on |
| Claude Code in paid plans | 20 USD per month (Pro, billed monthly)$17 a month billed annually; Max $100 and Ultra $200 a month also include Claude Code. Free does not. | Claude pricing (opens in a new tab)Verified on |
Frequently asked questions
Can Claude Code deploy to AWS?
It can run the AWS (opens in a new tab) CLI or Terraform if they are installed and logged in on your machine and you approve the commands. A safer pattern is that Claude Code writes the infrastructure code and the deploy workflow, and CI applies them with temporary credentials, for example through GitHub's OpenID Connect integration with AWS.
What is the difference between a skill, a hook and an MCP server?
A skill is instructions in a SKILL.md file that Claude follows when you run /skill-name or when it decides the skill applies. A hook is a command Claude Code itself runs at a point in its lifecycle, such as before each tool call, and it can block that call. An MCP server is a separate program that gives Claude new tools, such as access to an API.
Sources
- Claude Code, Configure permissions (opens in a new tab)
- Claude Code, Permission modes (opens in a new tab)
- Claude Code, Hooks reference (opens in a new tab)
- Claude Code, Sandboxing (opens in a new tab)
- Claude Code, Skills (opens in a new tab)
- Claude Code, Connect Claude Code to tools via MCP (opens in a new tab)
- Claude Code, Plugins overview (opens in a new tab)
- Claude Code, Settings files and precedence (opens in a new tab)
- Claude Code, Run Claude Code programmatically (opens in a new tab)
- Claude Code GitHub Actions (opens in a new tab)
- Claude Code, Security (opens in a new tab)
- Claude pricing (opens in a new tab)
Related articles
- Deploying
Claude Code built your app. Here is how to put it online
Can Claude Code deploy apps? It writes the code, the Dockerfile and the workflow, and can run deploy commands you approve, but it is not a host. The path from its code to a live URL on your own server.
- Deploying
A preview of every pull request, on your own server
What per-pull-request preview environments need on your own server, a tested do-it-yourself setup with Docker Compose, Caddy and GitHub Actions, and what OpsCrew's previews add.
- Security
Is your vibe-coded app ready for production? A checklist
An ordered checklist for taking an app built with Lovable, Bolt, Replit, v0, Cursor or Claude Code to production: secrets, database access, configuration, dependencies, the server, backups and monitoring.