Pete Gypps Mascot
n8n & Claude Code: Complete SSH Integration Guide
Back to Blog
Automation

n8n & Claude Code: Complete SSH Integration Guide

Pete Gypps
Pete Gypps
Published: 13th December 2025
10 min read

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:

  1. n8n instance - Self-hosted on a VPS (recommended: Hostinger, Hetzner)
  2. Claude Code CLI - Installed on a Linux-based machine (VPS, Raspberry Pi, separate server)
  3. Claude Max subscription ($100/month or $200/month) - Required for Claude Code CLI
  4. SSH access - Between n8n and your Claude Code server

Where to Install Claude Code CLI

You have three deployment options:

  1. 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
  2. Separate VPS/Server (recommended)

    • Claude Code on dedicated server (Ubuntu, Debian, etc.)
    • n8n connects via SSH using server IP
    • Better resource isolation and performance
  3. 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:

  1. Create a new workflow
  2. Add a Manual Trigger node (for testing)
  3. Add an SSH node to the workflow
  4. Set SSH node operation to Execute Command

Step 3: Configure SSH Credentials

Inside the SSH node:

  1. Click Create New Credential
  2. Enter connection details:
    • Host: Server IP address (e.g., 192.168.1.100 or public IP)
    • Port: 22 (default SSH port)
    • Username: Your SSH username
    • Authentication: Choose Password or Private Key
  3. Click Save
  4. 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

CommandFlagPurposeExample
claude -p "prompt"-pHeadless modeOne-off questions
claude -p "prompt" --session-id {uuid}--session-idStart sessionBegin conversation
claude -r -p "prompt" --session-id {uuid}-rResume sessionContinue 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

  1. SSH Keys: Use SSH key authentication (not passwords) for production
  2. Firewall: Restrict SSH access to n8n server IP only
  3. User Permissions: Run Claude as limited user, not root
  4. 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

  1. Set up your first workflow with single command
  2. Test session management with UUID
  3. Build multi-step diagnostic workflows
  4. Integrate with Slack or webhooks
  5. 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

Pete Gypps

Written by

Pete Gypps

Technology Consultant & Digital Strategist

About This Article

Step-by-step technical guide to connecting n8n workflows to Claude Code CLI via SSH. Learn session management, credential configuration, and multi-step conversation handling.

Let's Connect

Have questions about this article or need help with your IT strategy?

Book a Consultation
P
Pete Bot
Business Solutions Assistant
P

Let's Get Started!

Enter your details to begin chatting with Pete Bot

💬 Got questions? Let's chat!
P
Pete Bot
Hi! 👋 Ready to boost your business online? I'm here to help with web design, SEO, and AI solutions!