# Cortex Code (coco)

Cortex Code — informally `coco` — is Snowflake’s agentic AI coding assistant. It writes, modifies, explains, and reviews SQL and helps you build and operate on Snowflake. It comes in two forms: a desktop command-line tool and an integrated assistant inside Snowsight.

## What it is

Cortex Code is an agentic assistant for development and operational work on Snowflake: authoring and refactoring SQL, exploring data assets, reviewing changes with a diff view, explaining existing code, and performing administrative tasks. It plans and executes multi-step tasks, selecting internal tools and relevant Snowflake context (your roles, privileges, schemas, and SQL syntax) to produce accurate responses.

It ships in two forms:

- **Desktop / CLI** — the `cortex` command-line tool you install locally and connect to your Snowflake account.
- **On-platform in Snowsight** — an integrated assistant panel inside Snowsight Workspaces, context-aware of the script you have open.

## Cortex Code vs. the Cortex Intelligence Agent

Do not confuse Cortex Code with the **Cortex Intelligence Agent** (the `CLINICOGENOMICS_AGENT`, see that page). They solve different problems. Cortex Code is a *coding assistant*: you are still the author, and it helps you write, refactor, and explain SQL and build on the platform. The Cortex Intelligence Agent is *natural-language Q&A* over semantic views — you ask a question in plain English and it returns an answer, without you touching SQL.

| Tool | Best for | Interface |
| --- | --- | --- |
| `Cortex Code (coco)` | Writing, refactoring, and explaining SQL; building on Snowflake | CLI (desktop) or assistant panel in Snowsight Workspaces |
| `Cortex Intelligence Agent` | Quick natural-language questions over the curated semantic layer | Chat in Snowsight (AI & ML → Intelligence) |

Rule of thumb: reach for Cortex Code when the *output is code you own*; reach for the Cortex Intelligence Agent when the output is *an answer*.

## Desktop / CLI

Install the Cortex Code CLI with the official install script, then verify the install.

```bash
# macOS, Linux, or Windows Subsystem for Linux (WSL)
curl -LsS https://ai.snowflake.com/static/cc-scripts/install.sh | sh

# verify
cortex --version
```

On native Windows, install from PowerShell instead:

```bash
irm https://ai.snowflake.com/static/cc-scripts/install.ps1 | iex
```

### Connect to your account

Start `cortex` against your Snowflake account. You authenticate as a Snowflake user, so Cortex Code runs as your RWD role and sees only what that role can access (see [Access](#access)).

```bash
cortex -c <your-account>
```

> **Confirm current install & auth steps**
>
> Cortex Code is evolving quickly, and exact install URLs, the connection flow, and GA status change. Verify against the current Snowflake docs (Cortex Code CLI) before scripting anything, and ask in #rwd-snowflake-help if the steps above do not match what you see.

## On-platform in Snowsight

If you do not want a local install, use Cortex Code directly in Snowsight (`app.snowflake.com`). It appears as an integrated assistant panel in **Workspaces**, operating in the context of the script you have open.

- Type prompts to generate, modify, or explain SQL inline.
- Reference catalog objects with `@` to pull tables, views, and schemas into context.
- Review suggested code with a diff view before applying it.
- Use quick actions to fix errors and refine SQL in place.

Because it shares your Snowsight session, it inherits your active role and warehouse automatically.

## Access: roles & warehouse

Cortex Code is not a privilege escalation. It executes as **your Snowflake role** — e.g. `RWD_ANALYST_PHI_ROLE` — and can only read or operate on objects that role is already granted. If you cannot query something yourself, neither can coco on your behalf.

Running SQL needs a warehouse. Use an interactive warehouse such as `RWD_PRODUCTION_QUERY_INTERACTIVE_WH` for ad-hoc work. In Snowsight, it uses whatever role and warehouse are active in your session; from the CLI, set them on the connection.

> **It can run SQL**
>
> Cortex Code is agentic and can execute SQL it generates — including statements that write or change objects. Review the diff and the execute-permission prompts (Allow Once / Always Allow) before approving, especially against production schemas.

## Help

Stuck on install, auth, or a Cortex Code prompt? Ask in #rwd-snowflake-help.
