Most "AI automation" demos collapse the second they touch a real repo: the agent edits files nobody reviews, and the workflow JSON was copied from a template whose node API changed two versions ago. The fix isn't a bigger model — it's treating agent rulesets and workflow templates as versioned artifacts with CI in front of them.

TL;DR: Claude Code is your build-time agent (policy in CLAUDE.md, guardrails in hooks). n8n is your run-time orchestrator (369 importable JSON graphs). Git is the contract between them. Wire a PostToolUse hook that lints every workflow JSON the agent writes, and template drift stops being a production incident.

The Problem With Current AI Workflows

Three failure modes I hit repeatedly:

  1. Credential IDs are instance-scoped. A downloaded n8n JSON references "id": "8f2a..." for an OpenAI credential that doesn't exist on your box. Import succeeds, execution fails at node 3, and the error is a generic 401.
  2. No idempotency. n8n retries a failed branch, the Telegram node fires twice, and your on-call channel gets duplicate alerts. Templates rarely ship dedupe keys.
  3. Unbounded agents. A coding agent with Bash access and no PreToolUse policy will eventually run something destructive in a directory you cared about. "Be careful" in a prompt is not a control plane.

The community repos below solve the inventory problem. You still have to supply the governance.

How the Architecture Actually Works

 ┌────────────────────────────────────────┐ git ──►│ Claude Code (BUILD TIME) │ │ CLAUDE.md → repo policy │ │ .claude/commands/*.md→ slash commands │ │ .claude/skills/*/ → agent skills │ │ hooks: PreToolUse / PostToolUse │ └───────────────┬────────────────────────┘ │ writes / edits ▼ workflows/*.json src/ tests/ │ CI: jq lint → import → smoke run ▼ ┌────────────────────────────────────────┐ │ n8n (RUN TIME, self-hosted) │ │ Webhook / Cron / Telegram trigger │ │ → HTTP / pgvector / LLM chain │ │ → Execute Command (task runner) │ └───────────────┬────────────────────────┘ │ claude -p (headless) └──► branch + PR back into git 

Component breakdown:

  • Rulesets (CLAUDE.md + .claude/commands/) encode how this repo works: node naming, required error branches, which model IDs are allowed. Deterministic, reviewable, diffable.
  • Hooks are the enforcement layer. They receive JSON on stdin and can block a tool call with exit code 2, feeding stderr back to the model. This is a real gate, not a suggestion.
  • Workflow JSON is the deployable unit. Treat workflows/ like migrations/ — append-only, reviewed, imported by CI.
  • n8n owns scheduling, retries, and fan-out. It should not own business logic; push that into code the agent can test.

Quick Start (Copy-Paste Setup)

git clone https://github.com/hesreallyhim/awesome-claude-code ~/ref/acc git clone https://github.com/enescingoz/awesome-n8n-templates ~/ref/n8n mkdir -p .claude/hooks workflows && cd "$_" 

.claude/hooks/validate-workflow.sh — blocks malformed graphs at write time:

#!/usr/bin/env bash payload=$(cat) path=$(jq -r '.tool_input.file_path // empty' <<<"$payload") case "$path" in */workflows/*.json) jq -e '.nodes | all(.type and .typeVersion and .id)' "$path" >/dev/null || { echo "node missing type/typeVersion/id in $path" >&2; exit 2; } jq -e '[.nodes[].type] | all(startswith("n8n-nodes-base.") or startswith("@n8n/") or startswith("n8n-nodes-langchain."))' "$path" >/dev/null || { echo "unknown node namespace — declare community nodes first" >&2; exit 2; } ;; esac 

.claude/settings.json:

{ "hooks": { "PostToolUse": [ { "matcher": "Edit|Write|MultiEdit", "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate-workflow.sh" }] } ] } } 

A slash command that ports templates instead of blindly importing them (.claude/commands/port-workflow.md):

--- description: "Port an n8n template into this repo's conventions" allowed-tools: Read, Write, Bash(jq:*) argument-hint: <path-to-template.json> --- Read $ARGUMENTS. Strip all `credentials` blocks and `id` fields. Rename nodes to `<verb>_<noun>`. Add an error branch to every HTTP node. Write to workflows/ and print a list of credentials I must create manually. 

Runtime:

docker run -d --name n8n -p 5678:5678 \ -e N8N_ENCRYPTION_KEY="$(openssl rand -hex 24)" \ -e EXECUTIONS_DATA_PRUNE=true -e EXECUTIONS_DATA_MAX_AGE=168 \ -e N8N_RUNNERS_ENABLED=true \ -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n docker cp workflows n8n:/tmp/workflows docker exec n8n sh -c 'for f in /tmp/workflows/*.json; do n8n import:workflow --input="$f"; done' 

Persist that encryption key. Lose it and every stored credential is unrecoverable.

Real-World Use Cases & Honest Trade-Offs

Win 1 — Telegram ops bot with dedupe. Port a Telegram template, insert a Redis SETNX on message_id before the LLM node. Duplicate webhook deliveries become no-ops instead of duplicate token spend.

Win 2 — Scrape → chunk → pgvector RAG. The scraping templates give you the fetch/parse skeleton. Add a content-hash column and upsert on hash; re-running the crawl skips re-embedding unchanged pages. On a 4k-page corpus that's the difference between a $12 and a $0.40 nightly job.

Win 3 — Headless triage loop. A cron workflow queries failed executions, then an Execute Command node runs claude -p "diagnose these stack traces, patch src/, open a branch" inside a sandboxed runner with --allowedTools scoped to Read/Edit/Bash(git:*). You wake up to a PR, not a pager.

Limitation 1 — Template drift is real. A meaningful slice of the 369 workflows pin older typeVersion values or reference community nodes you haven't installed. Budget 15–30 minutes of porting per template. The PostToolUse lint catches structure, not semantics — it won't tell you a node's parameter schema changed.

Limitation 2 — Licensing and blast radius. n8n ships under the Sustainable Use License (fair-code, source-available, not OSI open source) — read it before you resell hosted automation. And a headless agent invoked from a workflow inherits that workflow's trigger surface: an unauthenticated webhook that reaches an Execute Command node is remote code execution. Put auth on the webhook, run the runner unprivileged, and never mount your real repo read-write.

📡 Daily drops: I post one open-source AI find per day on VibeNode AI — Claude Code hooks, slash commands, and ready-to-import n8n JSON, with the porting notes attached. Search #Drop01 in the channel to start from the first one.

Direct Links & Daily Open-Source Drops

Where do you draw the line? Do you let Claude Code own the entire n8n graph JSON, or restrict it to node-level code and keep the wiring hand-authored? I've gone back and forth — curious what's holding up in your production repos.