CLI Guide
The n8nac CLI (n8nac) provides command-line access to all n8nac functionality. It's perfect for automation, scripting, and CI/CD integration.
This page is intentionally command-heavy and serves as the detailed reference for terminal users, scripts, and other power-user workflows.
π¦ Installationβ
Global Installationβ
npm install -g n8nac
Project Installationβ
npm install --save-dev n8nac
Verify Installationβ
n8nac --version
Updatingβ
npm update -g n8nac
To confirm the new version is active:
n8nac --version
@n8n-as-code/cliThe CLI was previously published as @n8n-as-code/cli. That package is no longer maintained. The current package is n8nac (published on npm as n8nac).
If you have both installed at the same time, the old package can shadow the new one and hide commands added in recent releases. Remove it with:
npm uninstall -g @n8n-as-code/cli
# or, if installed as a project dependency
npm uninstall @n8n-as-code/cli
After removing it, n8nac --help should show the full, up-to-date command list.
π Quick Startβ
Initialize a Projectβ
n8nac init
This command:
- Creates or updates
n8nac-config.json - Saves an instance config for the n8n environment you want to use
- Prompts you to select which n8n project to sync
Download a Workflow from n8nβ
n8nac pull <workflowId>
This command:
- Fetches the specified workflow from n8n
- Saves it to the local
workflowsdirectory - Refuses to overwrite if a conflict is detected (use
n8nac resolvein that case)
Upload a Local Workflow to n8nβ
n8nac push workflows/instance/project/workflow.workflow.ts
This command:
- Uploads the specified workflow to n8n
- Uses Optimistic Concurrency Control β rejected if the remote was modified since last pull
- Suggests
n8nac resolveif a conflict is detected
push resolves the filePass the local workflow path you want to upload, for example workflows/instance/project/workflow.workflow.ts.
Use the path that matches your active sync folder and project layout in the workspace.
Complete the Runtime Loop Without Leaving the CLIβ
The CLI now covers the most painful post-push steps that used to force users back into the n8n UI:
- Detect missing credentials with
workflow credential-required - Inspect the expected credential payload with
credential schema - Create the credential with
credential create - Activate the workflow with
workflow activate - Inspect how to run it with
test-plan - Execute it with
test - Debug the actual server-side execution with
execution listandexecution get
This is a major quality-of-life improvement for agent-driven development: the agent can now provision credentials, run the workflow, and inspect the failing execution directly through n8n's API.
The exact commands for each step are documented below in the command reference, so high-level readers can understand the workflow without having to parse a wall of terminal examples first.
π Command Referenceβ
initβ
Initialize a new n8nac project.
Description: Interactive wizard that guides you through saving an n8n instance config and selecting the active project.
Example:
n8nac init
The wizard will ask for:
- n8n Host URL: The URL of your n8n instance (e.g.,
http://localhost:5678) - API Key: Your n8n API key (found in n8n Settings > API)
- Sync Folder: Local directory for workflow storage (default:
workflows) - Project: The n8n project to sync
n8nac init is the ergonomic alias for n8nac instance add.
instanceβ
Manage saved n8n instance configs in the current workspace.
n8nac instance add
n8nac instance list
n8nac instance select
n8nac instance delete
Use instance add for the main setup flow when you want to save a new n8n environment and choose its project in one command.
For scripts and autonomous agents, prefer the explicit non-interactive forms:
n8nac instance list --json
n8nac instance select --instance-id <instanceId>
n8nac instance select --instance-name "https://n8n.example.com / Etienne Lescot"
n8nac instance delete --instance-id <instanceId> --yes
n8nac instance delete --instance-name "https://n8n.example.com / Etienne Lescot" --yes
Use init-auth followed by init-project only when you want to split credential discovery from project selection.
switchβ
Switch to a different n8n project.
n8nac switch
After switching projects, use n8nac list to see the workflows in the new project, then n8nac pull <workflowId> for each workflow you want to download.
listβ
Display all workflows with their current sync status.
Description: Shows a color-coded table of all workflows with their sync status, helping you understand the current state of your workflow synchronization. Supports filtering to show only local or remote workflows.
Options:
--local: Show only workflows that exist locally (includingEXIST_ONLY_LOCALLY,TRACKED,CONFLICT)--remote/--distant: Show only workflows that exist remotely (includingEXIST_ONLY_REMOTELY,TRACKED,CONFLICT)--search <query>: Case-insensitive partial match on workflow name, workflow ID, or local filename--sort <status|name>: Keep the default sync-oriented ordering or force alphabetical sorting--limit <n>: Return only the firstnmatching workflows after filtering/sorting--include-archived: Include archived workflows in the output (by default only non-archived workflows are shown)--only-archived: Show only archived workflows--raw: Output raw JSON for scripting/automation
Example:
n8nac list # Show all non-archived workflows
n8nac list --include-archived # Show all workflows including archived
n8nac list --only-archived # Show only archived workflows
n8nac list --local # Show only local workflows
n8nac list --remote # Show only remote workflows
n8nac list --search billing # Find workflows by partial name, ID, or filename
n8nac list --sort name # Sort alphabetically
n8nac list --raw # Output raw JSON
Output:
- Status indicators with icons (β Tracked, π₯ Conflicts, + Local Only, - Remote Only)
- Workflow ID, name, and local path
- Summary statistics showing counts by status
findβ
Search workflows quickly using the same case-insensitive partial matching used by list --search.
Description: Optimized for large installations where you already know part of the workflow name, ID, or filename and want search-oriented results immediately.
Options:
<query>(required): Search text--local: Limit results to workflows with a local file--remote/--distant: Limit results to workflows known remotely--sort <status|name>: Sort search results by sync status or alphabetically (defaults toname)--limit <n>: Return only the firstnmatching workflows--include-archived: Include archived workflows in search results--only-archived: Show only archived workflows--raw: Output the filtered result set as JSON
Example:
n8nac find billing
n8nac find wf-123 --raw
n8nac find importer --limit 10
n8nac find archived-workflow --only-archived
Status Types:
TRACKED- Both local and remote exist (in sync)CONFLICT- Both local and remote modified since last syncEXIST_ONLY_LOCALLY- New local workflow not yet pushedEXIST_ONLY_REMOTELY- Remote workflow not yet pulled locally
pullβ
Download a specific workflow from n8n to the local directory.
Description:
Downloads a single workflow from your configured n8n instance. Detects and blocks on conflicts β use n8nac resolve when a conflict is reported.
Options:
<workflowId>(required): The ID of the workflow to pull
Example:
n8nac pull abc123
Behavior:
- Fetches the latest remote state for the workflow
- Checks for conflict (
CONFLICT) β aborts with instructions if detected (usen8nac resolve) - Downloads and writes the workflow file on success
pushβ
Upload a local workflow to n8n.
Description: Uploads a single workflow from local to your n8n instance. Uses Optimistic Concurrency Control (OCC) β the push is rejected if the remote was modified since the last pull.
Options:
<path>(required): The local workflow path to upload
Example:
n8nac push workflows/instance/project/workflow.workflow.ts
Behavior:
- Resolves the effective local file path from
n8nac-config.json - Finds the tracked workflow ID for that filename when one exists
- Checks for conflict β if remote was modified since last sync, aborts with instructions
- Uploads the local workflow on success
- Reports the
n8nac resolvecommands to use if a conflict is detected
resolveβ
Force-resolve a sync conflict for a specific workflow.
Description:
When n8nac pull or n8nac push reports a conflict, use this command to choose which version wins. No merging β one side overwrites the other.
Options:
<workflowId>(required): The ID of the conflicting workflow--mode <keep-current|keep-incoming>(required): Resolution strategykeep-current: Keep the local version (force-push it to n8n)keep-incoming: Keep the remote version (force-pull it locally)
Example:
n8nac resolve abc123 --mode keep-current # Force-push local
n8nac resolve abc123 --mode keep-incoming # Force-pull remote
update-aiβ
Update AI Context (AGENTS.md and code snippets).
Description: Regenerates context files that help AI coding assistants (GitHub Copilot, Cursor, Cline, Windsurfβ¦) understand n8n workflow structure and best practices. The command fetches the installed n8n version to tailor the output.
n8nac init-ai is kept as a backward-compatible alias for n8nac update-ai.
Example:
n8nac update-ai
Creates / updates:
AGENTS.md: Instructions for AI assistants on n8n workflow development.vscode/n8n.code-snippets: Code completion snippets for VS Code
workflowβ
Workflow lifecycle and credential inspection helpers.
workflow credential-requiredβ
List the credentials referenced by a workflow and whether matching credentials already exist.
n8nac workflow credential-required <workflowId> --json
This is the entry point for provisioning after a push. Exit code 1 means at least one credential is missing. Exit code 0 means everything referenced by the workflow is already present.
workflow activateβ
Activate a workflow once credentials are provisioned.
n8nac workflow activate <workflowId>
credentialβ
Inspect and create credentials from the CLI.
credential schemaβ
Return the JSON schema for a credential type.
n8nac credential schema openAiApi
Use this before creating any credential type you have not seen before.
credential createβ
Create a credential from a JSON file.
n8nac credential create --type openAiApi --name "My OpenAI" --file cred.json --json
Prefer --file over --data so secrets do not end up in shell history.
credential listβ
List existing credentials without exposing secret values.
n8nac credential list --json
test-planβ
Inspect how a workflow can be executed over HTTP.
n8nac test-plan <workflowId> --json
This returns:
- the detected trigger type
- the test and production URLs
- an inferred payload
- request hints for GET/HEAD webhooks
testβ
Execute a webhook/chat/form workflow over HTTP.
n8nac test <workflowId> --data '{"foo":"bar"}'
n8nac test <workflowId> --query '{"chatInput":"hello"}'
n8nac test <workflowId> --prod --query '{"chatInput":"hello"}'
Notes:
- For
GETandHEADwebhooks, prefer--query <json>. --datastill maps to query parameters forGETandHEADrequests for backward compatibility.testdistinguishes setup/config gaps from fixable wiring errors.
executionβ
Inspect workflow executions directly from the n8n server.
execution listβ
List recent executions, optionally filtered by workflow.
n8nac execution list --workflow-id <workflowId> --limit 5 --json
execution getβ
Fetch one execution, optionally including the run data.
n8nac execution get <executionId> --include-data --json
Use this immediately after a 2xx webhook call if the workflow still seems broken. A successful HTTP response only means n8n accepted the trigger; the execution may still fail later inside the workflow.
convertβ
Convert a single workflow file between JSON and TypeScript formats.
Description:
Converts a .json workflow export to a .workflow.ts file (or vice-versa). The target format is auto-detected from the source extension unless --format is provided.
Arguments:
<file>(required): Path to the source file
Options:
-o, --output <path>: Output file path (auto-generated if omitted)-f, --force: Overwrite output file if it already exists--format <json|typescript>: Override the auto-detected target format
Example:
n8nac convert my-workflow.json # JSON β TypeScript
n8nac convert my-workflow.workflow.ts # TypeScript β JSON
n8nac convert my-workflow.json -o out.workflow.ts -f # JSON β TS, force overwrite
convert-batchβ
Batch-convert all workflow files in a directory.
Description: Converts every workflow file in the specified directory to the target format.
Arguments:
<directory>(required): Path to the directory containing workflow files
Options:
--format <json|typescript>(required): Target format for all files-f, --force: Overwrite existing output files
Example:
n8nac convert-batch ./workflows --format typescript # Convert all JSON to TS
n8nac convert-batch ./workflows --format json # Convert all TS to JSON
βοΈ Configurationβ
Configuration Fileβ
The CLI uses a configuration file (n8nac-config.json) with the following structure:
{
"version": 2,
"activeInstanceId": "prod",
"instances": [
{
"id": "test",
"name": "Test",
"host": "https://test.n8n.example.com",
"syncFolder": "workflows-test",
"projectId": "your-test-project-id",
"projectName": "Test",
"instanceIdentifier": "test_instance_user"
},
{
"id": "prod",
"name": "Production",
"host": "https://n8n.example.com",
"syncFolder": "workflows-prod",
"projectId": "your-project-id",
"projectName": "Personal",
"instanceIdentifier": "local_5678_user"
}
]
}
The active instance is also mirrored at the top level for compatibility, but the source of truth is the instances array plus activeInstanceId.
Note: API keys are stored securely in your system's credential store, scoped by saved instance config when available, not in this file.
π Workflow Managementβ
Git-like Sync Workflowβ
# 1. Initialize project
n8nac init
# Optional: switch to another saved instance config
n8nac instance select
# 2. List all workflows to see their sync status (lightweight, covers all workflows)
n8nac list
# 3. Pull a specific workflow (single workflow, by ID)
n8nac pull abc123
# 4. Edit workflow files locally
# (edit workflows/*.workflow.ts files)
# 5. Push local changes to n8n (single workflow, by path)
n8nac push workflows/instance/project/workflow.workflow.ts
Git-like Development Patternβ
# See current status of all workflows
n8nac list
# Pull a specific workflow from remote (single workflow)
n8nac pull abc123
# ... edit workflow ...
# Push local changes back to n8n (single workflow)
n8nac push workflows/instance/project/workflow.workflow.ts
# Resolve a conflict (if push/pull is blocked) (single workflow)
n8nac resolve abc123 --mode keep-current # keep local
n8nac resolve abc123 --mode keep-incoming # keep remote
# View local-only or remote-only workflows
n8nac list --local # Show only local workflows
n8nac list --remote # Show only remote workflows
π Scripting Examplesβ
Backup Scriptβ
#!/bin/bash
# backup-workflows.sh
# Set date for backup folder
BACKUP_DATE=$(date +%Y-%m-%d)
BACKUP_DIR="backups/$BACKUP_DATE"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Copy workflows to backup directory
cp -r workflows/* "$BACKUP_DIR/" 2>/dev/null || true
# Or pull fresh copy to backup directory
# (Run in a separate folder if you want backups isolated)
# cd "$BACKUP_DIR" && n8nac init && n8nac pull <workflowId>
# Compress backup
tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"
echo "Backup created: $BACKUP_DIR.tar.gz"
CI/CD Integrationβ
#!/bin/bash
# ci-sync.sh
# Set environment variables for target instance
export N8N_HOST="https://staging.n8n.example.com"
export N8N_API_KEY="$STAGING_API_KEY"
# Initialize with environment variables
n8nac init
# List workflows and pull specific ones from staging
n8nac list
n8nac pull <workflowId>
# (Make any necessary transformations)
# Push to production if approved
if [ "$DEPLOY_TO_PROD" = "true" ]; then
export N8N_HOST="https://prod.n8n.example.com"
export N8N_API_KEY="$PROD_API_KEY"
n8nac init
n8nac push workflows/instance/project/workflow.workflow.ts
fi
Batch Operationsβ
#!/bin/bash
# batch-update.sh
# Update all workflows with a new tag
for workflow in workflows/*.json; do
echo "Updating $workflow"
# Add metadata using jq
jq '.metadata.tags += ["automated"]' "$workflow" > "$workflow.tmp"
mv "$workflow.tmp" "$workflow"
done
# Push changes to n8n
n8nac push workflows/instance/project/workflow.workflow.ts
π― Best Practicesβ
Project Structureβ
my-project/
βββ n8nac-config.json # Project configuration
βββ workflows/ # Workflow storage
β βββ instance_identifier/ # Organized by instance
β βββ project_slug/ # Organized by project
β βββ workflow1.json
βββ scripts/ # Automation scripts
β βββ backup.sh
βββ README.md
Version Controlβ
- Commit workflow JSON files to Git for version history
- Use
.gitignoreto exclude sensitive data - Tag releases with workflow versions
- Review changes using Git diff before pushing to n8n
Securityβ
- Never commit API keys or credentials to version control
- Use environment variables or secret managers for sensitive data
- Rotate API keys regularly
- Store API keys in system credential store (handled automatically by CLI)
π¨ Troubleshootingβ
Common Issuesβ
Connection Errors
# Check connectivity to n8n instance
curl -I https://n8n.example.com
# Verify configuration
cat n8nac-config.json
# Reinitialize connection
n8nac init
File Permission Issues
# Check file permissions
ls -la workflows/
# Fix permissions if needed
chmod -R 755 workflows/
Sync Issues
# Check workflow status
n8nac list
# Pull a specific workflow
n8nac pull <workflowId>
# Push local changes for a specific workflow file
n8nac push workflows/instance/project/workflow.workflow.ts
# Resolve a conflict
n8nac resolve <workflowId> --mode keep-current
Debug Modeβ
Enable debug logging for detailed output:
# Debug pull operation
DEBUG=n8n-as-code:* n8nac pull <workflowId>
# Debug specific operations
DEBUG=axios,n8n-as-code:* n8nac push workflows/instance/project/workflow.workflow.ts
π Next Stepsβ
- VS Code Extension Guide: Visual editing experience with git-like sync
- Getting Started: Complete setup guide
- Contribution Guide: Understand the architecture and development
The CLI provides powerful automation capabilities for managing n8n workflows as code. Use it for scripting, CI/CD integration, and headless workflow management.