AI and DevOps

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 -p starts 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 apply did not stop terraform -chdir=infra apply, but a PreToolUse hook that read the whole command blocked it.
  • A skill turns a runbook into a command: set disable-model-invocation for anything with side effects, and remember that allowed-tools grants 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

Claude Code's features that matter for DevOps, from Anthropic's documentation (11 November 2026)
FeatureWhat it doesOps useDocs page
Permission modesDecide which actions run without askingPlan mode for investigating, Manual for anything near productionPermission modes
Allow, ask and deny rulesPre-approve, force a prompt or block a tool or commandBlock reading .env, ask before sshConfigure permissions
HooksRun your command at points such as before each tool call; can block itRefuse infrastructure-changing commandsHooks reference
SandboxOS-level limits on files and network hosts for shell commandsInvestigate untrusted repositories safelySandboxing
SkillsSKILL.md instructions you run as /nameRunbooks: triage, release checksSkills
MCP serversGive Claude (opens in a new tab) new tools from other programsRead monitoring data, query a ticket systemMCP
PluginsPackage skills, agents, hooks and MCP servers as one unitShare the team's ops setupPlugins
Headless modeclaude -p for scripts and CIReview a diff, triage a failed jobRun Claude Code programmatically
GitHub Actions (opens in a new tab)anthropics/claude-code-action@v1 in workflows@claude on issues and pull requestsClaude 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

Claude Code's permission modes, as Anthropic describes them
ModeWhat 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
acceptEditsAccepts file edits and common filesystem commands in the working directory without asking
planReads files and explores, writes a plan, does not edit your source
autoA background classifier reviews actions instead of you
dontAskDenies every call that would otherwise prompt; pre-approved tools still run
bypassPermissionsSkips 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 -p and 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 set defaultMode in your settings, and an organisation can turn auto or bypass mode off with permissions.disableAutoMode or permissions.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 destroy and 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:

  • Read deny rules protect secrets. Read(./.env) stops Claude's file tools, and file commands Claude Code recognises in Bash such as cat and tail, 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 *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'.
  • Project allow rules wait for trust. permissions.allow rules in a committed .claude/settings.json apply only after each person trusts the folder; deny and ask rules apply at once. A claude -p run 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.mjs

We 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: true stops 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 /commit and /deploy: "You don't want Claude deciding to deploy because your code looks ready."
  • allowed-tools pre-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, use disallowed-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:

  • --allowedTools pre-approves specific tools, for example "Bash(git diff *),Bash(git log *)".
  • --permission-mode dontAsk denies everything that would otherwise prompt, which Anthropic calls "useful for locked-down CI runs".
  • --bare skips the hooks, skills, plugins, MCP servers and CLAUDE.md it would otherwise discover, so a run behaves the same on every machine. Without it, a -p run uses the project's hooks and .mcp.json servers 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

Key facts

FactValueSource
Rule evaluation orderdeny, then ask, then allow; the first match winsClaude Code, Configure permissions (opens in a new tab)Verified on
Starting permission modeauto 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 platformsmacOS, Linux and WSL2; on native Windows commands run unsandboxedClaude Code, Sandboxing (opens in a new tab)Verified on
Claude Code in paid plans20 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

  1. Claude Code, Configure permissions (opens in a new tab), Anthropic, accessed on
  2. Claude Code, Permission modes (opens in a new tab), Anthropic, accessed on
  3. Claude Code, Hooks reference (opens in a new tab), Anthropic, accessed on
  4. Claude Code, Sandboxing (opens in a new tab), Anthropic, accessed on
  5. Claude Code, Skills (opens in a new tab), Anthropic, accessed on
  6. Claude Code, Connect Claude Code to tools via MCP (opens in a new tab), Anthropic, accessed on
  7. Claude Code, Plugins overview (opens in a new tab), Anthropic, accessed on
  8. Claude Code, Settings files and precedence (opens in a new tab), Anthropic, accessed on
  9. Claude Code, Run Claude Code programmatically (opens in a new tab), Anthropic, accessed on
  10. Claude Code GitHub Actions (opens in a new tab), Anthropic, accessed on
  11. Claude Code, Security (opens in a new tab), Anthropic, accessed on
  12. Claude pricing (opens in a new tab), Anthropic, accessed on
Edit this article
  • 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.

    7 min read

  • 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.

    11 min read

  • 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.

    11 min read

Put OpsCrew to work on your app.

Run npx opscrew init in your app's repository. It checks your tools and tokens first, for free.