Skip to content

Infiniteyieldai/n8n-claude-code-guide

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

n8n + Claude Code Integration Guide

Connect n8n to Claude Code (or other AI terminal tools) via SSH for powerful automation workflows.

Video: n8n + Claude Code is OVERPOWERED


Table of Contents


Prerequisites

You'll need three things:

  1. n8n Instance - Self-hosted or cloud
  2. AI Terminal Tool - Claude Code (recommended), Gemini CLI, or Codex
  3. Coffee - That's just the rules

Claude Code Requirements

Where to Install Claude Code

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

Architecture Overview

┌─────────────┐         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.


Setup Guide

1. Install Claude Code

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

2. Configure n8n SSH Credentials

  1. In n8n, add an SSH node to your workflow
  2. Click Create New Credential
  3. 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
  1. Click Save - Look for "Connection tested successfully"

3. Test the Connection

First, test with a basic command:

hostname

If that works, test Claude Code:

claude --version

You should see the Claude Code version in the output.


Basic Usage

Simple Claude Command

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.

Adding Context (Working Directory)

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.

Using Skills and Agents

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

Session Management

The real power comes from maintaining conversations across multiple n8n executions.

Creating a Session ID

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 }}

Resuming Sessions

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.


Advanced Workflows

Slack Integration (Mobile Access)

Create a workflow that lets you chat with Claude Code from your phone via Slack:

Workflow Structure:

[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]

Key Components:

  1. Slack Trigger: Listens for messages mentioning your bot
  2. Code Node: Generates session UUID (see above)
  3. SSH Node (Initial): First Claude command with --session-id
  4. Slack Response: Posts Claude's response back to channel
  5. Slack Dropdown: "Are you done? [Yes] [No]"
  6. If Node: Routes based on user selection
  7. SSH Node (Resume): Uses -r --session-id for follow-ups
  8. Loop: Continues until user selects "Yes"

Example Prompts from Slack:

@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

Troubleshooting

Common issues and solutions:

Claude Command Not Found

The SSH session may not load your shell profile. Solutions:

  1. Use full path:

    /usr/local/bin/claude -p "your prompt"
  2. Source profile first:

    source ~/.bashrc && claude -p "your prompt"
  3. Add to system PATH:

    sudo ln -s $(which claude) /usr/local/bin/claude

Permission Denied Errors

If Claude can't access files or run tools:

  1. Ensure the SSH user has proper permissions
  2. Use --dangerously-skip-permissions for tool access
  3. Check file ownership in your project directories

Session Not Resuming

Make sure you're:

  1. Using the exact same session ID
  2. Including the -r flag when resuming
  3. Not letting too much time pass (sessions may expire)

Response Too Long

Slack has a 4000 character limit. Add to your prompts:

Keep response under 2000 characters.

SSH Connection Timeout

For long-running Claude operations:

  1. Increase SSH timeout in n8n node settings
  2. Consider breaking complex tasks into smaller prompts

Resources


What's Next?

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!


Created by NetworkChuck | YouTube | Discord

About

Connect n8n to Claude Code via SSH for powerful automation workflows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors