> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thinkplatform.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Choose User guide for browser tasks, Developers for CLI, SDK and external agents, and Administration for organization management.
> Confirm identity and organization/project context before operations. Documentation access does not grant ThinkPlatform permissions.
> Review side effects, verify changes with a read, and do not blindly retry an operation with an uncertain outcome.
> Use documented UI steps for the web app and documented public CLI or SDK interfaces for automation. Follow each page’s prerequisites and authentication requirements.

# Capture CLI output in a script

> Check exit status, preserve diagnostics, and consume structured read results.

Complete [installation](https://docs.thinkplatform.ai/cli/get-started/installation.md), [authentication](https://docs.thinkplatform.ai/cli/get-started/authentication.md), and [context selection](https://docs.thinkplatform.ai/cli/guides/context.md) before running unattended reads. Prepare the profile in advance; authentication can require user interaction. This guide shows how to capture a Canvas page inventory for another program.

## Check context, then capture a read

```bash theme={"system"}
tp context show
```

Confirm the active profile, organization and project. These examples use that saved context. Add `--json` when another program needs to parse the result, then run this shell script:

```bash theme={"system"}
if tp --json canvas pages list --fields id,title,updatedAt > pages.json 2> pages.err; then
  python3 -c 'import json; pages=json.load(open("pages.json")); print("Pages:", len(pages))'
else
  cat pages.err >&2
  exit 1
fi
```

Successful ordinary JSON commands write their result to stdout and exit `0`. This list is an array, so the script parses it before using it. On failure, treat `pages.json` as unusable even if it exists or contains some data. Keep stderr separate so diagnostics cannot corrupt JSON input.

Handled authentication, API, context, and value errors exit `1`. With `--json`, these handled errors are JSON objects on stderr with `ok: false` and `error`; API errors may also include `status_code` and `response_body`. Command syntax errors generally exit `2` and may be plain text. Do not assume every failure is JSON, or print diagnostics containing sensitive server details into public logs.

## Select a known field

For a program needing just the effective project ID:

```bash theme={"system"}
tp --json --query project_id context show
```

Global `--query` is a narrow output path selector: it supports keys, dotted fields, and nonnegative list indices, such as `items[0].id`. It is not JMESPath and does not support filters, wildcards, or arbitrary expressions. Missing keys and invalid indices fail; check that an array is nonempty before selecting its first item. JSON strings remain JSON strings, including quotes.

## Handle each command's output contract

`--json` is a global option placed before the command. It does not turn every command into one JSON document. Canvas JSONL exports and row queries with `--format jsonl` produce one record per line; Markdown exports produce text; job log streaming produces streamed content. Downloads and other file-oriented commands also need their own contract. Inspect command help and the [command reference](https://docs.thinkplatform.ai/cli/reference/commands.md) before piping output to a JSON parser.

There is no universal `--yes`, `--non-interactive`, or `--dry-run` option. Use only options advertised by the specific command. Some write commands provide previews; an API preview may still fetch OpenAPI, and a Canvas update preview may read the current page. Verify actual stored state after a write.

Local `--limit` and `--offset` options often slice a fetched collection. They do not establish that all backend pages were fetched. Record which slices you processed and account for concurrent changes. Interrupted exports or streams can leave partial files; check completion and exit status before promoting them to downstream inputs.

A timeout does not prove a mutation failed. Read the resource and reconcile its state before retrying a create, append, or delete. Use bounded retries only when the operation's semantics make repetition safe; do not add a blanket mutation retry loop. Follow [execution workflows](https://docs.thinkplatform.ai/cli/guides/execution.md) to monitor remote work and [troubleshooting](https://docs.thinkplatform.ai/cli/guides/troubleshooting.md) to diagnose failures. For longer workflows with typed results and explicit error handling, use the [Python SDK](https://docs.thinkplatform.ai/python-sdk/overview.md) and its [error guidance](https://docs.thinkplatform.ai/python-sdk/errors.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.