Claude Code hangs in your CI job waiting for input. Which change fixes it and also gives you machine-readable findings?
Why C is the answer
Run it with -p and use --output-format json with --json-schema
-p runs non-interactively, and the JSON flags produce structured output your pipeline can post as inline comments.
In detail
- Claude Code in interactive mode waits for a person, and a CI job has no person. The -p flag runs it non-interactively and exits with a status code.
- --output-format json gives your pipeline output it can parse, and --json-schema returns validated data in structured_output.
- Scripted runs can also use --bare, which skips auto-discovery including CLAUDE.md, so that results do not depend on the machine.
- Check the exit code as well, so a failed run fails the job.
Use case
An illustrative scenario, not a real incident.
A pipeline runs a review step that stops at a prompt and times out after an hour. Running claude -p with a JSON schema finishes on its own and returns findings that a script posts as pull request comments.
See it in different ways
flowchart LR
A["CI job"] --> B["claude -p with JSON output"]
B --> C{"Exit code"}
C -->|"0"| D["Parse the result"]
C -->|"Non-zero"| E["Fail the job"]sequenceDiagram participant CI as CI job participant C as Claude Code participant PR as Pull request CI->>C: claude -p with JSON output C-->>CI: JSON result and exit code CI->>PR: Post the findings
sequenceDiagram participant P0 as CI job participant P1 as Claude Code participant P2 as Pull request P0->>P1: claude -p with a JSON schema P1-->>P0: Validated findings and exit code P0->>P2: Post inline comments
Key point: CI needs -p for no prompts, and a schema for output it can parse.
Why the other options are wrong
- A. Add a CLAUDE.md rule telling it never to ask questions and to print JSON
- A rule in CLAUDE.md changes what Claude tries to do. It does not switch off interactive mode or guarantee the format.
- B. Pipe "yes" into the process so every prompt is accepted automatically
- This blindly accepts every prompt, and it still gives you no structured result.
- D. Increase the CI job timeout to an hour and parse the terminal output
- A longer timeout just means it hangs for longer, and terminal text is a poor format to parse.

