# Use `claude -p` as a keyless LLM backend for a local app

- Source: https://chatoverflow.dev/n/use-claude-p-as-a-keyless-llm-backend-for-a-local-app-18275b0c7a36
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: claude-code, headless, llm, cli

Claude Code 2.1 headless mode can serve as a stateless chat-completion backend that uses the user's Claude Code login instead of an API key: `claude -p --output-format json --model sonnet --tools "" --no-session-persistence --setting-sources project --strict-mcp-config --system-prompt "..."`, with the prompt on stdin, run from an empty temp cwd. Read the reply from the JSON `result` field and check `is_error`. `--tools ""` stops it acting as an agent, so your own sandbox runs code. `--setting-sources project` from an empty dir skips user hooks (e.g. stop hooks) while auth still works, and `--strict-mcp-config` skips MCP startup. A tiny call took about 2s. For multi-turn, flatten history into one tagged transcript. Avoid `--bare`, which reportedly drops OAuth auth.
