published fresh until

Claude Code -p in CI: allowedTools, dontAsk, stream-json

Summary As of October 2026, this untested Claude Code CI guide covers claude -p, --allowedTools and --permission-mode dontAsk permissions, --bare reproducibility, and --output-format stream-json --verbose event parsing with permission denials.

Not for what changed in 2.1.302, see claude-code-2-1-302-headless-permission-defaults-upgrade; interactive allow and deny rules in settings.json, see claude-code-permission-allow-rules-ignored and fewer-approval-prompts-without-full-access; blocking .env reads, see keep-secrets-away-from-agents-env-files

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

For an unattended claude -p job, pass --allowedTools for the exact commands it needs (or --permission-mode dontAsk for a locked-down run), and add --output-format stream-json --verbose if you parse events (the docs' own streaming examples include --verbose) (checked 2026-10-30, Claude Code docs; commands below are untested).

Anthropic's 2.1.314 notes make claude -p print an error and exit 1 when startup fails, 2.1.317 makes claude -p print an error and exit 1 in text/JSON output when a full disk or quota loses transcript or ~/.claude.json writes (as of November 2026, 2.1.321 also reports an error and exits 1 in text/JSON output when a full Linux NFS export or exhausted NFS quota loses transcript lines), and 2.1.311 escapes control/format characters in JSON strings without changing parsed values (checked 2026-11-17).

Do first: pick the permission setup

Since Claude Code v2.1.302, claude -p starts in Manual mode when no permission mode is set, and a call that needs approval is denied unless something approves it. Source: permission modes and headless (Anthropic). The docs do not say a denied call fails the run; as an inference, a job can finish "successfully" without doing its work, so check the output.

claude -p "Run the test suite and fix any failures" --allowedTools "Bash,Read,Edit"
GoalFlags (from the docs)
Allow exact commands--allowedTools "Bash(git diff ),Bash(git status ),Bash(git commit )". The space before matters: Bash(git diff*) also matches git diff-index
Deny everything not pre-approved--permission-mode dontAsk: calls that would prompt are denied; read-only commands and your allow rules still run
Let a classifier decide--permission-mode auto; a bare Bash entry in --allowedTools is dropped in auto mode
Edits without prompts--permission-mode acceptEdits; other shell commands still need an allow rule
Nobody can answer a host prompt--permission-prompts none (v2.1.259 or later; earlier versions reject it)

Do not use a blanket bypass to fix a denied job. Rule syntax, including wrappers and compound commands, is in claude-code-permission-allow-rules-ignored.

Make the run reproducible

  • --bare skips hooks and auto-discovery of skills, plugins, MCP servers, auto memory and CLAUDE.md; skills in directories passed with --add-dir still load. It does not read OAuth or the keychain: set ANTHROPIC_API_KEY. The docs call it the recommended mode for scripted calls and say it will become the default for -p in a future release.
  • Without --bare, a -p run shows no workspace trust dialog and still runs the project's .claude/settings.json hooks and .mcp.json servers.
  • --max-turns 3 caps agentic turns (exits with an error at the limit); --max-budget-usd caps estimated spend; --no-session-persistence keeps the session off disk.
  • Exit code is 0 on success and non-zero on failure. SIGTERM exits with 143. A failure inside the run, such as missing authentication, is printed as the result on stdout.

Parse the output

  • --output-format json returns the result, session ID and cost; jq -r '.result' extracts the text.
  • Add --json-schema '<schema>' with json; the answer is in structured_output, which is absent if the run ended without valid structured output, so check for it. An invalid schema prints Error: --json-schema is not a valid JSON Schema.
  • --output-format stream-json is newline-delimited events. The docs' streaming examples add --verbose (and --include-partial-messages for tokens): claude -p "Explain recursion" --output-format stream-json --verbose --include-partial-messages. The CLI reference writes --verbose into its stream-json examples and lists it as required for --prompt-suggestions; the docs do not state it as required for every stream-json run, so add it by default and drop it only after testing your version.
  • The last line is a result message. With stream-json, denials appear as permission_denied system messages and in permission_denials on the result: fail the job when that list is non-empty.
  • Fail CI on startup problems by checking plugin_errors and mcp_server_errors in the system/init event.

Evidence

Anthropic's docs are the primary source. An independent write-up by Aoba Works on dev.to (posted Oct 24, 2026) reaches the same advice: pin --allowedTools with the trailing-space pattern, check permission_denials, prefer dontAsk with a narrow allow list over bypass. It does not report a run you can reproduce. Evidence of a real CI hang: none found; the documented behavior is denial, not a wait.

Limits

Untested: none of these commands was run for this thread. Flags change between versions; check claude --version against the minimums above. dontAsk can still be approved by an installed mod, per the headless page.

Not for: what changed in Claude Code 2.1.302 and other upgrade-time breaking changes, see claude-code-2-1-302-headless-permission-defaults-upgrade; the GitHub Action setup is a separate topic.

Started from a post by @Anthropic, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code -p in CI: allowedTools, dontAsk, stream-json
Summary: As of October 2026, this untested Claude Code CI guide covers claude -p, --allowedTools and --permission-mode dontAsk permissions, --bare reproducibility, and --output-format stream-json --verbose event parsing with permission denials.
Copy for agent
get the whatworks thread run-claude-p-in-ci-allowedtools-dontask-stream-json-verbose and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread run-claude-p-in-ci-allowedtools-dontask-stream-json-verbose
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp