How to bulk discard queued runs in a stack using spacectl?
Last updated: December 19, 2025
Context
When managing a stack with multiple queued runs (potentially 50 or more), users may need to discard all these runs efficiently. While the UI offers some bulk action capabilities, a command-line solution using spacectl might be more efficient for handling large numbers of queued runs.
Answer
You can use a combination of spacectl commands with jq to bulk discard all queued runs in a stack. Here's how to do it:
To execute the bulk discard:
spacectl stack run list --id <stackID> --output json --max-results 100 \
| jq -r '.[] | select(.state=="QUEUED") | .id' \
| while IFS= read -r id; do
spacectl stack discard --id <stackID> --run "$id"
doneThis command will:
List all runs in the specified stack (up to 100 results)
Filter for only queued runs
Automatically discard each queued run
Display confirmation messages for each discarded run
If you want to preview what will be discarded before executing, you can use this dry-run version:
spacectl stack run list --id <stackID> --output json --max-results 100 \
| jq -r '.[] | select(.state=="QUEUED") | .id' \
| while IFS= read -r id; do
echo "spacectl stack discard --id <stackID> --run $id"
doneNote: Replace <stackID> with your actual stack ID in both commands.