Skip to content
For teams: coding agents on the self-hosted models you're allowed to run - see early access →

Scripting & CI

polyglot -p (or --print) runs a single prompt, prints the answer to stdout, and exits - no TUI.

Terminal window
polyglot -p "explain what src/agent/loop.ts does"
echo "summarize the README" | polyglot -p # prompt from stdin
polyglot -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-format text (default) streams the assistant’s reply to stdout. Tool activity goes to stderr, so a piped stdout stays clean.

  • --output-format json emits 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_usd is the estimated cost of the run (0 for an unpriced/local model, see pricing); tokens is the cumulative provider token count. reliability counts 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 gives stop_reason: "unreliable_model") - useful for gating a model in CI. fell_back_to lists 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:

Terminal window
sid=$(polyglot -p --output-format json "start the analysis" | jq -r .session_id)
polyglot --resume "$sid" -p "now write it up as a report"

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.mode to auto (in settings.json or POLYGLOT_PERMISSION_MODE),
  • pass --permission-mode auto,
  • add allow rules for the specific tools/commands you trust,
  • or pass --allow-all to 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.

- 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-5

Consider --no-persist in CI so nothing is written to ~/.polyglot/ on the runner - see Running offline and Data handling.