Output SDK のワークフロー(処理の手順)を非同期(完了を待たずに)で開始します。 次のような場合に使用: - 実行時間の長いワークフローを開始する - 後で監視するためにワークフローIDを取得する - バックグラウンドでワークフローを実行する - 複数のワークフローを並行して実行する
Start an Output SDK workflow asynchronously without waiting for completion. Use when starting long-running workflows, getting a workflow ID for later monitoring, running workflows in the background, or executing multiple workflows in parallel.
このスキルは、ワークフローを非同期(バックグラウンドで実行する方式)で開始します。コマンドはワークフローIDをすぐに返し、ワークフロー自体はバックグラウンドで実行されます。長時間かかるワークフローや、複数のワークフローを同時に実行する必要がある場合に使用します。
npx output workflow run コマンド(同期実行)の使用を検討する場合:
npx output workflow start <workflowName> --input '<json-input>'
npx output workflow start <workflowName> --input <path-to-json-file>
ワークフローが入力データを必要とする場合、--input フラグは必須です。
コマンドラインにJSONを直接渡す方法:
npx output workflow start data-migration --input '{"batchSize": 1000}'
入力を含むJSONファイルを参照する方法:
npx output workflow start data-migration --input src/data_migration/scenarios/large_batch.json
この方法が推奨される理由:
コマンド実行後に表示されるワークフローIDは、以下の用途に必要です:
npx output workflow status <id>npx output workflow result <id>npx output workflow debug <id>--monitor(-m)フラグを追加すると、開始直後に接続して、ワークフロー完了まで各ステップの更新がリアルタイムで流れます(状態をポーリングする必要がありません):
npx output workflow start data-migration --input src/data_migration/scenarios/large_batch.json --monitor
このコマンドは、開始したばかりの実行に接続します。Ctrl+Cでワークフローを止めずに監視を終了(終了コード130)でき、ワークフロー失敗時はコマンドが終了コード1で終了します。監視接続が途中で切れた場合(APIの再起動や接続リセット)、ワークフロー自体は動き続けており、コマンドは終了コード3で終了します。これにより、失敗したワークフローに基づく再実行は、すでに実行中のワークフローを二重実行しません。
監視では進捗が報告され、戻り値は報告されません。コマンド終了時に、次に実行する方法が表示されます。実行完了時は npx output workflow result <id>、失敗時は npx output workflow debug <id> を実行します。
以下のフラグはストリーム設定を調整し、--monitor が必須です:
| フラグ | デフォルト | 説明 |
|---|---|---|
--interval |
2500 | ポーリング間隔(ミリ秒) |
--include-payloads |
false | ステップの入出力ペイロード(実データ)を含める |
--color |
true | 状態表示をカラー表示(--no-color で無効化) |
--monitor は --json と組み合わせられません。--json では進捗出力を抑制して最後にJSON1個を出力するため、ストリームが静かに無視されてワークフロー終了までコマンドが応答しないように見えてしまいます。JSON形式で取得するには、npx output workflow run --json(結果待機)を使うか、--monitor なしで開始して npx output workflow monitor <id> --format json(NDJSON形式ストリーム)で接続してください。
単一ワークフローを完了まで監視する場合は、workflow status でポーリングするループより --monitor を推奨します。複数ワークフローを同時開始する場合は、--monitor はワークフロー完了まで待機するので、非同期形式のままにしてください。
例1: シナリオファイルで長時間実行ワークフローを開始する
npx output workflow start data-migration --input src/data_migration/scenarios/full_migration.json
# 出力:
# Started workflow: data-migration
# Workflow ID: abc123xyz
# Use 'npx output workflow status abc123xyz' to check progress
例2: 複数ワークフローを並行実行する(シナリオファイル利用)
# 異なるシナリオファイルで複数ワークフローを開始
npx output workflow start process-batch --input src/process_batch/scenarios/batch_1.json
npx output workflow start process-batch --input src/process_batch/scenarios/batch_2.json
npx output workflow start process-batch --input src/process_batch/scenarios/batch_3.json
# 注: ワークフローIDを保存して後から確認します
例3: シナリオを作成してからワークフローを開始
# シナリオファイルを作成
mkdir -p src/generate_report/scenarios
cat > src/generate_report/scenarios/annual_2024.json << 'EOF'
{
"year": 2024,
"includeCharts": true,
"format": "pdf"
}
EOF
# ワークフローを開始
npx output workflow start generate-report --input src/generate_report/scenarios/annual_2024.json
# 出力: Workflow ID: report-2024-abc
# 状態を確認
npx output workflow status report-2024-abc
# 出力: Status: RUNNING
# 後でもう一度確認
npx output workflow status report-2024-abc
# 出力: Status: COMPLETED
# 結果を取得
npx output workflow result report-2024-abc
例4: 開発時の簡単なインラインテスト
npx output workflow start quick-job --input '{"test": true}'
例5: 並行実行用スクリプト
# ワークフローを開始してIDを取得
ID1=$(npx output workflow start job --input src/job/scenarios/type_a.json | grep "Workflow ID" | cut -d: -f2 | tr -d ' ')
ID2=$(npx output workflow start job --input src/job/scenarios/type_b.json | grep "Workflow ID" | cut -d: -f2 | tr -d ' ')
# 待機して結果を確認
npx output workflow result $ID1
npx output workflow result $ID2
npx output workflow status <workflowId>
ステータス値:
npx output workflow result <workflowId>
完了したワークフローのみ使用可能です。失敗したワークフローはデバッグコマンドを使用してください。
npx output workflow debug <workflowId> --json
npx output workflow stop <workflowId>
複数ワークフローを開始する場合、IDを追跡管理します:
# IDをファイルに記録
npx output workflow start batch-job --input src/batch_job/scenarios/id_1.json >> workflow-ids.txt
npx output workflow start batch-job --input src/batch_job/scenarios/id_2.json >> workflow-ids.txt
# または、ワークフロー内で命名規則を使用してIDを予測可能にする
src/<workflow>/scenarios/ に入力を保存して再現性を確保するnpx output workflow status で進捗確認するnpx output workflow stop で止まったワークフローを停止するnpx output workflow run <name> --input - 同期実行するnpx output workflow monitor <id> - 実行中のワークフローに接続するnpx output workflow status <id> - 実行状態を確認するnpx output workflow result <id> - 実行結果を取得するnpx output workflow stop <id> - ワークフローを停止するnpx output workflow debug <id> - ワークフローをデバッグするThis skill starts a workflow asynchronously, meaning the command returns immediately with a workflow ID while the workflow executes in the background. Use this for long-running workflows or when you need to run multiple workflows in parallel.
Consider using npx output workflow run (sync) when:
npx output workflow start <workflowName> --input '<json-input>'
npx output workflow start <workflowName> --input <path-to-json-file>
The --input flag is required when the workflow expects input data.
Pass JSON directly on the command line:
npx output workflow start data-migration --input '{"batchSize": 1000}'
Reference a JSON file containing the input:
npx output workflow start data-migration --input src/data_migration/scenarios/large_batch.json
This is the recommended approach because:
The command outputs the workflow ID which you'll need for:
npx output workflow status <id>npx output workflow result <id>npx output workflow debug <id>Add --monitor (-m) to attach immediately after starting and stream step
updates until the workflow ends, instead of polling workflow status:
npx output workflow start data-migration --input src/data_migration/scenarios/large_batch.json --monitor
This attaches to the exact run that was just started. Ctrl+C detaches without stopping the workflow (exit 130), and the command exits 1 if the workflow fails. If monitoring itself drops (an API restart, a reset connection), the workflow keeps running and the command exits 3 instead — so a retry keyed on a failed workflow can't re-submit one that is already in flight.
Monitoring reports progress, not the return value; the command closes by naming
the follow-up — npx output workflow result <id> after a run that completed,
npx output workflow debug <id> after one that failed.
These flags tune the stream and require --monitor:
| Flag | Default | Description |
|---|---|---|
--interval |
2500 | Poll interval in milliseconds |
--include-payloads |
false | Include decoded step input/output payloads |
--color |
true | Colorize status output (--no-color to disable) |
--monitor cannot be combined with --json. Under --json the CLI suppresses
progress output and prints one JSON object at the end, so the stream would be
silently swallowed and the command would look hung until the workflow finished.
To get JSON, either use npx output workflow run --json (wait for the result),
or start without --monitor and attach with
npx output workflow monitor <id> --format json (streaming NDJSON).
Prefer --monitor over a workflow status polling loop when you're watching a
single workflow through to completion. Keep the plain async form when starting
several workflows in parallel, since --monitor blocks until the run ends.
Scenario: Start a long-running workflow with scenario file
npx output workflow start data-migration --input src/data_migration/scenarios/full_migration.json
# Output:
# Started workflow: data-migration
# Workflow ID: abc123xyz
# Use 'npx output workflow status abc123xyz' to check progress
Scenario: Start multiple workflows in parallel using scenario files
# Start several workflows with different scenario files
npx output workflow start process-batch --input src/process_batch/scenarios/batch_1.json
npx output workflow start process-batch --input src/process_batch/scenarios/batch_2.json
npx output workflow start process-batch --input src/process_batch/scenarios/batch_3.json
# Note: Save the workflow IDs to check them later
Scenario: Create scenario then start workflow
# Create a scenario file
mkdir -p src/generate_report/scenarios
cat > src/generate_report/scenarios/annual_2024.json << 'EOF'
{
"year": 2024,
"includeCharts": true,
"format": "pdf"
}
EOF
# Start the workflow
npx output workflow start generate-report --input src/generate_report/scenarios/annual_2024.json
# Output: Workflow ID: report-2024-abc
# Check status periodically
npx output workflow status report-2024-abc
# Output: Status: RUNNING
# Later, check again
npx output workflow status report-2024-abc
# Output: Status: COMPLETED
# Get the result
npx output workflow result report-2024-abc
Scenario: Quick inline test for development
npx output workflow start quick-job --input '{"test": true}'
Scenario: Script for parallel execution
# Start workflows and capture IDs
ID1=$(npx output workflow start job --input src/job/scenarios/type_a.json | grep "Workflow ID" | cut -d: -f2 | tr -d ' ')
ID2=$(npx output workflow start job --input src/job/scenarios/type_b.json | grep "Workflow ID" | cut -d: -f2 | tr -d ' ')
# Wait and check results
npx output workflow result $ID1
npx output workflow result $ID2
npx output workflow status <workflowId>
Status values:
npx output workflow result <workflowId>
Only works for COMPLETED workflows. For FAILED workflows, use debug.
npx output workflow debug <workflowId> --json
npx output workflow stop <workflowId>
When starting multiple workflows, keep track of IDs:
# Log IDs to a file
npx output workflow start batch-job --input src/batch_job/scenarios/id_1.json >> workflow-ids.txt
npx output workflow start batch-job --input src/batch_job/scenarios/id_2.json >> workflow-ids.txt
# Or use a naming convention in your workflow that makes IDs predictable
src/<workflow>/scenarios/ for reproducibilitynpx output workflow status to check progressnpx output workflow stopnpx output workflow run <name> --input - Execute synchronouslynpx output workflow monitor <id> - Attach to a run already in progressnpx output workflow status <id> - Check execution statusnpx output workflow result <id> - Get execution resultnpx output workflow stop <id> - Stop a running workflownpx output workflow debug <id> - Debug a workflow execution原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。