N8n cli refactor

From 8Dvibes/n8n-cli · View interactive version

N8n cli refactor is an AI agent skill from the GitHub repository 8Dvibes/n8n-cli. Refactor an n8n workflow for simplification. Finds redundant nodes, batching opportunities, and over-complex Code nodes, then proposes a cleaner version. Use when a workflow feels unwieldy or has grown past 20 nodes.

How to use this skill

Skill file

/n8n-cli-refactor — AI-Assisted Workflow Refactoring

Read a workflow, identify simplification opportunities, propose a refactor, and (with approval) build the refactored version.

Procedure

  1. Get the workflow:
  1. Analyze for refactor opportunities:

a. Redundant nodes — sequential Set or Function nodes that could combine into one

b. Repeated HTTP requests — multiple HTTP Request nodes hitting the same API. If they're fetching different IDs, propose batching with Split In Batches or moving the call into a single node with a loop

c. Branch + Merge that does nothing — IF nodes that split for no reason and immediately re-merge

d. Over-complex Code nodes — JS/Python code blocks doing things n8n nodes already do (HTTP requests via fetch, JSON parsing, date math). Offer to replace with built-in nodes

e. Hardcoded magic strings — URLs, IDs, channel names that should be variables or env config

f. Missing error handlers — risky nodes (HTTP, external API) without error output wired up

g. Dead branches — nodes that aren't connected to anything downstream

  1. Score the refactor opportunities by impact:
  1. Propose the refactor as a side-by-side:
## Refactor Proposal: [Workflow Name]

### Current state
- Nodes: 32
- Branches: 4
- Code nodes: 7
- HTTP Request nodes: 8

### Proposed state
- Nodes: 22 (-10)
- Branches: 3 (-1)
- Code nodes: 3 (-4)
- HTTP Request nodes: 5 (-3)

### Changes
1. Combine "Set Customer Vars" + "Set Order Vars" + "Set Defaults" into a single Set node (save 2 nodes)
2. Replace Code node "fetchOrderData" with HTTP Request node + JSON parse — n8n handles this natively (save 1 node + complexity)
3. Remove dead branch "Notify Legacy System" — it's not connected to a final output
4. Add error handler to "Stripe Webhook" — currently any failure here drops the order silently
5. ...

### Risk
- Low: changes 1, 2, 3 are safe
- Medium: change 5 modifies the order of operations slightly
- High: none

### Recommendation
Apply changes 1-3 immediately. Review change 5 with the workflow owner before applying.
  1. If user approves: write the refactored workflow JSON, save to /tmp/after.json, then either:

Output format

Safety

Tips

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.