Skip to content

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:

CommandBest forOutput modes
kompile execQuick 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 ​

TaskclaudeopencodecodexKompile
One-shot promptclaude -p "..."opencode run "..."codex exec "..."kompile exec "..."
Pipe stdincat f | claude -p "..."cat f | opencode runcat f | codex exec -cat f | kompile exec (or kompile exec -)
Streaming JSONLclaude -p "..." --output-format stream-jsonopencode run --format json "..."codex exec --json "..."kompile exec --json "..." (or kompile chat --prompt "..." --output-format stream-json)
Final text onlyclaude -p "..." --output-format textopencode run "..."codex exec -o out.md "..."kompile exec -q "..." (or --output-last-message out.md)
Continue last sessionclaude -c -p "..."opencode run -c "..."codex exec resume --last "..."kompile exec -c "..."
Resume specific sessionclaude -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 -):

bash
# 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 to stdout with no ANSI chrome; tool activity and progress messages go to stderr.
  • QUIET (-q / --quiet): suppresses tool/progress output and prints only the final assistant response text to stdout.
  • JSON (--json / --output-format stream-json): emits one self-contained JSON object per line to stdout; diagnostic chrome stays on stderr.

kompile exec options ​

FlagDefaultDescription
PROMPT...(stdin)Prompt text joined with spaces. Omit (or pass -) to read from stdin.
--jsonfalseEmit an ordered JSONL event stream to stdout.
-q, --quietfalsePrint 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, --continuefalseContinue 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>coderLocal agent profile to run.
--model <id>(saved)Override the configured model for this run.
-C, --cwd <dir>current dirWorking 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:

bash
# 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-json

Unified 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:

bash
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-json

Supported headless passthrough agents: claude, codex, gemini, qwen, opencode, pi, and agy (antigravity).

Additional headless flags on kompile chat ​

FlagDescription
--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-memoryDisable RAG or persistent memory injection for isolated CI runs.
--dangerously-skip-permissionsAuto-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 ​

json
{"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 ​

typeKey fieldsWhen emitted
sessionsession_id, model, cwd, optional "rag", "memory", "workflow"Once at start with effective non-secret configuration
backendsession_id, agent, process_idPassthrough runs when the underlying CLI subprocess starts
titlesession_id, titleWhen Kompile generates a title for the new session
thinkingtextDisplay-only model reasoning delta (never concatenated into the final answer)
texttextStreamed assistant text delta
tool_startcall_id, name, optional input, detailWhen a tool call begins
tool_outputcall_id, name, detailBounded live snapshot while a long-running tool is still executing
toolcall_id, name, ok, ms, optional detailWhen a tool call completes (with duration and structured presentation)
usageinput_tokens, output_tokens, cache_read_tokens, cache_creation_tokensProvider-reported token counts
"sources" / "stats""sources" / "stats"Grounding sources or summary metrics when produced
resulttext, session_id, tools, exitTerminal event on completion (includes full final text and tool count)
errormessage, exitTerminal event on fatal error
detachedsession_id, messageWhen a run detaches cleanly while background work continues

4. Practical Shell & CI Recipes ​

Extract live text as it streams (jq) ​

bash
kompile exec --json "Explain the build graph in pom.xml" \
  | jq -r --unbuffered 'select(.type == "text") | .text' -j

Log every tool call and its latency ​

bash
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 ​

bash
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 ​

bash
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 codeMeaning
0Turn completed cleanly
1Runtime, provider, or missing-session failure
2Invalid CLI flags, missing prompt, or incompatible option combination
124Run 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 (command events) 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).

Released under the Apache-2.0 License.