🛣️cortex-router
- ライセンス
- Proprietary. See LICENSE-SKILLS.md for complete terms
- ソース
- GitHub で見る ↗
説明
プロンプトフィルターフックによって読み込まれる自動ルーティングスキルです。 Snowflake関連の操作をCortex Code CLIにルーティングします。 直接呼び出しは想定されていません — 代わりに `$cortex-run` を使用してください。
原文を表示
Auto-routing skill loaded by the prompt filter hook. Routes Snowflake-related operations to Cortex Code CLI. Not for direct invocation — use $cortex-run instead.
ユースケース
- ✓Snowflake関連の操作をルーティング
- ✓プロンプトフィルターフックで自動ルーティング
本文(日本語訳)
Cortex Code Router
Snowflake の操作を Cortex Code CLI にルーティングします。 この CLI には、専門的なバンドルスキル(data-quality、semantic-view、cost-intelligence、ML、governance など)が含まれています。
重要: ステップ 1 → 2 → 3 の順に従ってください。ステップ 3 にスキップしないでください。
ステップ 1: CLI の確認
which cortex 2>/dev/null && cortex --version
cortex が見つからない場合:
- ユーザーに次のように伝えます: 「Cortex Code CLI がインストールされていません。今すぐセットアップします。」
- Skill ツールを使用して
snowflake-cortex-code:cortex-setupスキルを読み込みます。 - ここで停止 — CLI がインストールされるまで続行しないでください。
ステップ 2: ルーティングの確認
ルーティングスクリプトを実行して、このプロンプトを Cortex に送るべきか、Claude Code で処理すべきかを確認します:
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/route_request.py" --prompt "USER_PROMPT_HERE"
USER_PROMPT_HERE を実際のユーザープロンプト(シェルエスケープ済み)に置き換えてください。
出力を注意深く確認してください:
- 出力に "route: cortex" と表示された場合 → ステップ 3 に進む
- 出力に "route: claude" と表示された場合 → ここで停止。Claude Code のツール(sql_execute、Read、Write など)を使ってリクエストを自分で処理してください。
execute_cortex.pyは実行しないでください。
ステップ 3: Cortex Code 経由で実行
このステップには、ステップ 2 で Cortex へのルーティングが確認された場合のみ進みます。
操作内容に応じて、セキュリティエンベロープを選択してください:
- RO: 読み取り専用クエリ(SELECT、SHOW、DESCRIBE) — DDL や DML は実行しません
- RW: データ変更・DDL(CREATE、ALTER、DROP) — ほとんどの操作でデフォルト
- RESEARCH: 読み取り + Web アクセス、書き込みなし
- DEPLOY: フルアクセス(使用は最小限に)
リクエストが明らかに読み取り専用でない限り、デフォルトは RW を使用してください。
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/execute_cortex.py" \
--prompt "USER_PROMPT_HERE" \
--envelope "RW"
特定の Snowflake 接続が必要な場合は --connection CONNECTION_NAME を追加してください。
マルチターン: --resume-last vs 新規開始
Cortex の呼び出しごとに session_id が返され、ルーターによって保持されます。
フォローアップのターンではそのセッションを再開することができ、Cortex が以前の会話の文脈を参照できるようになります。
これはプロンプトごとに一度きりのバッチ処理ではなく、真のマルチターン対話です。
--resume-lastを追加する場合: 現在のプロンプトが直前の Cortex ターンの続きである場合。 例: 「続けて」「上位の提案を適用して」「もっと深く調べて」「〜も見せて」「先四半期についても」「それを修正して」、または Cortex が返した回答に対する何らかの補足・確認。--resume-lastを省略する場合(新規開始): ユーザーが話題を変えた場合、別のデータベース/ウェアハウスについて質問する場合、または明らかに新しいタスクを開始する場合。- 明示的な ID がある場合は
--resume <session_id>も使用できます。
# 直前の Cortex ターンのフォローアップ
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/execute_cortex.py" \
--prompt "drill into the top customer" --envelope "RO" \
--resume-last
タイムアウト: このコマンドは 30〜90 秒かかる場合があります。
2 分以上経過した場合はハングアップの可能性が高いため、プロセスを終了し、
直接実行のために $cortex-run を試すようユーザーに伝えてください。
ステップ 4: 結果の返却
Cortex の出力をユーザー向けに整形します:
- SQL の結果を見やすいテーブル形式で表示する
- 生成されたアーティファクトや分析結果を表示する
- 成功・失敗を明確に報告する
注意事項
- Cortex には以下のバンドルスキルが含まれています: data-quality、semantic-view、cost-intelligence、ML、governance、security、lineage、dynamic-tables など
- Cortex スキルを必要としないシンプルな SQL クエリの場合、ステップ 2 で Claude Code にルーティングされます
route_request.pyが見つからない、または失敗した場合は、Claude Code のツールにフォールバックしてください--resume-lastを使用することで、呼び出し間のマルチターンコンテキストが保持されます(ステップ 3 参照)
原文(English)を表示
Cortex Code Router
Route Snowflake operations to Cortex Code CLI, which has specialized bundled skills (data-quality, semantic-view, cost-intelligence, ML, governance, etc.).
CRITICAL: Follow steps 1 → 2 → 3 in order. Do NOT skip to Step 3.
Step 1: Verify CLI
which cortex 2>/dev/null && cortex --version
If cortex is NOT found:
- Tell the user: "Cortex Code CLI is not installed. Setting it up now."
- Load the
snowflake-cortex-code:cortex-setupskill using the Skill tool. - STOP — do not continue until the CLI is installed.
Step 2: Confirm Routing
Run the routing script to check if this prompt should go to Cortex or stay in Claude Code:
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/route_request.py" --prompt "USER_PROMPT_HERE"
Replace USER_PROMPT_HERE with the actual user prompt (shell-escaped).
Read the output carefully:
- If output says "route: cortex" → proceed to Step 3
- If output says "route: claude" → STOP. Handle the request yourself using Claude Code tools (sql_execute, Read, Write, etc.). Do NOT run execute_cortex.py.
Step 3: Execute via Cortex Code
Only reach this step if Step 2 confirmed routing to Cortex.
Choose a security envelope based on the operation:
- RO: Read-only queries (SELECT, SHOW, DESCRIBE) — won't run DDL or DML
- RW: Data modifications, DDL (CREATE, ALTER, DROP) — default for most operations
- RESEARCH: Read + web access, no writes
- DEPLOY: Full access (use sparingly)
Default to RW unless the request is clearly read-only.
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/execute_cortex.py" \
--prompt "USER_PROMPT_HERE" \
--envelope "RW"
Add --connection CONNECTION_NAME if a specific Snowflake connection is needed.
Multi-turn: --resume-last vs fresh
Every cortex invocation returns a session_id that the router persists. Follow-up
turns can resume that session so Cortex sees the prior conversation -- real
multi-turn, not one-shot batches per prompt.
- Add
--resume-lastwhen the current prompt is a continuation of the previous Cortex turn: "keep going", "apply the top suggestion", "dig deeper", "also show me ...", "and for last quarter", "fix that", or any clarification of an answer Cortex just gave. - Omit
--resume-last(start fresh) when the user switches topics, asks about a different database/warehouse, or begins a clearly new task. --resume <session_id>is also accepted if you have an explicit id.
# Follow-up on the previous Cortex turn
python "${CLAUDE_PLUGIN_ROOT}/scripts/router/execute_cortex.py" \
--prompt "drill into the top customer" --envelope "RO" \
--resume-last
Timeout: This command may take 30-90 seconds. If it takes longer than 2 minutes, it likely hung — kill the process and tell the user to try $cortex-run for direct invocation.
Step 4: Return Results
Format Cortex's output for the user:
- Show SQL results in readable tables
- Display any generated artifacts or analysis
- Report success/failure clearly
Notes
- Cortex has bundled skills for: data-quality, semantic-view, cost-intelligence, ML, governance, security, lineage, dynamic-tables, and more
- For simple SQL queries that don't need Cortex skills, Step 2 should route to Claude Code
- If
route_request.pyis missing or fails, fall back to Claude Code tools - Multi-turn context is preserved across invocations via
--resume-last(see Step 3)
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。