n8n Integration with Claude Code CLI¶
Automate complex workflows by connecting Claude Code CLI to n8n, the powerful workflow automation platform.
What You'll Learn¶
- What n8n is and why integrate it with Claude Code CLI
- Setting up the n8n MCP server for terminal use
- Executing workflows from your terminal
- Building AI-powered automation pipelines
- Real-world CLI integration patterns
What is n8n?¶
n8n is an open-source workflow automation tool that connects apps and services. Think of it as a visual programming environment where you can:
- Connect 400+ services (Slack, GitHub, databases, APIs)
- Build complex automation workflows
- Trigger actions based on events
- Process and transform data
Why Integrate with Claude Code CLI?¶
Combining Claude Code CLI with n8n gives you terminal-based access to hundreds of services:
| Claude Code CLI | n8n | Together |
|---|---|---|
| Terminal AI reasoning | Service connections | CLI-triggered automation |
| Code generation | Visual workflows | Smart pipelines |
| Natural language in terminal | Event triggers | Conversational automation |
| File operations | Data transformation | End-to-end processing |
Example: In your terminal, ask Claude to "notify the team about this bug" and it triggers an n8n workflow that creates a Jira ticket, posts to Slack, and sends an email - all without leaving your terminal.
Architecture Overview¶
When you type commands in your terminal, here's what happens:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Your │ │ n8n MCP │ │ n8n Server │
│ Terminal │────▶│ Server │────▶│ (Workflows) │
│ (Claude CLI)│◀────│ │◀────│ │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────────┐
│ External Services│
│ Slack, GitHub, │
│ Databases, APIs │
└─────────────────┘
All interaction happens through your terminal - you never need to leave the command line.
Setting Up n8n Integration¶
Prerequisites¶
- n8n instance - Self-hosted or n8n.cloud
- n8n API key - From your n8n settings
- Claude Code - Installed and configured
Step 1: Install n8n (if self-hosting)¶
# Using Docker
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
# Or using npm
npm install -g n8n
n8n start
Access n8n at http://localhost:5678
Step 2: Get Your n8n API Key¶
- Open n8n web interface
- Go to Settings → API
- Create a new API key
- Copy the key securely
Step 3: Install n8n MCP Server¶
Or use npx (no installation needed):
Step 4: Configure Claude Code¶
Add to your Claude Code settings (~/.claude/settings.json):
{
"mcpServers": {
"n8n": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-n8n"],
"env": {
"N8N_API_URL": "http://localhost:5678/api/v1",
"N8N_API_KEY": "your-api-key-here"
}
}
}
}
For n8n.cloud:
{
"mcpServers": {
"n8n": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-n8n"],
"env": {
"N8N_API_URL": "https://your-instance.app.n8n.cloud/api/v1",
"N8N_API_KEY": "your-api-key-here"
}
}
}
}
Step 5: Restart Claude Code CLI¶
Close any existing Claude Code session and start fresh in your terminal:
Verify the connection by typing in your terminal session:
Claude CLI will use the n8n MCP tools to query your workflows.
Available MCP Tools¶
Once configured, Claude has access to these n8n tools:
| Tool | Purpose |
|---|---|
mcp__n8n__search_workflows |
Find workflows by name or description |
mcp__n8n__get_workflow_details |
Get full workflow configuration |
mcp__n8n__execute_workflow |
Run a workflow with inputs |
Using n8n from Your Terminal¶
All n8n interaction happens through natural language in your Claude Code CLI session.
Listing Workflows¶
Type in your terminal session:
Claude CLI searches and lists your workflows with descriptions - no need to open the n8n web UI.
Understanding a Workflow¶
Claude CLI fetches the workflow details and explains: - Trigger type (webhook, schedule, etc.) - Nodes and their connections - Expected inputs and outputs
Executing Workflows¶
Claude CLI: 1. Finds the workflow 2. Checks required inputs 3. Executes with your parameters 4. Returns the result right in your terminal
Workflow Types and Triggers¶
n8n workflows have different trigger types. Claude handles each appropriately:
Webhook Workflows¶
Triggered by HTTP requests:
> Execute the webhook workflow "Process Order" with this data:
- customerId: 123
- items: ["widget", "gadget"]
- total: 99.99
Claude sends a POST request to the webhook with your data.
Chat/AI Workflows¶
Workflows designed for conversational input:
Claude sends the chat input and returns the response.
Form Workflows¶
Workflows expecting structured form data:
> Submit to the "New Employee" workflow:
- name: John Doe
- department: Engineering
- startDate: 2025-01-15
Manual Execution¶
Workflows without automatic triggers:
Real-World Integration Patterns¶
Pattern 1: Deployment Notifications¶
Create a workflow in n8n that: 1. Receives deployment info (webhook) 2. Posts to Slack 3. Updates status page 4. Sends email to stakeholders
Use from Claude Code:
> I just deployed version 2.3.1 to production. Run the deployment
notification workflow with:
- version: 2.3.1
- environment: production
- changes: "Bug fixes and performance improvements"
Pattern 2: Issue Triage¶
n8n workflow that: 1. Creates Jira/GitHub issue 2. Assigns based on labels 3. Notifies relevant team 4. Adds to sprint board
Use from Claude Code:
> Found a critical bug in the payment module. Create an issue:
- title: Payment fails for international cards
- severity: critical
- component: payments
- description: [Claude generates from context]
Pattern 3: Documentation Sync¶
n8n workflow that: 1. Receives documentation updates 2. Publishes to Notion/Confluence 3. Updates search index 4. Notifies documentation team
Use from Claude Code:
Pattern 4: Code Review Automation¶
n8n workflow that: 1. Receives PR information 2. Runs static analysis 3. Posts review comments 4. Updates review dashboard
Use from Claude Code:
Pattern 5: AI-Powered Data Processing¶
n8n workflow with AI nodes that: 1. Receives raw data 2. Uses Claude for analysis 3. Transforms results 4. Stores in database
Use from Claude Code:
Building n8n Workflows for Claude¶
Best Practices¶
1. Clear Input Schemas¶
Define what your workflow expects:
{
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "The message to send"
},
"channel": {
"type": "string",
"description": "Slack channel name"
},
"urgent": {
"type": "boolean",
"description": "Whether to use @here mention"
}
},
"required": ["message", "channel"]
}
2. Descriptive Names¶
Name workflows clearly: - ✅ "Send Slack Notification to Team" - ❌ "Workflow 1"
3. Add Descriptions¶
Include descriptions explaining: - What the workflow does - Required inputs - Expected outputs - Example usage
4. Return Useful Responses¶
End workflows with meaningful output:
{
"success": true,
"message": "Notification sent to #engineering",
"timestamp": "2025-01-15T10:30:00Z"
}
Example: Slack Notification Workflow¶
Create this workflow in n8n:
- Webhook Trigger
- Method: POST
-
Path:
/slack-notify -
Set Node (prepare message)
-
Format the incoming data
-
Slack Node
-
Send message to channel
-
Respond to Webhook
- Return success/failure
Now use it:
CLI-Specific Automation¶
One of the biggest advantages of Claude Code CLI is integration with shell scripts and terminal workflows.
Non-Interactive n8n Commands¶
Use claude -p for scripted automation:
# Trigger deployment notification from a shell script
claude -p "Run the 'Deploy Notification' workflow with version=2.3.1 env=production"
# Use in CI/CD pipelines
claude -p "Execute 'Test Results' workflow with status=passed build=$BUILD_NUMBER"
# Combine with other CLI tools
git log -1 --format="%s" | xargs -I {} claude -p "Run 'Commit Alert' with message='{}'"
Shell Script Integration¶
Create a deployment script that uses Claude + n8n:
#!/bin/bash
# deploy.sh - Deploy and notify via n8n
VERSION=$1
ENV=$2
# Run deployment
./deploy-app.sh $VERSION $ENV
# Notify via Claude + n8n (non-interactive)
claude -p "Run the deployment notification workflow with:
- version: $VERSION
- environment: $ENV
- timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
- deployer: $USER"
echo "Deployment complete and team notified"
Cron Jobs with n8n¶
Schedule n8n executions via cron:
# Daily report at 9am
0 9 * * * claude -p "Run the 'Daily Metrics Report' workflow" >> /var/log/claude-n8n.log 2>&1
# Hourly health check
0 * * * * claude -p "Execute 'System Health Check' workflow" >> /var/log/health.log 2>&1
Chaining Claude Code CLI and n8n¶
Sequential Operations¶
> 1. Analyze the test results in test-output.json
2. If there are failures, run the "Test Failure Alert" workflow
3. Create a summary of what failed and why
Claude: 1. Reads and analyzes the file 2. Conditionally triggers n8n 3. Generates a summary
Conditional Workflows¶
> Check if the build passed. If yes, run the "Deploy to Staging" workflow.
If no, run the "Build Failure Notification" workflow with the error details.
Data Transformation¶
> Read the sales data from sales.csv, summarize it, and send the summary
through the "Weekly Sales Report" workflow
Claude: 1. Reads and processes the CSV 2. Creates a summary 3. Sends to n8n for distribution
Troubleshooting¶
"Workflow not found"¶
Solutions:
- Check exact workflow name: > List all workflows
- Verify workflow is active in n8n
- Check API permissions
"Invalid input"¶
Solution: Check workflow requirements:
"Authentication failed"¶
Solutions: - Verify API key is correct - Check API key permissions in n8n - Ensure n8n URL is accessible
"Webhook timeout"¶
Solutions: - Check n8n server is running - Verify network connectivity - Check workflow execution logs in n8n
Security Considerations¶
API Key Protection¶
Never commit API keys:
Set via environment:
Workflow Permissions¶
- Use n8n's role-based access control
- Create dedicated API keys per environment
- Limit workflow execution permissions
Input Validation¶
Validate inputs in your n8n workflows:
// In n8n Function node
if (!$input.item.json.email.includes('@')) {
throw new Error('Invalid email format');
}
Try It Yourself¶
Exercise 1: Basic Integration¶
- Set up n8n locally or use n8n.cloud
- Create a simple webhook workflow that returns a greeting
- Configure the MCP server
- Execute the workflow from Claude Code
Exercise 2: Notification System¶
- Create an n8n workflow that:
- Accepts a message and urgency level
- Sends to Slack (or logs if no Slack)
-
Returns confirmation
-
Use Claude Code to:
- List the workflow
- Understand its inputs
- Execute with different parameters
Exercise 3: Development Automation¶
- Create workflows for:
- PR notifications
- Deployment alerts
-
Test failure reports
-
Integrate with your actual development process
Exercise 4: AI Pipeline¶
- Create an n8n workflow with an AI node
- Send data from Claude Code
- Receive AI-processed results back
- Take action based on results
What's Next?¶
You've learned how to integrate n8n with Claude Code for powerful automation. Consider:
- Building a library of reusable workflows
- Creating team-specific automation commands
- Integrating with your CI/CD pipeline
- Building AI-powered data processing pipelines
Return to Enterprise Patterns to see how this fits into team workflows.
Summary:
- n8n extends Claude Code CLI with 400+ service integrations
- All interaction stays in your terminal - no context switching
- Configure via MCP server with API key authentication
- Execute workflows using natural language in your terminal session
- Build AI-powered automation pipelines triggered from the CLI
- Use non-interactive mode (claude -p) for scripted n8n automation
- Secure your integration with environment variables and RBAC
Learning Resources¶
Featured Video¶
freeCodeCamp: n8n Workflow Automation (10M+ subscribers)
Comprehensive n8n + AI integration - build automated workflows with 400+ service connections.
Additional Resources¶
| Type | Resource | Description |
|---|---|---|
| 🎬 Video | Claude Code + MCP Workflows | All About AI - Automation patterns |
| 📚 Official Docs | n8n AI Tutorial | Official n8n AI documentation |
| 📖 Tutorial | freeCodeCamp Guide | Complete n8n tutorial |
| 🎓 Free Course | n8n AI Templates | 4780+ free workflow templates |
| 💼 Commercial | n8n Complete Course | Comprehensive automation training |