Claude Code bei WordPress-Wartung: Regeln und Hooks schützen Live-Seiten
I do WordPress maintenance work for clients — the unglamorous kind: plugin updates on live sites, layout breakage after someone else's update, server migrations that have to happen without taking the contact form (or the mail server) down with them. For the past few months I've been doing a lot of

Ich mache WordPress-Wartung für Kunden, die unglamouröse Art: Plugin-Updates auf Live-Seiten, zerschossene Layouts, nachdem jemand anderes etwas aktualisiert hat, Servermigrationen, die stattfinden müssen, ohne das Kontaktformular oder den Mailserver mit in den Abgrund zu reißen.
In den vergangenen Monaten habe ich viel dieser Arbeit mit Claude Code neben mir erledigt. Es ist tatsächlich gut in der Untersuchungsseite der Wartung: Fehlerprotokolle lesen, nachvollziehen, welches Plugin-Update zeitlich mit einer Layoutänderung zusammenfällt, ein Site-Inventar vor einer Migration erstellen. Aber Wartung hat eine Eigenschaft, die Greenfield-Entwicklung nicht hat: Die Seite ist bereits live, bringt bereits Geld für den Kunden ein, und das schlechteste Ergebnis ist nicht "der Code ist hässlich", sondern "die Seite ist down und der Kunde hat es vor mir erfahren".
Bevor ich also einen KI-Agenten diese Art von Arbeit anfassen lasse, wollte ich zwei Schutzebenen:
Dieser Beitrag handelt davon, wie ich beide eingerichtet habe. Alles im Folgenden ist die tatsächliche Konfiguration, mit der ich arbeite.
Claude Code liest beim Start einer Sitzung eine Datei namens CLAUDE.md im Projektordner. Für ein Wartungsprojekt ist meine um eine Idee herum aufgebaut: Die Regeln für eine bestehende Live-Site drehen sich hauptsächlich darum, nichts zu beschädigen. Die Abschnitte, die sich bewähren:
Nicht verhandelbare Grundregeln. Die Regeln, die ich niemals mitten in einer Sitzung wegverhandelt haben möchte:
Eine Reihenfolge zur Störungsanalyse. Wenn etwas kaputt ist, fängt ein Agent, der improvisieren darf, oft an, Dinge zu ändern. Stattdessen gebe ich ihm eine feste Reihenfolge vor: zuerst die Fehlerprotokolle lesen (PHP-Fehler, das Protokoll des Hosters, wp-content/debug.log), das Timing mit den letzten Änderungen abgleichen, verdächtige Plugins beginnend mit denen mit der geringsten Auswirkung isolieren, feststellen, ob der Fehler im Theme oder auf Serverseite liegt, und erst dann eine Lösung vorschlagen. Ursache und Belege melden, bevor irgendetwas repariert wird.
Berichtsformat. Jede Sitzung endet mit einem Arbeitsprotokoll: was geändert wurde, warum, was bewusst nicht geändert wurde (Updates, die ich zurückgestellt habe, und warum), und Hinweise, die an das nächste Mal weitergetragen werden. Der letzte Teil, die bewussten Nicht-Änderungen, hat sich am meisten für das Kundenvertrauen als wichtig erwiesen.
Ein ehrlicher Vorbehalt: CLAUDE.md wirkt über Anweisungen, nicht über Zwang. Es ist ein kräftiger Anstoß, keine Garantie. Deshalb existiert Ebene 2.
Claude Code unterstützt Hooks, also Shell-Befehle, die an definierten Punkten ausgeführt werden. Ein PreToolUse-Hook feuert, bevor ein Werkzeug ausgeführt wird, und wenn das Hook-Skript mit Exit-Code 2 endet, wird die Operation blockiert und die Standardfehlerausgabe des Skripts wird Claude als Rückmeldung angezeigt.
Hier ist der Hook, mit dem ich verhindere, dass datenvernichtende Befehle innerhalb einer Sitzung jemals ausgeführt werden. Er liest das JSON, das Claude Code über stdin übergibt, extrahiert den Bash-Befehl, der gerade ausgeführt werden soll, und blockiert die Muster, die ich niemals unbeaufsichtigt ausgeführt haben möchte:
#!/usr/bin/env bash # PreToolUse-Hook: stoppt irreversible Bash-Befehle, bevor sie laufen. # Voraussetzung: jq set -euo pipefail input = $( cat ) command = $( printf '%s' "$input" | jq -r '.tool_input.command // empty' ) case "$command" in * "rm -rf" * | * "wp db reset" * | * "wp site empty" * | * "DROP TABLE" * | * "DROP DATABASE" * | * "wp db drop" * ) echo "Vom Hook blockiert (datenvernichtende Operation): ${command}" >& 2 echo "Falls das wirklich nötig ist, prüfe zuerst Ziel und Wirkungsradius und führe es dann manuell aus." >& 2 exit 2;; esac exit 0 Vollbildmodus öffnen Vollbildmodus schließen Und die zugehörige.claude/settings.json, die alles verdrahtet, plus eine Permission-Deny-Liste als zweites Netz:
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-bash.sh" } ] } ] }, "permissions": { "deny": [ "Edit(./wp-config.php)", "Write(./wp-config.php)", "Bash(rm -rf *)", "Bash(wp db reset *)", "Bash(wp site empty *)" ] } } Vollbildmodus öffnen Vollbildmodus schließen (Nicht vergessen, dem Hook-Skript chmod +x zu geben, sonst läuft es stillschweigend gar nicht.)
Zwei Details, die sich zu übernehmen lohnen, wenn man das adaptiert:
Ein zweiter Hook führt über einen PostToolUse-Hook immer dann php -l aus, wenn eine PHP-Datei bearbeitet wurde, sodass ein Syntaxfehler in der Sitzung auftaucht statt auf dem Staging-Server. Gleiches Muster, kleinerer Nutzen, aber trotzdem lohnend.
Das andere, was ich am Ende formalisiert habe, sind Verfahren, also die Prüfungen, die jedes Mal in derselben Reihenfolge stattfinden müssen. In Claude Code existieren diese als Skills, ein Ordner unter.claude/skills/ mit einer SKILL.md, die das Verfahren beschreibt und zum Beispiel über /wp-migration-precheck aufgerufen wird.
Meiner meistgenutzter Skill ist die Prüfung vor der Migration. Migrationszwischenfälle entstehen fast immer daraus, dass am Umzugstag zutage tritt, dass niemand von einer Einstellung wusste. Der Skill durchläuft daher ein festes Inventar: Versionen und Größen, Theme- und Plugin-Liste und welche Plugins serverabhängig sind, DNS und SSL, und, das, worüber Menschen stolpern, wohin die MX-Einträge zeigen. Wenn E-Mail auf derselben Domain läuft und man die Seite achtlos umzieht, kann man die E-Mail des Kunden gleich mit abschalten. Alles, was sich nicht bestätigen lässt, wird als "unbestätigt" markiert statt geraten, denn ein Angebot auf Basis von Vermutungen ist der Grund, warum Migrationsprojekte Geld verlieren.
Ähnliche Skills habe ich für die Analyse zerschossener Layouts, ein Nur-Lese-Sicherheitsaudit und die Backup-Verifikation, also die Prüfung, ob das Backup eine echte, wiederherstellbare Datei ist und nicht nur ein Plugin behauptet, "aktiviert" zu sein.
Ich habe die vollständige Konfiguration, die CLAUDE.md-Vorlagen (Wartung, Theme-Entwicklung, Plugin-Entwicklung plus eine für Google-Apps-Script-Projekte), fünf Skills, Checklisten sowie die oben genannten Settings und Hooks, als Kit namens Claude Code × WordPress / GAS Field Kit gepackt. Es gibt es auf Gumroad für 29 US-Dollar, und das Hook-Skript sowie die Wartungs-CLAUDE.md-Vorlage sind als kostenlose Probe verfügbar, falls man erst hineinschauen möchte, bevor man irgendetwas entscheidet:
Zur vollständigen Transparenz: Ich habe das Kit erstellt und verkaufe es. Alles in diesem Artikel, der Hook, die Settings, die Regeln, ist für sich genommen vollständig; das Kit ist nur der Rest der Vorlagen und Verfahren an einem Ort.
Ich wäre daran interessiert, wie andere das Problem "Agent auf einer Produktivsite" angehen, insbesondere, was ihr in die Kategorie mechanisch blockiert versus die Kategorie bitte nicht gesteckt habt.
Hinweis: Dieser Beitrag wurde mit KI-Unterstützung entworfen und vor der Veröffentlichung von mir überprüft und redigiert, gemäß den Richtlinien von DEV für KI-unterstützte Artikel.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
I do WordPress maintenance work for clients — the unglamorous kind: plugin updates on live sites, layout breakage after someone else's update, server migrations that have to happen without taking the contact form (or the mail server) down with them.
For the past few months I've been doing a lot of this work with Claude Code open next to me. It's genuinely good at the investigation side of maintenance: reading error logs, tracing which plugin update coincided with a layout change, inventorying a site before a migration. But maintenance has a property that greenfield development doesn't — the site is already live, already making the client money, and the worst outcome isn't "the code is ugly," it's "the site is down and the client found out before I did."
So before I let an AI agent touch that kind of work, I wanted two layers of protection:
This post is about how I set up both. Everything below is the actual configuration I work with.
Claude Code reads a CLAUDE.md file in your project folder at the start of a session. For a maintenance project, mine is built around one idea: the rules for an existing live site are mostly about not breaking things. The sections that earn their keep:
Non-negotiables. The rules I never want negotiated away mid-session:
An incident triage order. When something is broken, an agent left to improvise will often start changing things. I give it a fixed order instead: read the error logs first (PHP errors, the host's log, wp-content/debug.log ), line the timing up against recent changes, isolate suspect plugins starting with the lowest-impact ones, determine whether the fault is in the theme or on the server side — and only then propose a fix. Report the cause and the evidence before fixing.
Reporting format. Every session ends with a work log: what changed, why, what was deliberately not changed (updates I decided to hold, and why), and watch-outs carried over to next time. That last part — the deliberate non-changes — turned out to matter most for client trust.
One honest caveat: CLAUDE.md works by instruction, not enforcement. It's a strong nudge, not a guarantee. Which is why layer 2 exists.
Claude Code supports hooks — shell commands that run at defined points. A PreToolUse hook fires before a tool executes, and if the hook script exits with code 2, the operation is blocked and the script's stderr is shown to Claude as feedback.
Here is the hook I use to keep data-destroying commands from ever running inside a session. It reads the JSON Claude Code passes on stdin, pulls out the Bash command that's about to run, and blocks the patterns I never want executed unattended:
#!/usr/bin/env bash # PreToolUse hook: stop irreversible Bash commands before they run. # Requires: jq set -euo pipefail input = $( cat ) command = $( printf '%s' "$input" | jq -r '.tool_input.command // empty' ) case "$command" in * "rm -rf" * | * "wp db reset" * | * "wp site empty" * | * "DROP TABLE" * | * "DROP DATABASE" * | * "wp db drop" * ) echo "Blocked by hook (data-destroying operation): ${command}" >& 2 echo "If this is really needed, review the target and the blast radius first, then run it manually." >& 2 exit 2;; esac exit 0 Enter fullscreen mode Exit fullscreen mode And the matching.claude/settings.json that wires it up, plus a permission deny list as a second net:
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-bash.sh" } ] } ] }, "permissions": { "deny": [ "Edit(./wp-config.php)", "Write(./wp-config.php)", "Bash(rm -rf *)", "Bash(wp db reset *)", "Bash(wp site empty *)" ] } } Enter fullscreen mode Exit fullscreen mode (Don't forget chmod +x on the hook script, or it silently won't run.)
Two details worth copying if you adapt this:
A second hook runs php -l via a PostToolUse hook whenever a PHP file is edited, so a syntax error surfaces in the session instead of on the staging server. Same pattern, smaller payoff, still worth it.
The other thing I ended up formalizing is procedures — the checks that have to happen in the same order every time. In Claude Code these live as skills (a folder under.claude/skills/ with a SKILL.md describing the procedure, invoked like /wp-migration-precheck ).
My most-used one is the pre-migration check. Migration incidents almost always come from "we had no idea that setting existed" surfacing on moving day, so the skill walks a fixed inventory: versions and sizes, theme/plugin list and which plugins are server-dependent, DNS and SSL — and, the one that bites people, where the MX records point. If mail runs on the same domain and you move the site carelessly, you can take the client's email down along with it. Anything that can't be confirmed gets marked "unconfirmed" rather than guessed, because a quote built on guesses is how migrations lose money.
I have similar skills for layout-breakage triage, a read-only security audit, and backup verification (checking the backup is a real, restorable file — not just that a plugin says "enabled").
I've packaged the full configuration — the CLAUDE.md templates (maintenance, theme dev, plugin dev, plus one for Google Apps Script projects), five skills, checklists, and the settings/hooks above — as a kit called the Claude Code × WordPress / GAS Field Kit. It's on Gumroad for $29, and the hook script and maintenance CLAUDE.md template are available as a free sample if you want to look before deciding anything:
Full disclosure: I made the kit and I sell it. Everything in this article — the hook, the settings, the rules — is complete on its own; the kit is just the rest of the templates and procedures in one place.
I'd be interested in how others are handling the "agent on a production site" problem — especially what you've put in the mechanically-blocked category versus the please-don't category.
Disclosure: this article was drafted with AI assistance and reviewed/edited by me before posting, per DEV's AI-assisted article guidelines.