# Altertable CLI

Install the CLI, log in, and run a first query.

## Prerequisites

You need a terminal and an Altertable account with access to an [organization and environment](/docs/administration.md).

## Connect

### Set up with your agent

```text
Set up the Altertable CLI in this environment. Follow https://altertable.ai/docs/lakehouse/query/cli.md.

Detect my operating system, shell, and any existing CLI installation. Install or reuse the supported CLI and preserve existing profiles. Guide me through browser login, then confirm the intended organization and environment with the active profile.

Verify lakehouse credentials are available without printing them. Run SELECT 1 AS ok and confirm the returned value is 1. Use --agent when the agent consumes structured CLI output. Report the installed version, active profile, verification result, and any remaining setup. Do not ingest data or change remote resources during this setup.
```

### Install the CLI

Run the installer in your terminal:

```bash
curl -fsSL https://install.altertable.ai | sh
```

**Other installation methods**

Install from npm:

```bash
npm install -g @altertable/cli
```

You can also download a binary for your operating system from [GitHub Releases](https://github.com/altertable-ai/altertable-cli/releases).

### Log in

```bash
altertable login
```

Complete browser login and choose your organization and environment. The CLI creates or reuses a local profile with those settings. The first lakehouse command automatically provisions temporary credentials for that profile. You do not need to copy credentials for this login-based workflow.

For environment-variable configuration, supply `ALTERTABLE_BASIC_AUTH_TOKEN` or `ALTERTABLE_LAKEHOUSE_USERNAME` and `ALTERTABLE_LAKEHOUSE_PASSWORD` explicitly. Automatic provisioning applies to stored profiles with management access. See [profile configuration](/docs/api-references/cli.md#altertable-profile-configure) for manually configured profiles.

## Run your first query

Check that the active profile points to the intended environment, then run a query that needs no existing table:

```bash
altertable profile show
altertable query "SELECT 1 AS ok"
```

The query should return an `ok` column with the value `1`.

Next, [ingest your first data](/docs/getting-started/ingest-data.md) and read it back.

**More CLI workflows**

- [Query options, SQL files, and output formats](/docs/api-references/cli.md#altertable-query)
- [Append records](/docs/api-references/cli.md#altertable-append), [upload files](/docs/api-references/cli.md#altertable-upload), and [upsert rows](/docs/api-references/cli.md#altertable-upsert)
- [Manage profiles](/docs/api-references/cli.md#altertable-profile) and [log in as a service account](/docs/api-references/cli.md#altertable-login)
- [Call the management API](/docs/api-references/cli.md#altertable-api)
- [Develop data apps](/docs/api-references/cli.md#altertable-app)
- [Use the CLI with agents](/docs/agents/cli.md)

For all commands and global flags, see the [CLI reference](/docs/api-references/cli.md).

## Monitor running queries

Use the active profile to inspect queries and refresh their progress:

```bash
altertable query list
altertable query top --watch --interval 5
altertable query show <query-id>
altertable query cancel <query-id>
```

Environment credentials can see all running queries in the environment; principal credentials see only their own. Press Ctrl+C to leave the live monitor. Use `query cancel` when you intend to stop a query.

## Troubleshooting

- **Credentials expired:** run `altertable login` again.
- **Wrong environment:** [switch to the correct profile](/docs/api-references/cli.md#altertable-profile-switch).
- **Login works but queries fail:** check the profile's [lakehouse credentials](/docs/administration/lakehouse-credentials.md).