npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chrishdx/n8n-nodes-claude-cli

v1.1.1

Published

n8n Community Node for Claude CLI as LangChain Chat Model

Readme

n8n-nodes-claude-cli

Community node package for n8n that exposes the Claude CLI (Claude Code) as a LangChain Chat Model. It runs claude --print --output-format json using the bundled @anthropic-ai/claude-agent-sdk CLI or a custom Claude CLI install.

Nodes included

  • Claude Chat Model (CLI): LangChain chat model for the AI Agent node
  • Claude Auth (CLI): browser login + login status for Claude CLI sessions (no API keys)

Features

  • Claude CLI integration: non-interactive --print mode
  • Login without API keys: browser-based OAuth (PKCE) flow from n8n
  • Login status: check Claude CLI session status inside n8n
  • Browser login in n8n: start + complete browser login flows for automation
  • Automatic token refresh: OAuth tokens are automatically renewed in the background when 75% of their lifetime has elapsed (no workflows needed)
  • Manual token refresh: optional manual refresh via workflow (for advanced use cases)
  • Model selection: aliases (sonnet, opus, haiku) or full model IDs
  • Permissions: permission modes plus tool allow/deny lists
  • Session control: stateless or stateful CLI sessions
  • Streaming: optional token streaming via stream-json
  • Budget controls: optional max budget + fallback model

Requirements

  • Self-hosted n8n only (uses child_process)
  • n8n >= 1.0.0
  • Node.js >= 18
  • Claude CLI available via:
    • Bundled CLI from @anthropic-ai/claude-agent-sdk, or
    • Custom Path to a claude CLI executable or cli.js

Installation

Option 1: Install from npm (once published)

npm install @chrishdx/n8n-nodes-claude-cli

Option 2: Install locally for development

git clone <your-repo-url>
cd n8n-nodes-claude-cli
npm install
npm run build
npm link

Then in your n8n installation directory:

npm link @chrishdx/n8n-nodes-claude-cli
n8n start

Credentials setup

Create Claude CLI credentials in n8n:

  • Claude CLI Source: Bundled or Custom Path
  • Claude CLI Path: path to claude or cli.js if using Custom Path
  • Config Directory (CLAUDE_CONFIG_DIR): optional; set to the same directory used by the CLI

No API keys are required.

Login (no API keys)

You must complete Claude CLI login on the same host/container where n8n runs so the CLI can reuse its session.

Browser login from n8n (Start + Complete)

