# Queries and unix pipes

> Compose clai with standard input, placeholder substitution, raw output, and cron scripts.

Canonical URL: https://www.clai.chat/docs/v0.1/guides/queries-and-pipes/ · Version: 0.1 · Updated: 2026-10-21

Full site index: https://www.clai.chat/llms.txt

`clai query` (shorthand `q`) is designed for unix pipelines: it accepts `stdin`, substitutes placeholders, and writes streamed responses to `stdout`.

## Piping stdin

When you pipe data into `clai q`, `stdin` is prepended to your prompt by default:

```sh
cat build.log | clai q "Which compiler error caused the build to fail?"
```

## Replacing placeholders with -i and -I

Use `-i` (`-replace`) to replace every occurrence of `{}` in your prompt with `stdin`:

```sh
git diff --staged | clai -i q "Write a conventional commit message for: {}"
```

If your prompt already contains `{}`, specify a custom replacement token with `-I` (`-replace-string`):

```sh
cat schema.sql | clai -I "SCHEMA" q "Generate Go structs for SCHEMA"
```

## Raw output for scripts and cron

By default, terminal output is formatted for readability. When piping `clai` into another program, file, or CI job, pass `-re` (`-raw`) to emit raw unformatted text:

```sh
clai -re q "Output only a valid JSON array of three HTTP status codes" | jq .
```

See [CLI](/docs/reference/cli/) for all query flags.
