Skip to main content
The fastest way to use Claude Code is to run the pre-built cli.js that ships inside the npm package. No build step required.
1

Check your Node.js version

Claude Code requires Node.js 18 or later.
node --version
# Should print v18.x.x or higher
2

Navigate to the repository root

The pre-built cli.js lives at the root of the package, alongside package.json.
cd /path/to/claude-code-source-code
3

Verify the CLI works

node cli.js --version
# → 2.1.88 (Claude Code)
4

Authenticate

Claude Code needs access to the Anthropic API. Use either method:Option 1 — Environment variable (recommended for scripts):
export ANTHROPIC_API_KEY=sk-ant-...
Option 2 — Interactive login:
node cli.js login
The login command walks you through the OAuth flow and stores credentials locally.
5

Run a non-interactive query

Use -p (or --print) to send a single prompt and exit immediately. No interactive session is opened.
node cli.js -p "Hello Claude"
The response is printed to stdout and the process exits.
6

Start an interactive session

Run without any flags to open the interactive REPL:
node cli.js
You’ll see the Claude Code welcome screen. Type your prompt and press Enter. Use /help to list available slash commands.

Key flags

FlagDescription
--version, -vPrint the version string and exit. Zero module loading — the fastest path.
-p, --printNon-interactive mode. Send one prompt, print the response, and exit.
-c, --continueResume the most recent session in the current working directory.
-r, --resume <session-id>Resume a specific session by ID. Optionally pass a search term to filter the interactive picker.
--model <model-id>Override the model used for the main agent loop. Accepts aliases (sonnet, opus, haiku) or full IDs.
--output-format <format>Output format for --print mode: text (default), json, or stream-json.
--max-turns <n>Maximum number of agentic turns in non-interactive mode.
--dangerously-skip-permissionsBypass all permission checks. For sandboxed CI/CD pipelines only.
--add-dir <path>Grant tool access to an additional directory beyond the current working directory.
--allowed-tools <tools...>Comma/space-separated allowlist of tool names (e.g. "Bash(git:*) Edit").
--disallowed-tools <tools...>Comma/space-separated denylist of tool names.
--system-prompt <prompt>Replace the default system prompt with a custom one.
--append-system-prompt <prompt>Append text to the default system prompt.
--mcp-config <file>Load MCP server configurations from a JSON file.
--settings <file-or-json>Load additional settings from a JSON file or inline JSON string.
--bareMinimal mode: skip hooks, LSP, plugins, attribution, and auto-memory. Auth via ANTHROPIC_API_KEY only.
--no-session-persistenceDisable writing session transcripts to disk (only works with --print).

Example: non-interactive query

ANTHROPIC_API_KEY=sk-ant-... node cli.js -p "List all TypeScript files in ./src that export a default function"
The agent runs, executes whatever tools are needed (glob, read, etc.), prints the final answer, and exits.

Example: resume a previous session

# Continue from where you left off in the current directory
node cli.js --continue

# Resume a specific session by ID
node cli.js --resume sess_abc123

Install globally (optional)

If you want to call claude instead of node cli.js:
npm install -g .
claude --version
# → 2.1.88 (Claude Code)
The -p flag puts Claude Code into non-interactive (headless) mode. This is equivalent to the SDK’s QueryEngine path and is well-suited for scripting and automation.

Build docs developers (and LLMs) love