Connect n8n to Claude Code (or other AI terminal tools) via SSH for powerful automation workflows.
Video: n8n + Claude Code is OVERPOWERED
- Prerequisites
- Architecture Overview
- Setup Guide
- Basic Usage
- Session Management
- Advanced Workflows
- Troubleshooting
- Resources
You'll need three things:
- n8n Instance - Self-hosted or cloud
- AI Terminal Tool - Claude Code (recommended), Gemini CLI, or Codex
- Coffee - That's just the rules
- Requires an Anthropic Pro subscription or API access
- Can be installed on any Linux-based machine (including Mac, Windows WSL)
You can install Claude Code on:
| Location | Pros | Cons |
|---|---|---|
| Same VPS as n8n | Simple setup, same machine | Resource sharing |
| Dedicated Ubuntu server | Best performance, local file access | Additional infrastructure |
| Raspberry Pi | Low cost, always on | Limited resources |
| Hostinger VPS | Cloud-based, easy setup | Monthly cost |
┌─────────────┐ SSH ┌──────────────────┐
│ n8n │ ───────────────────► │ Linux Server │
│ (workflow) │ │ (Claude Code) │
└─────────────┘ └──────────────────┘
│
▼
┌──────────────────┐
│ Your Files │
│ Your Skills │
│ Your Context │
└──────────────────┘
The magic? SSH. That's it. n8n uses the SSH node to remotely execute Claude Code commands on your server.
On your Linux server (Ubuntu example):
# Install Node.js (if not installed)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Verify installation
claude --version
# Authenticate (follow prompts)
claude auth- In n8n, add an SSH node to your workflow
- Click Create New Credential
- Fill in your server details:
| Field | Value |
|---|---|
| Host | Your server IP (e.g., 10.77.14.30 or public IP) |
| Port | 22 (default SSH) |
| Username | Your SSH username |
| Authentication | Password or Private Key |
| Password/Key | Your credentials |
- Click Save - Look for "Connection tested successfully"
First, test with a basic command:
hostnameIf that works, test Claude Code:
claude --versionYou should see the Claude Code version in the output.
Use the -p (print) flag for headless mode - send a prompt and get a response:
SSH Node Command:
claude -p "Why do pugs look so weird?"The -p flag puts Claude in "print mode" - it processes your prompt and returns the result without interactive input.
Give Claude access to your project files by changing directory first:
SSH Node Command:
cd /path/to/your/project && claude -p "Is this video going to be any good?"Claude will read files in that directory to inform its response. This is the power - context from your local files.
Put Claude in "dangerous mode" to enable tool use and agent deployment:
SSH Node Command:
claude --dangerously-skip-permissions -p "Use your unifi skill to check wifi status, network performance, and security. Deploy three agents, one for each task. Keep response under 2000 characters."This enables Claude to:
- Use installed skills (like UniFi, Slack, etc.)
- Deploy multiple agents in parallel
- Execute code and scripts
- Access APIs and external services
The real power comes from maintaining conversations across multiple n8n executions.
Add a Code node before your SSH node to generate a UUID:
Code Node (JavaScript):
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return [{ json: { sessionId: uuid } }];SSH Node Command:
claude -p "How many access points are up right now?" --session-id {{ $json.sessionId }}To continue a conversation, use the -r (resume) flag with the same session ID:
SSH Node Command (Follow-up):
claude -r --session-id {{ $('Code').item.json.sessionId }} -p "Why is one of them down?"The -r flag resumes the previous session, so Claude remembers the context of your earlier questions.
Create a workflow that lets you chat with Claude Code from your phone via Slack:
[Slack Trigger] → [Code: Generate UUID] → [SSH: Initial Claude Command]
↓
[Slack: Send Response]
↓
[Slack: Ask Continue?]
↓
[If Node]
/ \
[False] [True]
↓ ↓
[Loop: SSH Resume] [End Workflow]
↓
[Slack: Response]
↓
[Back to Ask Continue]
- Slack Trigger: Listens for messages mentioning your bot
- Code Node: Generates session UUID (see above)
- SSH Node (Initial): First Claude command with
--session-id - Slack Response: Posts Claude's response back to channel
- Slack Dropdown: "Are you done? [Yes] [No]"
- If Node: Routes based on user selection
- SSH Node (Resume): Uses
-r --session-idfor follow-ups - Loop: Continues until user selects "Yes"
@bot deploy two agents to battle it out: which is better, nano or neovim?
Research, contrast, compare, give me a solid answer. Keep response under 2000 characters.
@bot use your NAS skill to check how my stuff server is doing
Common issues and solutions:
The SSH session may not load your shell profile. Solutions:
-
Use full path:
/usr/local/bin/claude -p "your prompt" -
Source profile first:
source ~/.bashrc && claude -p "your prompt"
-
Add to system PATH:
sudo ln -s $(which claude) /usr/local/bin/claude
If Claude can't access files or run tools:
- Ensure the SSH user has proper permissions
- Use
--dangerously-skip-permissionsfor tool access - Check file ownership in your project directories
Make sure you're:
- Using the exact same session ID
- Including the
-rflag when resuming - Not letting too much time pass (sessions may expire)
Slack has a 4000 character limit. Add to your prompts:
Keep response under 2000 characters.
For long-running Claude operations:
- Increase SSH timeout in n8n node settings
- Consider breaking complex tasks into smaller prompts
- NetworkChuck Academy: n8n Course | Claude Code Course
- Claude Code Docs: Official Documentation
- n8n Docs: SSH Node
- Previous Videos:
- n8n Part 1 - Getting Started with n8n
- n8n Part 2 - n8n Now Runs My ENTIRE Homelab (Terry)
- AI in the Terminal - Claude Code, Gemini CLI, Codex Introduction
In the next video, we're building a full IT Department with:
- n8n as the orchestrator
- Claude Code, Gemini CLI, and Codex as the workers
- Automated monitoring, alerting, and remediation
Subscribe to catch it when it drops!