# Automate with Tokens, JSON, and Context

> Use the Done Bear CLI from scripts, CI jobs, and agent workflows.

Set up repeatable, non-interactive CLI runs with tokens, machine-readable output, and agent-friendly context.

## Use a token instead of browser login

For CI and non-interactive scripts, set `DONEBEAR_TOKEN` instead of running `donebear auth login`.

A coding agent creating the human's first account uses `donebear auth signup --email <human-email> --json --no-interactive` instead of inventing credentials. That path emails a verification code, polls until the human verifies, then stores a `db_` key. Already-registered emails should run `donebear auth login`.

```bash
export DONEBEAR_TOKEN=<token>
donebear task list --json
```

Token precedence is:

1. `--token <token>`
2. `DONEBEAR_TOKEN`
3. The stored session from `donebear auth login`

That means you can override a local session for one command without changing the session on disk:

```bash
donebear --token <token> workspace list --json
```

## Create an API key for automation

Create a long-lived key:

```bash
donebear api-key create "CI"
```

List or revoke keys later:

```bash
donebear api-key list
donebear api-key revoke <key-id>
```

## Use JSON, CSV, or TSV output

Use `--json` for scripting and `--format csv|tsv` for exports.

```bash
donebear task list --json
donebear search "launch" --format csv
donebear history --format tsv
```

Count-only output works well for health checks and shell conditions:

```bash
donebear search "blocked" --total
```

## Target a workspace explicitly

Use `--workspace` when a script should never depend on the current default workspace:

```bash
donebear task list --workspace personal --json
```

Use the prefix form when you want the workspace at the very front of the command:

```bash
donebear workspace=personal task list --json
donebear workspace=personal search "launch"
```

## Generate agent-friendly context

Use `spec` when an agent needs the command surface without any auth requirement:

```bash
donebear spec
donebear spec task add
```

Use `context` when an agent needs the current workspace state:

```bash
donebear context --json
donebear context --markdown
```

`spec` is static and command-focused. `context` is workspace-aware and stateful.

## Export recent work

Capture open tasks as JSON:

```bash
donebear task list --state open --json > open-tasks.json
```

Export search results as CSV:

```bash
donebear search "invoice" --format csv > invoice-results.csv
```

## Caveats for automation

- Task IDs can be full UUIDs or unique prefixes of four or more characters.
- Prefix resolution is workspace-scoped. Use full IDs in scripts to avoid ambiguous matches.
- `context --markdown` is meant for prompt injection and human review, not structured parsing.

## Next steps

- Read [Command reference](/cli/commands) for the supported global flags and command groups.
- Follow [Import from Things 3](/cli/import-things) if your automation starts with a migration.
- Switch to [API overview](/api) if you need direct HTTP access instead of the CLI.

---

Every Done Bear page is listed at https://donebear.com/llms.txt. Any page has a markdown copy at its URL plus `.md`. Start from the map rather than guessing a path.
