Two Tools, One Missing Piece Each

n8n knows when things should happen. Cron schedules, webhooks, Slack messages, email triggers — it's a workflow automator that watches the world and reacts. But it can't think. It runs predefined steps.

Claude Code knows how to think. It reads codebases, analyzes logs, writes fixes, reasons about problems. But it just sits there in a terminal waiting for you to type something. No triggers, no scheduling, no awareness of the outside world.

SSH is the bridge.

n8n's built-in SSH node connects to whatever machine runs Claude Code. Send a prompt, get a response. Here's what that looks like in practice:

  1. Someone posts in Slack: "why is prod slow?"
  2. n8n catches the message via webhook
  3. n8n SSHs into your server and runs: claude -p "Check the nginx and app logs from the last hour. What's causing high latency?"
  4. Claude Code reads the logs, reasons about them, responds with a diagnosis
  5. n8n takes that response and posts it back to Slack

No human in the loop. No copy-pasting between terminals. The automator triggers the thinker, and the thinker does what it does best.

What You Need

  • A self-hosted n8n instance — Docker on any Linux machine you own
  • An AI terminal tool — Claude Code, Gemini CLI, or OpenAI Codex CLI
  • SSH access between the n8n host and the machine running the AI tool

Self-Hosting n8n

If you have a home server, a Raspberry Pi, or any Linux box with Docker:

mkdir -p ~/n8n-data
docker run -d --restart unless-stopped \
  --name n8n \
  -p 5678:5678 \
  -v ~/n8n-data:/home/node/.n8n \
  n8nio/n8n

That's it. n8n runs at http://your-server:5678. Add a reverse proxy for HTTPS — Caddy, nginx, Cloudflare Tunnel, whatever you already use.

Installing Claude Code

# On the machine where you want AI to run
npm install -g @anthropic-ai/claude-code

# Verify
claude --version

Claude Code runs locally. It reads your files, understands project context, and executes commands — all on your hardware.

The Cost Reality

Let's be upfront about pricing. Claude Code requires one of:

  • Anthropic Max subscription — $100/month, includes Claude Code usage with limits
  • Anthropic API key — pay-per-token, costs vary with how much you use it

If that's too steep, Gemini CLI is a solid free alternative. Google offers generous free-tier usage with rate limits. It won't match Claude's reasoning depth on complex tasks, but for log parsing, file operations, and straightforward analysis it gets the job done.

Pick what fits your budget. The n8n + SSH pattern works the same regardless of which AI tool sits on the other end.

Connecting n8n to Claude Code via SSH

Step 1: SSH Key Setup

# On your n8n machine (or inside the container)
ssh-keygen -t ed25519 -f ~/.ssh/claude_host -N ""

# Copy to the target machine
ssh-copy-id -i ~/.ssh/claude_host.pub user@target-machine

Step 2: Configure the SSH Credential in n8n

  1. Go to Credentials → New → SSH
  2. Enter the target machine's host, user, and private key
  3. Test the connection

Step 3: Build the Workflow

The simplest useful workflow:

  1. Trigger — Cron, webhook, Slack message, whatever starts the job
  2. SSH node — Runs claude -p "your prompt here" on the target machine
  3. Process output — Parse, format, route the response wherever it needs to go

In the SSH node, your command looks like:

claude -p "Analyze the last 50 lines of /var/log/syslog. Summarize any errors or warnings." --output-format text

The -p flag runs Claude Code in non-interactive mode — it processes the prompt and exits. Perfect for automation.

Real Workflows Worth Building

Daily Server Health Report

Cron trigger (8 AM) → SSH → claude -p "Check disk usage, memory, CPU load, and recent error logs. Give me a health summary." → Email or Slack the report.

Git PR Reviewer

GitHub webhook on PR → SSH → claude -p "Review the diff at /repo/path. Focus on bugs, security issues, and style." → Post review as a PR comment.

Log Anomaly Detector

Cron every 15 minutes → SSH → claude -p "Compare the last 15 min of logs against normal patterns. Flag anything unusual." → Alert only if something's off.

Incident Responder

Monitoring alert webhook → SSH → claude -p "Service X is down. Check its logs, recent deployments, and resource usage. What happened?" → Post diagnosis to incident channel.

Tips From Actually Running This

  • Use --output-format text — keeps responses clean for downstream parsing
  • Set timeouts — Claude Code can take a while on complex prompts. Set SSH timeout to 120–300 seconds in n8n
  • Be specific in prompts — "check the logs" is vague. "Check /var/log/nginx/error.log for 5xx errors in the last hour" gets better results
  • Chain SSH nodes — first node gathers context, second node analyzes. Keeps prompts focused
  • Use n8n's error handling — if SSH fails or times out, route to a fallback (notification, retry, manual queue)

Why Not Just Use n8n's Built-in AI Nodes?

n8n has LLM nodes. They're fine for text generation — summarize this, draft that, classify this email.

But they can't do things on your server. They can't read your files, run commands, check logs, or interact with your infrastructure. Claude Code can. That's the difference: API-based text processing vs. an AI agent with actual access to your system.

Security — Take This Seriously

You're giving an AI tool SSH access to a machine. Sit with that for a second.

  • Use a dedicated user with limited permissions — not root
  • Restrict SSH keys to specific commands if possible
  • Run Claude Code in a sandboxed directory — don't give it your entire filesystem
  • Log everything — automated workflows should be fully auditable
  • Start small — read-only tasks first, then gradually expand as you build trust

This setup is powerful precisely because it's dangerous. Respect that.

Wrapping Up

n8n handles the "when." Claude Code handles the "what." SSH is just the pipe connecting them. The result is a self-hosted AI workflow system that can actually interact with your infrastructure — not just generate text about it.

Start with something simple: a daily log summary, a cron health check. Once you see an AI reasoning about your actual server state and n8n routing that intelligence where it needs to go, you'll start seeing possibilities everywhere.

Compiled by AI. Proofread by caffeine. ☕