Claude Code icon

Claude Code

Execute Claude Code commands using the SDK

Overview

This node allows users to execute commands using the Claude Code CLI tool via its SDK interface. It sends a prompt (and optional context) to the Claude command-line interface and retrieves the response. This is useful for automating interactions with Claude Code, such as running code generation, analysis, or other AI-assisted coding tasks directly within an n8n workflow.

Typical use cases include:

  • Sending programming-related prompts to Claude Code to generate or analyze code snippets.
  • Providing additional context or file content to improve Claude's responses.
  • Controlling the interaction mode and output format of Claude Code responses.
  • Restricting which tools Claude can use during execution for security or specificity.

Properties

Name Meaning
Prompt The main prompt text sent to Claude Code. This is the primary input that instructs Claude what to do.
Context Additional context or file content appended before the prompt to provide more background information.
Allowed Tools Comma-separated list of allowed tools Claude can use during execution (e.g., Bash(git log:*),Bash(git diff:*)).
System Prompt Custom system prompt prepended to the conversation to guide Claude's behavior.
Max Turns Maximum number of conversation turns Claude will engage in. Defaults to 1.
Output Format How the output is formatted. Options are: Text (plain string), JSON (parsed JSON object if possible), or Full Response (includes stdout, stderr, etc).
Non-Interactive Whether to run Claude in non-interactive mode (true/false). Defaults to true.
Permission Mode Permission mode controlling tool usage restrictions. Options: Standard, Strict, or Relaxed.

Output

The node outputs an array of items where each item contains a json field with a response property. The structure of response depends on the selected output format:

  • Text: A plain string containing Claude's textual response.
  • JSON: Attempts to parse the response as JSON; if parsing fails, returns an object with a text property containing the raw response.
  • Full Response: An object containing:
    • stdout: The full standard output from Claude CLI.
    • stderr: Any error output from Claude CLI.
    • prompt: The combined prompt sent to Claude.
    • args: The array of CLI arguments used.

No binary data output is produced by this node.

Dependencies

  • Requires the Claude CLI tool (claude) to be installed and accessible in the system environment where n8n runs.
  • Uses Node.js child process spawning to invoke the Claude CLI.
  • Environment variables from the current process are passed through to the spawned process.
  • No internal API keys or credentials are handled by this node; any required authentication must be configured externally for the Claude CLI.

Troubleshooting

  • Claude CLI not found or failed to execute: Ensure the claude executable is installed and available in the system PATH where n8n runs.
  • CLI exits with non-zero code: The node captures standard error output and includes it in the error message. Check the error details for clues (e.g., invalid flags, permission issues).
  • JSON parsing errors: If output format is set to JSON but Claude returns non-JSON text, the node falls back to returning the raw text inside an object.
  • Permission mode misconfiguration: Using strict or relaxed modes changes how tools are permitted; incorrect settings may cause unexpected failures.
  • Long-running or interactive prompts: The node defaults to non-interactive mode; setting this to false may cause hangs if Claude expects user input.

To resolve errors, verify CLI installation, check prompt formatting, and adjust options accordingly.

Links and References


If you need further details or examples on how to configure specific properties or handle outputs, feel free to ask!

Discussion