DEV Community

Muhammad Mairaj
Muhammad Mairaj

Posted on Edited on Originally published at Medium AI-assisted

A brake for Claude Code on Azure: ask before anything that costs money

An AI agent can create a billable Azure resource in one line. The only brake most setups have is you, reading every command before it runs, every time, forever.

I stopped trusting that brake the day it worked exactly as designed.

The approval was a conversation, not a control

I was measuring the small file problem on disk and in Azure. The Azure half needed a storage account, so Claude Code and I talked through a cost plan first. I said yes in chat. Then it created a resource group and a storage account.

Nothing went wrong. That's the uncomfortable part. My "yes" was a sentence in a conversation. Nothing in the tooling connected that sentence to the commands that followed. If the plan had drifted, a bigger SKU, a second account, a cluster instead of a bucket, the same sentence would have covered it.

hand pressing a red button sort of like a emergency brake
Photo by fsefefs sefesfesfesf on Unsplash

The bill arrives after the damage

The usual answer is "set a budget alert." A budget alert is an email. It doesn't stop anything, and it can only react to usage data Azure has already posted.

I checked how fast that data shows up. Hours after my test, the subscription's usage records still had rows for other resources and nothing for the storage account I'd just used. So the earliest warning you can get is late by design: the meter runs now, the record shows up later, the alert after that.

For an agent that types faster than you read, that order is backwards. The check has to happen before the command, not after the invoice.

What az-brake does

az-brake is a Claude Code plugin with one job: when Claude is about to run an Azure CLI command that creates or starts something that costs money, it stops and asks you.

It's a PreToolUse hook. Claude Code calls it before every shell command. If the command looks billable, the hook answers "ask", and Claude Code shows its normal approval prompt. The prompt names what it can see:

  • the kind of resource being created,
  • its --name,
  • the size, SKU and location flags, if the command has them.

In a chained command (a && b && c), every billable step is listed, not just the first.

It never shows a price. The hook can't see your rates, discounts or reservations, and a wrong number in a safety prompt is worse than no number.

What it asks about, and what it lets through

Billable creates: about 50 resource types. Virtual machines and scale sets, disks, storage accounts, AKS clusters and node pools, SQL databases, PostgreSQL and MySQL flexible servers, Cosmos DB, Redis, web and function apps, Databricks workspaces, Log Analytics, public IPs, gateways and load balancers, and more.

It also asks before anything that starts, resumes, scales or resizes one of those, and before commands that can create anything at all: deployments, az stack create, az resource create, az rest --method put. For those, the prompt says plainly that it can't see what the template contains. A --what-if run passes, because it only previews.

Everything else runs without a prompt: reads, list, show, deletes, az login, resource groups, virtual networks. az group create and az sql server create pass too, because they're free on their own.

That list of "lets through" matters as much as the other one. A hook that asks too often gets switched off. The whole design is about asking rarely enough that you still read the prompt.

It fails open, on purpose

Any error inside the hook means the command runs.

That sounds backwards for a safety tool, so here's the reasoning. A brake that jams is worse than a soft one. If a bug in my parser blocked your deploy at 2 am, you'd uninstall it by 2:05, and then you'd have no brake at all.

It's also a speed bump, not a security boundary. It reads command text, so it catches well-known shapes. It doesn't read bash -c "az vm create ...", Terraform, the portal, or anything you type yourself. It's there to catch an agent's honest mistakes, not a determined attacker.

How I tested it

  • 95 unit cases, run straight against the TypeScript source.
  • Every command path checked against the real CLI. I ran az <path> -h for each one on the installed Azure CLI. Ten of those paths turned out to live in CLI extensions, the kind Azure offers to install the first time you use them. A table written from memory would have been wrong about those.
  • Live headless runs. I ran Claude Code headless (claude -p) in dontAsk and bypassPermissions modes and gave it an az storage account create command. The hook stopped it both times. The command pointed at a resource group that doesn't exist, so even a miss couldn't have created anything. A free command (az group exists) went straight through.

Headless mode can't answer a prompt, so those runs prove the hook fires and the command doesn't run. They don't prove the interactive dialog.

Not verified yet

  • The interactive approval dialog itself: approving a flagged command and watching it run.
  • The PowerShell path, and machines without Git Bash.
  • macOS and Linux. I built and tested it on Windows only.

I'd rather list these than let you assume them.

Install

/plugin install az-brake --marketplace thisismairaj/az-brake
Enter fullscreen mode Exit fullscreen mode

Nothing to configure. It needs Node 20 or newer on your PATH. The code is on GitHub and on npm as az-brake.

If you want the longer story of how Azure and its neighbours meter you in the first place, I wrote up what Databricks and Snowflake actually charge you for. The short version is the same lesson: the meter is always running before the report is.

Your agent can type az vm create faster than you can read it. Make it ask first.

Top comments (0)