page

N8N SSH Method

N8N SSH Method for Claude Code

Source: theNetworkChuck/n8n-claude-code-guide

How It Works

n8n uses SSH node to remotely execute Claude Code commands on a server.

Key Commands

Basic headless execution

claude -p "your prompt here"

With file/project context

cd /project/path && claude -p "analyze this code"

With tool access (agents, skills)

claude --dangerously-skip-permissions -p "deploy agents"

Session Management (Critical for LARS)

Create session with UUID

claude -p "question" --session-id {{ sessionId }}

Resume conversation

claude -r --session-id {{ sessionId }} -p "follow-up"

The -r flag retrieves previous context!

Python Equivalent (No N8N)

We can replicate this in pure Python:

import subprocess
import uuid

def call_claude_code(prompt: str, session_id: str = None, resume: bool = False):
    cmd = ["claude", "-p", prompt]

    if session_id:
        cmd.extend(["--session-id", session_id])

    if resume:
        cmd.insert(1, "-r")

    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout

# Usage
session = str(uuid.uuid4())
response1 = call_claude_code("What files are here?", session_id=session)
response2 = call_claude_code("Now modify the main one", session_id=session, resume=True)

For LARS Integration

LARS can call Claude Code when: 1. Task exceeds LARS capabilities 2. Complex multi-file operations needed 3. External API integrations required 4. Long-running development tasks

Example Flow

User: "Hey LARS, refactor the authentication module"
LARS: "That's a complex task. Let me delegate to Claude Code."
LARS: subprocess.run(["claude", "-p", "refactor auth...", "--session-id", sid])
LARS: "Claude Code completed the refactor. Here's what changed..."
ID: 99afd0f4
Path: LARS Voice Assistant > Claude Code Integration > N8N SSH Method
Updated: 2025-12-30T19:40:50