n8n & Claude Code: Complete SSH Integration Guide
Last Updated: 13th December 2025
Reading Time: 10 minutes
Overview
This guide shows you how to connect n8n workflows to Claude Code CLI via SSH, enabling automated AI operations with session management and conversation continuity.
Prerequisites
Before starting, you need:
- n8n instance - Self-hosted on a VPS (recommended: Hostinger, Hetzner)
- Claude Code CLI - Installed on a Linux-based machine (VPS, Raspberry Pi, separate server)
- Claude Max subscription ($100/month or $200/month) - Required for Claude Code CLI
- SSH access - Between n8n and your Claude Code server
Where to Install Claude Code CLI
You have three deployment options:
-
Same VPS/Server as n8n (simplest setup)
- Both n8n and Claude Code on same server
- SSH to localhost (127.0.0.1)
- Minimal setup, shared resources
-
Separate VPS/Server (recommended)
- Claude Code on dedicated server (Ubuntu, Debian, etc.)
- n8n connects via SSH using server IP
- Better resource isolation and performance
-
Local Machine (development only)
- Install on your laptop/desktop (macOS, Linux, WSL)
- n8n connects via SSH to your local IP
- Not recommended for production
Recommended: Use a separate VPS for Claude Code, with n8n orchestrating via SSH.
VPS Provider Options:
- Hostinger - Used in the original tutorial, affordable VPS hosting
- AWS EC2 - Enterprise-grade, scalable instances (t2.micro for basic usage)
- AWS Lightsail - Simplified AWS VPS, fixed pricing
- Hetzner - Excellent price/performance ratio, EU-based
- DigitalOcean - Developer-friendly, simple pricing
The connection method is SSH - simple and effective.
Step 1: Install Claude Code CLI
On your target server, install and authenticate Claude Code CLI:
# Installation varies by platform
# macOS: brew install claude-code
# Linux: Follow official installation guide
# Authenticate after installation
claude auth login
Verify installation:
claude --version
Step 2: Create n8n Workflow
In your n8n instance:
- Create a new workflow
- Add a Manual Trigger node (for testing)
- Add an SSH node to the workflow
- Set SSH node operation to Execute Command
Step 3: Configure SSH Credentials
Inside the SSH node:
- Click Create New Credential
- Enter connection details:
- Host: Server IP address (e.g.,
192.168.1.100or public IP) - Port:
22(default SSH port) - Username: Your SSH username
- Authentication: Choose Password or Private Key
- Host: Server IP address (e.g.,
- Click Save
- Verify "Connection tested successfully"
Step 4: Test Basic Commands
In the SSH node command field:
hostname
Execute the workflow. You should see your server's hostname.
Test Claude Code connection:
claude --version
Execute again. You should see Claude Code's version number.
Step 5: Execute Claude Commands (Headless Mode)
The -p flag runs Claude in headless mode - perfect for automation:
claude -p "What are the security best practices for SSH?"
Execute. Claude responds with the answer.
Step 6: Add Context with Directory Changes
Claude Code has access to your server's files:
cd /var/www/myproject && claude -p "Review this codebase for security issues"
This changes to your project directory, then asks Claude to analyse it with full file context.
Step 7: Session Management (Multi-Step Conversations)
To maintain conversation context across multiple executions:
Add Code Node (Generate UUID)
Before your first SSH node, add a Code node with this JavaScript:
return [{
json: {
sessionId: crypto.randomUUID()
}
}];
This generates a unique session ID.
First SSH Node (Start Session)
Use the UUID in your Claude command:
claude -p "How many servers are currently online?" --session-id {{ $json.sessionId }}
Second SSH Node (Resume Session)
Add another SSH node. Use the -r flag to resume the conversation:
claude -r -p "Which ones have high CPU usage?" --session-id {{ $json.sessionId }}
Claude remembers the previous context and continues the conversation.
Complete Workflow Structure
Manual Trigger
↓
Code Node (Generate UUID)
↓
SSH Node 1 (Start session with --session-id)
↓
SSH Node 2 (Resume with -r and --session-id)
Command Reference
| Command | Flag | Purpose | Example |
|---|---|---|---|
claude -p "prompt" | -p | Headless mode | One-off questions |
claude -p "prompt" --session-id {uuid} | --session-id | Start session | Begin conversation |
claude -r -p "prompt" --session-id {uuid} | -r | Resume session | Continue conversation |
Practical Use Cases
1. Infrastructure Monitoring
claude -p "Check server health: CPU, memory, disk space"
2. Code Analysis
cd /var/www/production && claude -p "Find any SQL injection vulnerabilities"
3. Multi-Step Diagnostics
# First SSH node
claude -p "List all running Docker containers" --session-id {{ $json.sessionId }}
# Second SSH node
claude -r -p "Which ones are using more than 1GB RAM?" --session-id {{ $json.sessionId }}
4. Automated Documentation
cd /docs && claude -p "Generate API documentation from the code comments"
Troubleshooting
"claude: command not found"
n8n's SSH session doesn't have Claude in PATH.
Solution: Use full path:
/usr/local/bin/claude -p "prompt"
Or add to .bashrc:
export PATH="/usr/local/bin:$PATH"
Session Not Resuming
Ensure you're using the exact same sessionId variable from the Code node in both SSH nodes.
Permission Denied
Check SSH user has permission to execute Claude:
which claude
ls -la /usr/local/bin/claude
Advanced: Slack Integration
You can trigger n8n workflows from Slack:
Slack Trigger → Code Node (UUID) → SSH Node → Slack Response
This enables conversational AI from your mobile device.
Security Considerations
- SSH Keys: Use SSH key authentication (not passwords) for production
- Firewall: Restrict SSH access to n8n server IP only
- User Permissions: Run Claude as limited user, not root
- Rate Limiting: Implement rate limiting on n8n triggers
Performance Tips
- Use headless mode (
-p) for all automation - Generate UUID once, reuse across multiple SSH nodes
- Keep sessions focused (don't maintain sessions for hours)
- Monitor Claude Code usage via Claude dashboard
Next Steps
- Set up your first workflow with single command
- Test session management with UUID
- Build multi-step diagnostic workflows
- Integrate with Slack or webhooks
- Create automated monitoring workflows
Summary
n8n + Claude Code via SSH provides:
✅ Automated AI operations
✅ Session-based conversations
✅ Full file system access
✅ Simple SSH connection
✅ Flexible workflow orchestration
Start with basic commands, then progress to session management and complex workflows.
Resources
- NetworkChuck's n8n + Claude Code Tutorial: https://www.youtube.com/watch?v=s96JeuuwLzc - Excellent walkthrough with real-world examples and practical implementation guidance. Credit to NetworkChuck for pioneering this integration approach.
- n8n Documentation: https://docs.n8n.io/
- Claude Code: https://www.anthropic.com/claude-code
- SSH Node Guide: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.ssh/



