Cortex Code CLI reference

Command line reference for Cortex Code CLI.

Starting Cortex Code

CommandDescription
cortexStart in current directory
cortex -c productionStart with specific connection
cortex -w /path/to/projectStart in specific directory
cortex -w /new/project -c myconnCombine workdir and connection
cortex --continueContinue last session
cortex --resume <session_id>Resume specific session

CLI options

OptionDescription
-c, --connection <name>Use specific Snowflake connection
-w, --workdir <path>Set working directory for file operations
-m, --model <model_name>Specify AI model to use
--planPlan mode: require approval before all actions
--bypassAutomatically approve all planned actions
--dangerously-allow-all-tool-callsDisable tool call permission prompts (caution)
--continueResume most recent conversation
-r, --resume <session_id>Resume specific session by ID, or last for last session
-p, --print "<prompt>"Pass specified prompt, print response, and exit
-f, --file <file>Read prompt from file, execute, and exit
--output-format stream-jsonJSON output (for scripting)
-V, --versionShow installed version
--helpShow CLI help

Connections must be defined in ~/.snowflake/connections.toml. See Cortex Code CLI for connection setup. Session IDs are shown at startup, at exit, and stored in ~/.snowflake/cortex/conversations/.

Examples

Start with working directory:

cortex -w /path/to/project

Resume last session with specific connection:

cortex --continue -c production

One-off prompt (JSON output):

cortex -p "List all Python files" --output-format stream-json

Commands

update

CommandDescription
cortex updateUpdate to latest version
cortex --versionVerify after update

mcp

CommandDescription
cortex mcp listList configured servers
cortex mcp addAdd new server (interactive)
cortex mcp remove <server_name>Remove server

See for details.

Interactive mode

Keyboard shortcuts

ShortcutAction
Ctrl+CCancel current operation
Ctrl+C Ctrl+CExit Cortex Code CLI
Ctrl+LClear terminal screen (keeps conversation)
Up/Down arrowsNavigate command history
TabCommand completion

Slash commands

Session management

CommandDescription
/helpShow interactive help
/planEnable planning mode
/plan_offDisable planning mode
/clear, /clsClear the screen
/newStart a new session
/rename <title>Rename current session
/exit, /quitExit Cortex Code CLI
/resume, /r, /sessionsList and resume sessions
/rewindGo back n steps in conversation or pick interactively
/skill listList available skills
/mcp-statusShow MCP server status
/forkFork current session into a new session

Model and mode

CommandDescription
/modelShow/select AI model
/planEnable plan mode
/plan-offDisable plan mode
/bypassEnable bypass mode (auto-approve all including tool calls)
/bypass-offDisable bypass mode
/statusShow current configuration

Snowflake and data

CommandDescription
/sql <query>Execute SQL query
/sql <query> --limit <n>Limit displayed rows
/table [<file>], /csvOpen table viewer
/connections, /connManage Snowflake connections

Development tools

CommandDescription
/sh, ! <command>Execute shell command
/diff, /changes, /reviewReview git changes
/worktreeManage git worktrees
/dbtdbt operations
/lineagedbt lineage visualization

Configuration

CommandDescription
/settingsView/modify settings
/themeSelect color theme
/sandboxManage sandbox settings
/add-dir <path>Add working directory

Extensibility

CommandDescription
/skill, /skillsManage skills
/mcpMCP server status
/hooksView hooks configuration
/commands, /cmdsManage custom commands
/agentsView subagents

Utilities

CommandDescription
/tasksShow task list
/feedbackProvide session feedback (Saved locally as a .tgz file)
/updateUpdate Cortex Code

Session storage

CommandDescription
~/.snowflake/cortex/conversations/Session files
~/.snowflake/cortex/settings.jsonGeneral settings
~/.snowflake/cortex/permissions.jsonPermission preferences

See Cortex Code CLI Settings for configuration details.

Command details

/sql: Execute SQL examples

Basic query:

/sql SELECT * FROM users

With row limit:

/sql SELECT * FROM large_table --limit 1000

Multi-line queries (use Ctrl+J for newlines):

/sql SELECT
  customer_id,
  SUM(amount) as total
FROM orders
GROUP BY customer_id

Results open automatically in the table viewer (Ctrl+T).

/worktree: Git worktrees

CommandDescription
/worktree create feature-branchCreate new worktree
/worktree listList all worktrees
/worktree switch feature-branchSwitch to worktree
/worktree delete feature-branchDelete worktree

