cortex -p "your prompt here" --output-format stream-jsonExecutes Cortex in headless mode with streaming JSON output.
Output Format: NDJSON (newline-delimited JSON)
- Each line is a complete JSON object
- Events stream in real-time as they occur
cortex -p "prompt" --allowed-tools "tool1" "tool2" "tool3"Explicitly allows specific tools. Required for headless execution when --dangerously-allow-all-tool-calls is disabled by organization.
cortex skill listLists all available skills (bundled and custom).
cortex connections listShows all configured Snowflake connections.
cortex search object <pattern>
cortex search docs <query>Searches Snowflake objects or documentation.
{
"type": "system",
"subtype": "init",
"session_id": "unique-session-id",
"tools": ["read", "write", "bash", ...],
"model": "auto"
}Initialization event at session start.
{
"type": "assistant",
"session_id": "...",
"message": {
"role": "assistant",
"content": [
{"type": "text", "text": "Response here"},
{"type": "tool_use", "id": "...", "name": "bash", "input": {...}}
]
}
}Cortex's responses and tool invocations.
{
"type": "user",
"session_id": "...",
"message": {
"role": "user",
"content": [
{"type": "tool_result", "tool_use_id": "...", "content": "result or error"}
]
}
}Tool results or user input (including permission denials).
{
"type": "result",
"session_id": "...",
"subtype": "success",
"result": "Final outcome text",
"is_error": false,
"duration_ms": 5234,
"num_turns": 3
}Final session result.
When a tool is not in --allowed-tools, you'll see:
{
"type": "user",
"message": {
"content": [{
"type": "tool_result",
"tool_use_id": "toolu_xxx",
"content": "Permission denied: Tool denied: headless mode requires --allowed-tools"
}]
}
}Handling:
- Detect permission denial in event stream
- Extract the requested tool from the context
- Surface to user via Claude Code's AskUserQuestion
- Re-invoke Cortex with updated
--allowed-toolsif approved
snowflake_sql_execute- Execute SQL queries on Snowflakebash- Run bash commandsread- Read fileswrite- Write filesedit- Edit filesglob- File pattern matchinggrep- Content searchweb_fetch- Fetch web contentask_user_question- Ask user questionstask- Task management- Plus skill-specific tools
cortex -p "Show top 10 customers" \
--output-format stream-json \
--allowed-tools "snowflake_sql_execute" "bash"cortex -p "Check data quality for SALES_DATA table" \
--output-format stream-json \
--allowed-tools "snowflake_sql_execute" "bash" "read" "write"cortex -p "# Previous Context
User asked about customer segmentation.
# Recent Cortex Work
Ran RFM analysis on customers table.
# Current Request
Create a dynamic table for high-value customers" \
--output-format stream-json \
--allowed-tools "snowflake_sql_execute" "bash" "read"~/.snowflake/cortex/settings.json
Key settings:
cortexAgentConnectionName- Default Snowflake connectionmodel- AI model to use- Other Cortex-specific preferences
~/.snowflake/cortex/cortex.json
Project-specific trust and permissions.
~/.local/share/cortex/sessions/*.jsonl
Stored session transcripts for context enrichment.
Error: Connection refused
Solution: Check Snowflake connection:
cortex connections listPermission denied: Tool denied: headless mode requires --allowed-tools
Solution: Add tool to --allowed-tools list.
Error: Rate limit exceeded
Solution: Cortex routes through Snowflake Cortex AI. Check Snowflake quotas.
- Start Conservative: Begin with minimal tool set, expand as needed
- Enrich Context: Always provide relevant background from Claude session
- Read Sessions: Check recent Cortex work to avoid duplicate operations
- Handle Streams: Parse NDJSON line-by-line, don't wait for completion
- Timeout Handling: Set reasonable timeouts (30-60s for complex queries)
- Error Recovery: Detect permission denials early, prompt user immediately
- No Persistent Sessions: Each invocation is stateless
- No
--resume: Session resumption not available in headless mode - Organization Policies: Some flags may be blocked (e.g.,
--bypass,--dangerously-allow-all-tool-calls) - Tool Restrictions: Only tools in
--allowed-toolscan be used - Rate Limits: Subject to Snowflake Cortex AI rate limits