Scripting & CI
polyglot -p (or --print) runs a single prompt, prints the answer to stdout, and
exits - no TUI.
polyglot -p "explain what src/agent/loop.ts does"echo "summarize the README" | polyglot -p # prompt from stdinpolyglot -p --output-format json "list the tools" # machine-readable@ mentions work here too: @<path> inlines a file,
@<agent> <task> runs an agent definition, and a @<skill>
token activates a skill for the run.
Output
Section titled “Output”-
--output-format text(default) streams the assistant’s reply to stdout. Tool activity goes to stderr, so a piped stdout stays clean. -
--output-format jsonemits a single object instead:{"result": "...","session_id": "...","is_error": false,"stop_reason": "done","persisted": true,"cost_usd": 0.0123,"tokens": { "input": 4210, "output": 380 },"reliability": { "tool_calls": 6, "repaired": 1, "parse_errors": 0, "gave_up": 0 },"fell_back_to": []}cost_usdis the estimated cost of the run (0for an unpriced/local model, seepricing);tokensis the cumulative provider token count.reliabilitycounts the run’s tool calls, how many needed repair, how many failed to parse, and whether the model was abandoned as unreliable (gave_up > 0, which also givesstop_reason: "unreliable_model") - useful for gating a model in CI.fell_back_tolists any models a failover switched to during the run (usually empty).
The session id is also written to stderr as session: <id>, so runs can be chained:
sid=$(polyglot -p --output-format json "start the analysis" | jq -r .session_id)polyglot --resume "$sid" -p "now write it up as a report"Permissions in -p mode
Section titled “Permissions in -p mode”There’s no TTY to show approval prompts, so any write / execute / network tool that would need approval is denied, and the model is told so. For automation, choose one:
- set
permissions.modetoauto(insettings.jsonorPOLYGLOT_PERMISSION_MODE), - pass
--permission-mode auto, - add
allowrules for the specific tools/commands you trust, - or pass
--allow-allto run every tool without prompting.
Hooks still run in -p mode - a userPromptSubmit hook that
blocks makes the run exit non-zero with stop_reason: "hook_blocked" in the JSON
envelope, and a preToolUse hook can gate individual tool calls even under
--allow-all. Secret scanning applies too.
CI example
Section titled “CI example”- run: npm install -g @usepolyglot/cli- run: polyglot -p --allow-all --output-format json "review the diff in this PR for obvious bugs" > review.json env: POLYGLOT_PROVIDER: anthropic ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} POLYGLOT_MODEL: claude-sonnet-4-5Consider --no-persist in CI so nothing is written to ~/.polyglot/ on the runner -
see Running offline and
Data handling.