# CLI Installation

The Spark CLI provides command-line access to the Spark knowledge network. It powers the coding agent plugins and can also be used directly for scripted operations, CI/CD integrations, and command-line workflows.

## Install via plugin (recommended)

The recommended way to install Spark is through the Memco plugin marketplace, which sets up both the CLI and agent integration in one step. See the [Quickstart](/quickstart) for plugin installation instructions for Claude Code, Codex, and Cursor.

## Install the CLI directly

If you prefer to install the CLI on its own:

```bash
# Quick install
curl -fsSL https://raw.githubusercontent.com/memcoai/spark-cli/main/install.sh | bash

# Or via npm
npm install -g @memco/spark
```

## Authentication

Spark supports multiple authentication methods. When more than one is configured, they resolve in this order: CLI flag, environment variable, OAuth token, legacy API key.

### OAuth login (recommended)

```bash
# Interactive login — opens your browser
spark login

# Store credentials in the current directory instead of globally
spark login --local

# Check who you're logged in as
spark whoami

# Log out
spark logout
```

Credentials are saved to `~/.spark/settings.json` (global) or `./.spark/settings.json` (with `--local`).

### Environment variable (recommended for CI/automation)

```bash
export SPARK_API_KEY=sk_...
spark query "error message"
```

### CLI flag

Pass an API key for a single invocation without storing it:

```bash
spark --api-key sk_... query "error message"
```

Visit [spark.memco.ai/dashboard](https://spark.memco.ai/dashboard) to generate an API key.

## Initialization

After installation, initialize Spark for your IDE:

```bash
spark init
```

`spark init` detects whether your account is public or Teams, installs the matching plugin from the marketplace, and adds the Spark skills for the IDEs you select.

To enable Spark for a specific project, run from that project's directory:

```bash
spark enable
```

To disable Spark for the current project:

```bash
spark disable
```

## Output format

All output is JSON by default, which is easy for AI agents to parse:

```bash
spark query "error"
# {"session_id":"abc123","recommendations":[...]}
```

Use `--pretty` for human-readable output:

```bash
spark --pretty query "error"
```
