Headless & Streaming Mode (kompile exec & stream-json)
Kompile supports non-interactive, pipe-friendly streaming execution for scripts, CI pipelines, editor integrations, and automation — comparable to claude -p, opencode run, and codex exec, while preserving Kompile's MCP tools, Enforcer, persistent memory, and session transcripts.
You have two entry points backed by the same streaming engine:
| Command | Best for | Output modes |
|---|---|---|
kompile exec | Quick one-shot prompts, stdin piping, and shell scripts (uses your saved chat defaults) | Default text, -q / --quiet, --json (JSONL) |
kompile chat --prompt ... | Full overrides (--provider, --auth, --thinking, --attachment, --role, --workflow) or passthrough streaming over claude, codex, opencode, gemini, agy, pi, or qwen | --output-format text, --output-format stream-json (or --json) |
Watch Out for -p on kompile chat
Unlike claude -p, on kompile chat the short flag -p is --port. Always pass --prompt "..." (or positional prompt arguments) to kompile chat, or use kompile exec "...".
Quick Comparison With Other Agent CLIs
| Task | claude | opencode | codex | Kompile |
|---|---|---|---|---|
| One-shot prompt | claude -p "..." | opencode run "..." | codex exec "..." | kompile exec "..." |
| Pipe stdin | cat f | claude -p "..." | cat f | opencode run | cat f | codex exec - | cat f | kompile exec (or kompile exec -) |
| Streaming JSONL | claude -p "..." --output-format stream-json | opencode run --format json "..." | codex exec --json "..." | kompile exec --json "..." (or kompile chat --prompt "..." --output-format stream-json) |
| Final text only | claude -p "..." --output-format text | opencode run "..." | codex exec -o out.md "..." | kompile exec -q "..." (or --output-last-message out.md) |
| Continue last session | claude -c -p "..." | opencode run -c "..." | codex exec resume --last "..." | kompile exec -c "..." |
| Resume specific session | claude -r <id> -p "..." | opencode run -s <id> "..." | codex exec resume <id> "..." | kompile exec -r <id> "..." |
| Run another CLI behind one JSONL schema | — | — | — | kompile chat --mode passthrough --agent claude --prompt "..." --output-format stream-json |
1. Quick Start With kompile exec
kompile exec reads your prompt from positional arguments or from stdin (when no arguments are given, or when the single argument is -):
# Stream raw assistant text to stdout (tool & progress activity goes to stderr)
kompile exec "Summarize the architecture of src/auth/"
# Pipe a diff or log file on stdin
git diff main | kompile exec "Review this diff for regressions and edge cases"
cat build.log | kompile exec -
# Quiet mode: print only the final answer to stdout (suppress stderr progress)
kompile exec -q "List every public REST endpoint in this repo" > endpoints.md
# Stream ordered JSONL events (NDJSON) for scripts and CI parsers
kompile exec --json "Count the Java modules and check for circular deps"
# Also save the final response to a file while streaming
kompile exec --output-last-message review.md "Audit src/auth/ for token refresh races"
# Continue the most recent session, or resume a specific session ID
kompile exec -c "Now write a regression test for finding #1"
kompile exec -r exec-a1b2c3d4 "Run the unit test and confirm it passes"Clean stdout / stderr separation
Kompile separates streams intentionally so shell pipelines never get polluted by spinners or ANSI formatting:
TEXT(default): raw assistant text deltas stream directly tostdoutwith no ANSI chrome; tool activity and progress messages go tostderr.QUIET(-q/--quiet): suppresses tool/progress output and prints only the final assistant response text tostdout.JSON(--json/--output-format stream-json): emits one self-contained JSON object per line tostdout; diagnostic chrome stays onstderr.
kompile exec options
| Flag | Default | Description |
|---|---|---|
PROMPT... | (stdin) | Prompt text joined with spaces. Omit (or pass -) to read from stdin. |
--json | false | Emit an ordered JSONL event stream to stdout. |
-q, --quiet | false | Print only the final response text; suppress stderr progress (cannot combine with --json). |
--output-last-message <file> | — | Also write the final assistant response text to <file>. |
-c, --continue | false | Continue the most recent saved session with its history restored. |
-r, --resume <id> | — | Resume a specific session by ID or transcript UUID. |
--session-id <id> | exec-<8hex> | Pin an explicit session ID for transcript persistence and later resume. |
--agent <name> | coder | Local agent profile to run. |
--model <id> | (saved) | Override the configured model for this run. |
-C, --cwd <dir> | current dir | Working directory for tools, config, and transcript metadata. |
--timeout <seconds> | 0 (none) | Cancel and exit with code 124 if the run exceeds <seconds>. |
(Because headless runs cannot prompt a TTY, kompile exec auto-approves tool permissions while keeping Enforcer policies, resource policies, and project rules active.)
2. Full Streaming Mode With kompile chat
Whenever you need provider/auth/effort overrides, file attachments, roles, workflow teams, or managed passthrough streaming across external agent CLIs, invoke kompile chat non-interactively.
Headless mode activates automatically whenever you supply --prompt, positional PROMPT / -, --output-format, or --json:
# Direct provider + model + reasoning effort override with JSONL streaming
kompile chat \
--provider openai --auth oauth --model gpt-5.6-sol --thinking high \
--prompt "Audit src/auth for token refresh races" \
--output-format stream-json
# Attach files to a direct-model headless turn
kompile chat \
--attachment design-spec.md --attachment error.log \
--prompt "Explain why the retry loop diverges from the spec" \
--output-format stream-json
# Assign a custom role or workflow team and cap runtime
kompile chat \
--role security-reviewer \
--timeout 300 \
--output-last-message audit.md \
--prompt "Review the OAuth callback handler"
# Resume an existing conversation onto a different vendor headlessly
kompile chat \
--resume <session-id> \
--provider openrouter --model anthropic/claude-sonnet-4-5 \
--prompt "Continue from the last checkpoint and finish the test suite" \
--output-format stream-jsonUnified stream-json Across External Agent CLIs (Passthrough)
Kompile can also run managed external CLIs non-interactively through the exact same stream-json JSONL envelope, injecting Kompile's MCP tools, memories, reminders, and exact native session resume:
kompile chat --mode passthrough --agent claude --prompt "Summarize recent commits" --output-format stream-json
kompile chat --mode passthrough --agent codex --prompt "Summarize recent commits" --output-format stream-json
kompile chat --mode passthrough --agent opencode --prompt "Summarize recent commits" --output-format stream-json
kompile chat --mode passthrough --agent agy --prompt "Summarize recent commits" --output-format stream-jsonSupported headless passthrough agents: claude, codex, gemini, qwen, opencode, pi, and agy (antigravity).
Additional headless flags on kompile chat
| Flag | Description |
|---|---|
--prompt <text> | Prompt text for a non-interactive turn (alternative to positional PROMPT or stdin -). |
--output-format <text|stream-json> | Output mode (json and jsonl are accepted aliases for stream-json; --json is shorthand). |
--provider, --auth, --model, --thinking (--effort) | Override the provider route, auth method, model, or reasoning effort for this run. |
--mode <standard|passthrough> & --agent <name> | Run Kompile's standard agent or a managed external CLI headlessly. |
--attachment <file> | Attach a file to a direct-model turn (repeatable). |
--working-dir <dir> | Project directory for config, tools, and transcript metadata. |
--role <name> / --workflow <team> | Apply a saved role persona or multi-agent workflow team. |
--no-rag / --no-memory | Disable RAG or persistent memory injection for isolated CI runs. |
--dangerously-skip-permissions | Auto-approve all standard-chat tool permissions without prompting. |
--output-last-message <file> / --timeout <seconds> | Write final assistant text to a file / enforce a hard wall-clock timeout. |
3. The stream-json JSONL Event Protocol
With --json or --output-format stream-json, every line on stdout is a single JSON object with a monotonically increasing seq number (assigned by Kompile's publisher so interleaved model tokens and tool callbacks stay strictly ordered) and a type discriminator.
Sample stream
{"seq":1,"type":"session","session_id":"exec-9f2a1c4b","model":"claude-sonnet-4-5","cwd":"/repo"}
{"seq":2,"type":"tool_start","call_id":"call_1","name":"grep","input":"refreshToken"}
{"seq":3,"type":"tool","call_id":"call_1","name":"grep","ok":true,"ms":42}
{"seq":4,"type":"text","text":"Found two race conditions in "}
{"seq":5,"type":"text","text":"TokenRefresher.java..."}
{"seq":6,"type":"usage","input_tokens":4120,"output_tokens":380,"cache_read_tokens":2800,"cache_creation_tokens":0}
{"seq":7,"type":"result","text":"Found two race conditions in TokenRefresher.java...","session_id":"exec-9f2a1c4b","tools":1,"exit":0}Event types
type | Key fields | When emitted |
|---|---|---|
session | session_id, model, cwd, optional "rag", "memory", "workflow" | Once at start with effective non-secret configuration |
backend | session_id, agent, process_id | Passthrough runs when the underlying CLI subprocess starts |
title | session_id, title | When Kompile generates a title for the new session |
thinking | text | Display-only model reasoning delta (never concatenated into the final answer) |
text | text | Streamed assistant text delta |
tool_start | call_id, name, optional input, detail | When a tool call begins |
tool_output | call_id, name, detail | Bounded live snapshot while a long-running tool is still executing |
tool | call_id, name, ok, ms, optional detail | When a tool call completes (with duration and structured presentation) |
usage | input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens | Provider-reported token counts |
"sources" / "stats" | "sources" / "stats" | Grounding sources or summary metrics when produced |
result | text, session_id, tools, exit | Terminal event on completion (includes full final text and tool count) |
error | message, exit | Terminal event on fatal error |
detached | session_id, message | When a run detaches cleanly while background work continues |
4. Practical Shell & CI Recipes
Extract live text as it streams (jq)
kompile exec --json "Explain the build graph in pom.xml" \
| jq -r --unbuffered 'select(.type == "text") | .text' -jLog every tool call and its latency
kompile exec --json "Fix the failing unit test in kompile-cli-main" \
| jq -r --unbuffered 'select(.type == "tool") | "\(.name)\tok=\(.ok)\t\(.ms)ms"'Capture final text and session ID in a CI job
OUT=$(mktemp)
kompile exec --json --timeout 600 --output-last-message review.md \
"Review PR changes against docs/architecture/app-persona-boundary.md" > "$OUT"
STATUS=$?
SESSION_ID=$(jq -r 'select(.type == "result") | .session_id' "$OUT")
TOOLS_USED=$(jq -r 'select(.type == "result") | .tools' "$OUT")
echo "Exit=$STATUS Session=$SESSION_ID Tools=$TOOLS_USED"Chain a multi-step scripted workflow in one session
SID="ci-audit-$(date +%s)"
kompile exec --session-id "$SID" --quiet "Identify the top 3 flaky tests in this repo" > findings.md
kompile exec --resume "$SID" --quiet "Write a minimal patch for finding #1 and run the test"5. Exit Codes
| Exit code | Meaning |
|---|---|
0 | Turn completed cleanly |
1 | Runtime, provider, or missing-session failure |
2 | Invalid CLI flags, missing prompt, or incompatible option combination |
124 | Run exceeded --timeout <seconds> and was cancelled |
6. Persistent Bidirectional Protocols (Web Harness & Editors)
If you are building a rich UI or editor integration rather than a one-shot CLI script, Kompile also exposes two bidirectional streaming protocols over stdio:
- Live JSONL control stream (
--input-format web-json --output-format stream-json --web-controls): Used internally by the Web Harness to stream prompts, mid-turn cancellations, and slash-command outcomes (commandevents) over a single JSONL connection. - Agent Client Protocol (
kompile acp/kompile chat --acp): Standard ACP v1 stdio JSON-RPC server for editors such as Zed, JetBrains IDEs, Neovim, and Emacs. See ACP v1 (Server & Client).
Related Guides
- Chat & Harness — Interactive
kompile chat, vendor switching, and configuration. - Hands-On Guide to Subagents — Delegating parallel work (
task,multi_task,quorum_task) inside a session. - Import, Resume & Vendor Switching — Resuming headless or interactive sessions across any vendor.
- MCP Tools & Reference — Every tool available to headless and interactive runs.