Skip to content
Getting Started Simple

Your First CLI Call

Run Claude in headless mode and get a plain text response

Command

$ "color:#7C5CFC">claude -p "Say exactly: Hello CLI Test" "color:#d97757">--output-format text

Response

Hello CLI Test

Parsing Code

059669">">const { execFileSync } = require(059669059669">">'child_process');
059669">">const output = execFileSync(059669059669">">'claude', [
  059669059669">">'-p', 059669059669">">'Say hello', 059669059669">">'--output-format', 059669059669">">'text'
], { encoding: 059669059669">">'utf-8', timeout: 120_000, env: { ...process.env, CLAUDECODE: 059669059669">">'' } });
console.log(output.trim());

Gotchas

! Set CLAUDECODE='' env var when calling from scripts to prevent nested invocation errors
! The -p flag is required for headless (non-interactive) mode

Related Recipes