TachEmail r90
Docs / Everyday use / Query from the terminal

Query from the terminal

Build the native query reader, configure your own query key, read usage and Health, and export Answers without a browser.

Built from commit f569b4a on Nov 14, 2026

The native tach reader asks your server for usage and Health. It uses your own query key. A member reads only their own usage. An administrator reads instance usage and Health.

Get the native reader

The native reader is currently a source-build path. These instructions require access to the Tach source and its pinned Rust toolchain. They do not assume a public binary download.

From the repository root:

CARGO_BUILD_JOBS=2 cargo build --manifest-path portable/Cargo.toml --release --locked --bin tach
portable/target/release/tach --help

The examples below use portable/target/release/tach to distinguish this reader from the VM’s maintenance command, also named tach. The current query installer supplies a different reader and does not install this native binary.

Configure your query key

Create a Query key on Keys. Set TACH_QUERY_URL to https://YOUR_DOMAIN/v1/query and TACH_QUERY_KEY to that key in your secret-aware environment.

Alternatively, create ~/.config/tach/config.json with these fields. Replace the placeholders privately:

{"query_url":"https://YOUR_DOMAIN/v1/query","query_key":"YOUR_QUERY_KEY"}

On Unix, the file must be regular, owned by your user and have no group or other permissions. Set its mode to 600. TACH_CONFIG selects another path. Each environment value overrides its corresponding file value. With both environment values present, the reader never opens the file.

On systems where file ownership cannot be verified, use both environment variables.

Ask a usage question

portable/target/release/tach query --by model
portable/target/release/tach query --by user,model --sort cost
portable/target/release/tach query --source claude_code --by session --limit 50
portable/target/release/tach query --by model --json
portable/target/release/tach query --by model --csv

The default window is the 30 days ending now. For another window, pass real RFC 3339 timestamps with offsets to --from and --to. The start is inclusive and the end exclusive. The window must be positive and at most 30 days.

Flag Values or default
--by session, user, source, model, day, machine, provider, billing, or tag:Category. Default session. At most two distinct dimensions, with no Session pair.
--from, --to RFC 3339 instants. Defaults: 30 days ago and now.
--user, --source, --provider, --model Filter by identity.
--machine Filter by machine UUID.
--session Literal session prefix. Requires --source.
--billing usage_billed or subscription_notional.
--tag Category=Value, once per category. Category=Not set selects an absent assignment.
--limit, --offset 1 to 1000 rows, and a nonnegative row offset. Defaults: 50 rows for Session, otherwise 1000, with offset 0.
--sort tokens, cost, events or dim. Default tokens.
--include-inactive-people Include active registered people without usage. Requires --by user and only user or tag filters. The flag does not mean deactivated accounts.
--tokens Token-only table view. Cannot combine with JSON or CSV.
--json, --csv Choose one output format. Without either, output is a table.
--help, -h Show help.

Tag grouping and filters use current assignments. The Answer’s tag evidence records the assignment time and changes. The CLI does not create or edit tags.

Read pages and exports

--json preserves the complete Answer document, including its evidence. CSV contains rows without the query metadata. Missing costs remain null in JSON and blank in CSV. A table shows a dash for an unknown cost.

Each invocation returns one requested page. Read later pages with --offset. full_count and evidence still describe every matching event. A CSV invocation is one page, while the web Report’s export downloads every page.

Check Health

An administrator’s query key is required:

portable/target/release/tach health --json
portable/target/release/tach health --days 7 --threshold 3
portable/target/release/tach health --help

--days sets the dropped-event and price-check window, from 1 to 30, default 7. --threshold sets business days without usage before silence, from 1 to 30, default 3. The reader derives the Health URL from the configured query URL.

Exit Query Health
0 Read succeeded. No critical or warning problem is open.
1 Read failed. Read failed.
2 Command or configuration is invalid. Command or configuration is invalid.
3 Not used. A critical or warning problem is open.

For failed keys and request classes, see Troubleshooting.

Enter to openEsc to close