---
agent:
  instructions: "Search crawlapi docs via GET /.well-known/search?q={query} (add &format=json or Accept: application/json for JSON)."
  endpoint: "https://docs.crawlapi.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.crawlapi.dev/llms.txt"
---

> Documentation index: https://docs.crawlapi.dev/llms.txt
> Search docs: https://docs.crawlapi.dev/.well-known/search?q={query}
> OpenAPI 3.1 specification: https://docs.crawlapi.dev/openapi.json

# CLI

> Read pages, URL lists, and sites from your terminal with the crawl CLI.

`crawl` is crawlapi's standalone CLI. Read a single page, a list of URLs, or a whole same-host site right from your terminal, pipe clean markdown or JSON to stdout, and branch on clear exit codes in scripts or agents.

> **Connecting an AI coding agent?**
>
> Connect the hosted [MCP server](https://docs.crawlapi.dev/mcp.md) with zero local install, or run `crawl mcp` locally if you want full output from large pages saved to disk.

## Install

**cURL**

```bash
curl -fsSL https://crawlapi.dev/install.sh | sh
```

**Homebrew**

```bash
brew install crawlapi-dev/tap/crawlapi
```

**npm**

```bash
npm i -g crawlapi
```

**PowerShell**

```powershell
irm https://crawlapi.dev/install.ps1 | iex
```

**Cargo**

```bash
cargo install crawlapi --locked
```

The install scripts verify the archive's SHA-256 checksum before unpacking into `~/.local/bin` (Windows: `%LOCALAPPDATA%\crawlapi\bin`, which the script adds to your `PATH`). The install scripts, Homebrew, and npm also install the binary as `crawlapi` in case another `crawl` binary is already on your `PATH`. Run `crawl doctor` to verify your install, key, and API connection.

## Sign in

**Shell**

```bash
crawl login                          # approve this machine in your browser; saves a CLI key
crawl login --no-browser             # print the approval link instead of opening a browser
crawl login --no-wait --json         # non-blocking start/finish for AI agent shells
pbpaste | crawl login --key-stdin    # store an existing key from stdin
export CRAWLAPI_API_KEY=ck_...       # override with an environment variable
```

Credentials stay out of shell history (`crawl` accepts keys via browser login, stdin, or `CRAWLAPI_API_KEY` — never as a flag) and are stored locally in `credentials.toml` with owner-only permissions. Your active key is never echoed in output, errors, or debug logs.

> **CLI key vs scrape key**
>
> `crawl login` mints a `cli`-scoped key that works for every command, including `crawl keys` and `crawl billing`. Keys created in the dashboard or by `crawl keys create` are `scrape`-scoped: they run scrapes, `crawl account`, `crawl usage`, `crawl requests`, and `crawl doctor`.

## Read a page

**Shell**

```bash
crawl example.com                          # markdown on stdout
crawl news.ycombinator.com -f json         # structured object, tables, JSON-LD, embedded state
crawl news.ycombinator.com --links         # page links, one per line
crawl news.ycombinator.com --links --json  # compact JSON with links and usage
crawl example.com --json | jq .usage       # full API response: data, usage, request_id
crawl example.com -o pages/example.md      # write to a file (-o - writes stdout)
crawl example.com -t 60s                   # custom timeout (1s-60s, default 30s)
```

`-f` picks `markdown` (default) or `json`. `--json` prints the full API response envelope on both success and failure. Global flags (`--json`, `-q`, `--no-color`) work anywhere on the command line. Single-page `-o` creates parent folders automatically and writes the file only when the request succeeds. Credit receipts always go to stderr so stdout stays clean for piping.

## Read many pages and sites

**Shell**

```bash
crawl -i urls.txt -o pages/                    # one file per page; rerun to resume
cat urls.txt | crawl -i - --json               # one JSON line per page, then a summary
crawl -i urls.txt -o pages/ --max-credits 500  # stop starting pages at 500 credits
crawl site docs.example.com -o docs/ --max-pages 50 --include "/docs/**"
```

Batches pace automatically to your account's rate and concurrency limits (`--concurrency N` lowers concurrency). `--max-credits N` stops starting new pages once `N` credits are spent.

With `-o`, each page writes to `<host>/<path>.md` (or `.json`) and records progress in `.crawl-journal.jsonl`. Rerunning skips completed pages and permanent failures, and Ctrl-C preserves everything already fetched. `crawl site` follows links breadth first on the exact start **host and port**, up to `--max-pages` (default `25`) and `--max-depth` (default `2`).

## Account commands

| Command | What it shows or does |
| --- | --- |
| `crawl account` | Credit balance, held credits, rate limits, active key, and key source |
| `crawl keys list` · `create --name NAME` · `revoke <ID_OR_PREFIX>` | Active keys with UTC timestamps; `create` (`--description` optional) prints a new key once; `revoke` takes id or prefix positionally (`--yes` for scripts) |
| `crawl usage` · `crawl requests` | Daily or `--by-domain` totals; recent requests (`--days`, default `7`, `--from`/`--to`, `--limit 1-100`, default `25`) |
| `crawl billing packs` · `buy <PACK>` · `purchases` · `auto-top-up` | Available credit packs, Stripe checkout link (`--no-browser` prints URL), purchase history, and auto top-up state |
| `crawl setup` · `crawl skill` · `crawl completions <SHELL>` | Install the CLI skill (`--project` for repo scope), print MCP commands, or generate `bash`/`zsh`/`fish`/`powershell`/`elvish` completions |
| `crawl doctor` · `crawl logout` | Verify install, `PATH`, key, and API connectivity; revoke this machine's key and remove it |

## Exit codes

| Code | Meaning | What to do |
| --- | --- | --- |
| `0` | Success | Use the output |
| `1` | Unexpected CLI error | Report it |
| `2` | Invalid command or local path | Fix the arguments |
| `3` | Not signed in, key refused, or account suspended | Run `crawl login` (or contact support if suspended) |
| `4` | Out of credits, or `--max-credits` reached | Top up at [app.crawlapi.dev/billing](https://app.crawlapi.dev/billing), run `crawl billing packs`, or raise `--max-credits` |
| `5` | Permanent page failure (`retryable: false`) | Do not retry |
| `6` | Temporary page failure (`retryable: true`) | Retry later |
| `7` | Network or service error | Retry with backoff |
| `8` | Partial batch failure | Rerun to retry remaining pages |
| `130` | Interrupted with Ctrl-C | Rerun to resume |

With `--json`, `error.code` and `error.retryable` report the exact failure; see [Errors and retries](https://docs.crawlapi.dev/errors.md).

## Environment

| Variable | Effect |
| --- | --- |
| `CRAWLAPI_API_KEY` | API key; takes precedence over the saved `crawl login` key |
| `CRAWLAPI_CONFIG_DIR` | Directory containing `config.toml` and `credentials.toml` |
| `CRAWLAPI_LOG` | Debug logs on stderr (for example `CRAWLAPI_LOG=debug`); keys are never logged |
| `NO_COLOR` · `FORCE_COLOR` | Disable color, or force color inside a pipe |

Configuration precedence: CLI flags, environment variables, `./.crawlapi.toml` (`format`, `timeout`), `config.toml`, then built-in defaults. Run `crawl help environment` to see every supported variable.

## Use with an agent

Add a short block to your repository's `AGENTS.md` or `CLAUDE.md` when you want coding agents to use `crawl` in shell commands:

**AGENTS.md**

```markdown
## Reading web pages with crawl

The `crawl` CLI is installed. Never print `CRAWLAPI_API_KEY` or pass keys on the command line.
Use `crawl <url>` for markdown, `-f json` for structured data, and `--json` when parsing fields in scripts.
Always bound multi-page runs with `--max-pages` and `--max-credits`, and check `crawl <cmd> --help` before using unfamiliar flags.
```

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| `command not found` | Add `~/.local/bin` to `PATH` with the line the install script printed (on Windows, open a new terminal), check `command -v crawl`, or call `crawlapi`. |
| Exit code `3` on `crawl keys` or `crawl billing` | Those commands require a `cli`-scoped key from `crawl login`, not a `scrape`-scoped dashboard key. |
| `Cost: unknown` after a network drop | `crawl` avoids silent double-billing on uncertain drops; check `crawl requests` before retrying. |
| Credential file refused | Restrict `credentials.toml` to owner-only permissions (`chmod 600`). |
