Skip to content

Headless and pipe mode

You can run asksh non-interactively in scripts, CI pipelines, and Unix pipes without launching the TUI.

When pipe mode activates

asksh enters headless pipe mode whenever any of these is true:

  • You pass -p or --pipe.
  • You pass -x or --exec.
  • You pass --json.
  • Standard input is not a TTY (for example data piped via |) and --hook is not set.

Piping standard input

When standard input is not a TTY, asksh reads up to 64 KB (65536 bytes), trims cleanly at a UTF-8 boundary, and appends \n[stdin truncated to 64KB] if the input exceeded 64 KB.

The stdin content is sent alongside your prompt:

journalctl -u greendale-api -n 100 | asksh -p "summarize the root cause of any errors"
git diff | asksh -p "write a concise one-line commit subject"

Headless runs never resume an earlier interactive session.

Executing suggested commands (-x / --exec)

Pass -x (or --exec) to run the command the model suggests via suggest_command:

asksh -x "find all .log files in /var/log/greendale older than 14 days and print their sizes"

asksh runs the suggested command on the active --target and prints its stdout and stderr.

Safety and permissions in pipe mode

  • High-danger refusal: -x refuses to run any command rated high danger (by the model or by AST preflight) unless you also pass --yolo (or set yolo = true in config.toml). low and medium danger commands run without prompting.
  • Tool approvals: Because there is no interactive TUI in pipe mode, any tool call that evaluates to Ask under permissions.toml is automatically denied unless allowed by a rule or bypassed with --yolo.
  • Proposed plans: If the model returns propose_plan, headless mode formats the plan as plain text and does not execute its steps.
  • Turn limit: Headless mode caps multi-turn tool loops at 64 turns.

Structured JSON output (--json)

Add --json to emit a single JSON object containing the answer, suggested command, danger rating, AST preflight findings, execution status, and tool call count:

asksh --json "check which process is listening on port 8080" | jq '{command, danger}'

See the inline reference for the exact JSON fields.

Exit codes in headless mode

asksh exits 1 on errors such as missing config, LLM request failures, invalid target URIs, or a refused high-danger command under -x.

Child command exit codes under -x

When -x executes a suggested command and that command exits non-zero, asksh captures the child exit code in the --json exit_code field and still exits 0. In scripts that check child success, combine -x --json and inspect .exit_code (and .executed).