Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST
AI Tools
Claude Code

Why Our Claude Code Agent Almost Ran rm -rf in CI (And How We Locked It Down)

Learn to wire CLAUDE.md, slash commands, hooks, subagents and MCP permissions so Claude Code stays safe in unattended runs.

MCB Editorial
MCB Editorial
Tech Buzz Daily Desk · 10 min read ·
5(1)
Why Our Claude Code Agent Almost Ran rm -rf in CI (And How We Locked It Down)
Narrated by Study Buddy Narration
Voiceover Engine • Interactive Audio Sync
0:0010:00

Learning Objectives & Key Takeaways

0 / 4 Completed
🚀 Architecture Ready
100%
What you will learn
  1. CLAUDE.md shapes behavior but never enforces a boundary; only permissions and hooks do that.
  2. PreToolUse hooks run before every permission prompt except EndConversation and can deny calls outright.
  3. In promptless or background sessions, an undecided hook call is denied by default, not allowed.
  4. Deny rules beat allow rules every time, even under bypassPermissions mode.
  5. Scope MCP access narrowly per subagent instead of granting the mcp__* wildcard to everyone.

The 2 AM Incident: A Background Agent and a Missing Deny Rule

A platform team had a nightly subagent cleaning stale build caches across a monorepo, running non-interactively from a cron job with the Bash tool broadly allowed and nothing in the deny list.

One night a shell variable resolved empty before expansion, turning a scoped rm -rf $BUILD_DIR/* into something far wider, and because the session was running unattended there was no permission prompt for a human to catch on the way past.

In the rest of this story
  1. The Configuration Stack, In the Order Claude Code Expects
  2. CLAUDE.md and Slash Commands: Guidance the Model Reads, Not a Fence
  3. Hooks: The Only Thing That Still Runs When Nobody Is Watching
  4. A Locked-Down Subagent, Its Hook, and Its Narrow MCP Access
  5. MCP Servers and Permission Order: Deny, Then Ask, Then Allow
1 code example · 10 min read in full
Member-only story

Checking your membership…

Members read every Tech Buzz story in full, with code examples, audio and the discussion, plus every course, quiz and interview set in the Learning Dashboard.

0
MCB Editorial
Written By

MCB Editorial

Tech Buzz Daily Desk. Contributing deep-dive engineering architectures, cloud paradigms, and system design insights to Master Class Buddy.