/sandbox: Sandbox control

CommandDescription
/sandboxInteractive selector
/sandbox onEnable container sandbox
/sandbox offDisable container sandbox
/sandbox statusShow sandbox status
/sandbox runtime onEnable OS sandbox
/sandbox runtime offDisable OS sandbox
/sandbox mode autoAuto-allow sandboxed commands
/sandbox mode regularPrompt for all commands

/mcp: MCP servers

CommandDescription
/mcpShow status viewer
/mcp listList all servers
/mcp start <server>Start server
/mcp get <server>Get server details
/mcp remove <server>Remove server

Batch mode

CommandDescription
cortex -p "<prompt>"Run single prompt and exit
cortex -f request.txtRead prompt from file
cortex --output-format stream-json -p "<prompt>"JSON output
cortex -c prod --workdir /app -p "..."Control context

Exit codes

CodeDescription
0Success
1General error
2Configuration error
3Connection error
4Permission denied
130Interrupted by user (Ctrl+C)

Configuration and setup

Updating Cortex Code CLI

Cortex Code CLI updates itself when a new version is available. You can also manually update to the latest version by issuing cortex update. Issue cortex update <version> to install the specified version.

To disable automatic updates, edit ~/.snowflake/cortex/settings.json and add "autoUpdate": false.

Manually adding a connection

To manually create or edit the ~/.snowflake/connections.toml file to define your connection, follow the steps below:

  1. Create the ~/.snowflake/connections.toml file if it doesn’t already exist.

    mkdir -p ~/.snowflake
    touch ~/.snowflake/connections.toml
  2. Use the chmod command to set its permissions so that only you can read and write it.

    chmod 600 ~/.snowflake/connections.toml
  3. Open the file in a text editor (here, nano).

    nano ~/.snowflake/connections.toml
  4. Add lines like the following to define a connection. Enter the name of the connection in place of myaccount and replace the placeholder values with your Snowflake account details. Use browser-based SSO (external browser authentication) or PAT (programmatic access token). You can obtain a PAT from Snowsight (see Using programmatic access tokens for authentication). Include only the authenticator value or password value, depending on the authentication method you choose.

    [myaccount]
    account       = "<ACCOUNT>"
    user          = "<USERNAME>"
    authenticator = "externalbrowser" # For browser-based SSO; omit for PAT
    password      = "<PAT>"           # For PAT authentication; omit for SSO
    warehouse     = "<WAREHOUSE>"
    role          = "<ROLE>"
    database      = "<DATABASE>"
    schema        = "<SCHEMA>"
  5. Save and close the file.

Setting up shell completions

To give your shell the ability to auto-complete Cortex Code CLI commands and options, follow the instructions below for your shell.

Tip

If you’re not sure which shell you’re using, issue echo $(basename $SHELL) in your terminal. The name printed is the default shell for your account, and may not be accurate if you have started a different shell manually.

ShellCommand
bashcortex completion bash > ~/.bash_completion.d/cortex
zshcortex completion zsh > ~/.zsh/completions/_cortex
fishcortex completion fish > ~/.config/fish/completions/cortex.fish

After running the appropriate command above for your shell, restart your shell with exec $SHELL.

Directory structure

Installing Cortex Code CLI creates the following directory structure in your home directory:

~/.snowflake/cortex/
    settings.json          # Main configuration
    mcp.json               # MCP server configs
    conversations/         # Session history
    skills/                # Global skills
    commands/              # Custom commands
    hooks/                 # Hook scripts
    profiles/              # Team profiles
    cache/                 # Temporary cache

Troubleshooting

Following are common error messages you may encounter during installation and setup.

Command not found

Make sure that the installation directory ~/.local/bin is included in your PATH environment variable. For example, if you are using bash, issue the following commands:

export PATH="~/.local/bin:$PATH"
echo 'export PATH="~/.local/bin:$PATH"' >> ~/.bashrc

Permission denied

Make sure that the cortex executable has execute permissions. Issue the following command:

chmod +x ~/.local/bin/cortex

Connection errors

Make sure that the connection file ~/.snowflake/connections.toml exists and contains valid connection details.

cat ~/.snowflake/connections.toml

Try invoking the cortex command with a connection explicitly specified using the -c option. For example:

cortex -c myaccount

See also

Cortex Code CLI

Installation, setup, and first prompts

Cortex Code CLI Settings

Configuration file reference

Cortex Code CLI workflow examples

Capabilities and workflow examples