Use Claude Auth (CLI) in two steps so you can send the URL via your workflow:

  1. Browser Login (Start): returns loginUrl + loginSessionId + loginConfigDir (defaults to Claude.ai Login)
  2. Send loginUrl with your preferred messaging node
  3. After login, copy the full redirect URL from the browser (https://console.anthropic.com/oauth/code/callback?...)
  4. Browser Login (Complete): pass the callback URL and loginSessionId to store the OAuth tokens

If you only have the authorization code, you can paste it into Authorization Code. If it is shown as code#state, you can paste the whole value (the node will extract both).

Notes:

  • To force a fresh login (even if you are already logged in), enable Use Temporary Config Directory or set Login Config Directory Override to a new empty folder. Pass the returned loginConfigDir into Browser Login (Complete) so it uses the same location.
  • Enable Use Claude.ai Login if you want the login page hosted on claude.ai.
  • Browser Login (Single Node) performs the Start step only; use Complete to finish.

Check login status in n8n

Use Claude Auth (CLI) with Login Status to verify the stored tokens. The node will reuse saved profile data and auto-fetch account info if missing. Enable Check Remote Profile to always validate tokens with Anthropic, and Fail If Not Logged In if you want the workflow to stop when no session is available.

Automatic token refresh

New in v1.1.0: OAuth tokens are now automatically refreshed in the background!

  • Tokens are renewed automatically when 75% of their lifetime has elapsed (25% remaining)
  • The background service checks every 5 minutes and refreshes when needed
  • Works after n8n server restarts (the service resumes on the first node execution)
  • No manual workflows required - it just works!
  • Uses file locking to prevent concurrent refresh attempts
  • Includes automatic retry with exponential backoff on failures

The service starts automatically when:

  • You complete a browser login (Browser Login Complete)
  • You manually refresh a token (Refresh Token operation)
  • You use the Claude Chat Model node

Manual token refresh (optional)

For advanced use cases, you can still manually refresh tokens using Claude Auth (CLI) with Refresh Token. This can be useful for:

  • Testing token refresh behavior
  • Forcing an immediate refresh outside the automatic schedule
  • Custom refresh logic in specific workflows

The node returns tokenExpiresAt so you can monitor token expiration if needed.

Options:

  • Use Claude.ai Login is enabled by default to ensure the user:inference scope required by the CLI.
  • Fetch Profile After Refresh (default: true) updates account info after refresh.
  • Include Tokens In Output is off by default for safety.

Optional: Login with the CLI

If you prefer to log in from the host:

node node_modules/@anthropic-ai/claude-agent-sdk/cli.js

Or, if you have a claude executable installed:

claude

The CLI will store its session in ~/.claude (or your CLAUDE_CONFIG_DIR).

Optional: Long-lived OAuth token

If you prefer a long-lived OAuth token (still no API keys), run:

claude setup-token

Then set the token on the n8n host:

export CLAUDE_CODE_OAUTH_TOKEN=<token>

Using the Claude Chat Model

  1. Add an AI Agent node
  2. Select Claude Chat Model (CLI) as the chat model
  3. Choose your Claude CLI credentials
  4. Configure Model and Options as needed

Options quick reference

  • Working Directory and Additional Directories for tool access
  • Permission Mode and Dangerously Skip Permissions
  • Tools / Allowed Tools / Disallowed Tools to control built-in CLI tools
  • Max Budget (USD) and Fallback Model
  • Settings (JSON or File Path) for CLI config overrides
  • No Session Persistence for stateless runs
  • Stream Response for streaming tokens

Example workflow: Telegram chatbot

A simple flow that turns Telegram messages into Claude responses:

  1. Telegram Trigger (incoming message)
  2. AI Agent using Claude Chat Model (CLI)
  3. Telegram node (Send Message)

Typical mappings:

  • AI Agent input: use Telegram message.text (for example, {{$json.message.text}})
  • Telegram response: map the AI Agent output text

Troubleshooting

Node does not appear in n8n

  • Verify install: npm list @chrishdx/n8n-nodes-claude-cli
  • Restart n8n
  • Check n8n logs for load errors

CLI execution fails

  • Verify the Claude CLI source (Bundled vs Custom Path)
  • Check the CLI manually: claude --version or node node_modules/@anthropic-ai/claude-agent-sdk/cli.js --version
  • Ensure the login happened on the same host/container as n8n

Login issues

  • Use Browser Login (Start) + Browser Login (Complete) for a multi-step flow (no terminal)
  • Ensure the callback URL includes code and state (copy it from the browser address bar)
  • If you see code#state, paste the entire value into Authorization Code or provide the state separately
  • If Login Status shows missingScopes with user:inference, re-run Browser Login (Start) with Use Claude.ai Login enabled
  • Make sure Login Session ID and Login Config Directory match between Start and Complete
  • Use Use Temporary Config Directory to force a clean login when testing
  • Use Login Status with Check Remote Profile to verify stored tokens

Automatic token refresh issues

The automatic token refresh service logs to the console. Check your n8n logs for messages starting with [TokenRefresh]:

  • Service not starting: Ensure at least one Claude node (Auth or Chat Model) executes after n8n starts
  • Refresh failures: Check logs for error messages; the service retries automatically with exponential backoff
  • Multiple n8n instances: If running multiple n8n servers with shared credentials file, file locking prevents conflicts
  • Tokens not refreshing: Verify that issuedAt timestamp exists in ~/.claude/.credentials.json (requires v1.1.0+ login)
  • Check service status: Look for [TokenRefresh] Service started for config: <path> in logs

To monitor the service:

# View n8n logs for token refresh events
tail -f ~/.n8n/logs/n8n.log | grep TokenRefresh

Common log messages:

  • Service started for config: ~/.claude - Service initialized successfully
  • Token refresh needed (75% lifetime elapsed) - Automatic refresh triggered
  • Token refreshed successfully - Refresh completed
  • Refresh attempt X failed - Temporary error, will retry automatically

License

MIT

Support

  • GitHub Issues: https://github.com/chrishdx/n8n-nodes-claude-cli/issues
  • n8n Community Forum: https://community.n8n.io

Acknowledgments

  • Built on the n8n community nodes starter
  • Powered by LangChain
  • Uses the official @anthropic-ai/claude-agent-sdk