Chaffbroom

Chaffbroom Winnow

Free & source available

Chaffbroom Winnow finds and deletes orphaned preview environments on Neon, Supabase, Vercel, Fly.io, Railway and Cloudflare. It decides by the state of each preview's pull request and by its age. It is a library, a CLI and a GitHub Action. It plans by default and deletes only when you pass --yes.

Works withGitHubGitHubGitHub ActionsGitHub ActionsNeonNeonSupabaseSupabaseVercelVercelFly.ioFly.ioRailwayRailwayCloudflare PagesCloudflare PagesCloudflare WorkersCloudflare Workers

What it does

Preview environmentsIts pull requestpreview/pr-214Neon branchPR #214 openkeeppr-198Vercel deploymentPR #198 mergeddeleteapp-pr-171Fly.io appPR #171 closeddeletemainSupabase branchdefault · protectedkeep winnow apply --yes: 2 deleted, 2 kept
Chaffbroom Winnow checks each preview's pull request and deletes only the ones whose PR is merged or closed. Open PRs and protected branches stay.

What it catches

  • Previews whose mapped PR is merged or closed without merge, after a grace period (grace_after_close).
  • Previews whose PR number gives a 404 on GitHub, but only after repo access with your token was verified in the same run.
  • Previews older than the provider TTL. A TTL never deletes an open PR's preview unless reap_open is true.
  • Previews with no PR mapping, reported as no-pr-mapping. They are deleted with reap_unmapped: true, or by the TTL when no PR number or branch was found at all.
  • Providers: Neon branches, Supabase branches, Vercel deployments, Fly.io apps and machines, Railway ephemeral environments, Cloudflare Pages previews.
  • Cloudflare Workers versions are listed with reasons but report-only: apply never deletes them.

Install

GitHub Actions workflow (nightly sweep, plus reap on PR close)yaml
on:
  schedule:
    - cron: "17 3 * * *"
  pull_request:
    types: [closed]
  workflow_dispatch:
    inputs:
      mode:
        description: plan or apply
        default: plan

permissions:
  contents: read
  pull-requests: read

jobs:
  reap:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
      - name: Sweep
        if: github.event_name != 'pull_request'
        uses: chaffbroom/winnow@v0
        with:
          mode: ${{ github.event_name == 'schedule' && 'apply' || inputs.mode }}
          yes: ${{ github.event_name == 'schedule' || inputs.mode == 'apply' }}
          max-deletes: "50"
          neon-api-key: ${{ secrets.NEON_API_KEY }}
          supabase-access-token: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          fly-api-token: ${{ secrets.FLY_API_TOKEN }}
          railway-token: ${{ secrets.RAILWAY_TOKEN }}
          cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
      - name: Reap this PR
        if: github.event_name == 'pull_request'
        uses: chaffbroom/winnow@v0
        with:
          mode: apply
          yes: "true"
          pr: ${{ github.event.pull_request.number }}
          # same provider tokens as above
Installsh
npx chaffbroom init        # shows the files it would write, writes nothing
npx chaffbroom init --yes  # writes the config and the workflows
CLIsh
npx chaffbroom winnow plan                      # list orphans, change nothing
npx chaffbroom winnow plan --show-kept -f json  # everything, machine-readable
npx chaffbroom winnow apply --yes               # delete what plan marked "delete"
npx chaffbroom winnow apply --yes --pr 123      # only this PR's previews (skips the close grace)
npx chaffbroom winnow plan --fail-on-orphans    # exit 1 if anything is deletable
Libraryts
// not on npm: build it from a clone of the repository
//   git clone --depth 1 https://github.com/chaffbroom/chaffbroom .chaffbroom
//   cd .chaffbroom && npm ci && npm run build:lib -w winnow
import { loadConfig, plan, apply, render } from './.chaffbroom/winnow/lib/index.js';
const p = await plan({ config: await loadConfig('.winnow.yml'), fetch });
console.log(render(p, 'markdown'));
await apply(p, { yes: true });

Step by step, with what to check after each part: installation manual. Everything else: the README.

Permissions

  • GitHubGitHub: GITHUB_TOKEN with contents: read and pull-requests: read, to look up each preview's PR. Secrets are not passed to pull_request runs from forks.
  • NeonNeon: NEON_API_KEY (Action input neon-api-key).
  • SupabaseSupabase: SUPABASE_ACCESS_TOKEN (Action input supabase-access-token).
  • VercelVercel: VERCEL_TOKEN (Action input vercel-token).
  • Fly.ioFly.io: FLY_API_TOKEN (Action input fly-api-token).
  • RailwayRailway: RAILWAY_TOKEN (Action input railway-token). Project tokens use the Project-Access-Token header (token_kind: project).
  • CloudflareCloudflare: CLOUDFLARE_API_TOKEN (Action input cloudflare-api-token).
  • Only the tokens for providers you enable are needed. A missing token skips that provider, the others still run, and the exit code is 1.

Privacy

  • Runs on your own runner with your own tokens and sends nothing anywhere else.
  • Tokens come from the environment; the optional .winnow.yml holds settings, not secrets.
  • Resource names, branches and provider error text are escaped in the job summary: no HTML, no Markdown, no @mentions.
  • Log lines stay on one line, so a hostile name cannot start a workflow command.

Limits

  • Deletes use the id the provider's list API returned, never a name.
  • Protected resources are never listed as deletable: default and primary branches, production deployments and environments, the latest Worker version, and anything listed under protect in the config.
  • Fail closed: if your token cannot read the repo, no preview is classed merged, closed or missing and all mapped previews are kept.
  • Any other PR lookup error (5xx, 429, network) keeps the preview with the note PR lookup failed.
  • Railway PR environment naming is unverified: no real payload was checked. Run plan and check the pr column before the first apply, and set pr_pattern if needed.
  • Cloudflare documents no API to delete a Worker version, so Workers versions are report-only.
  • Fork PR previews can only be found by explicit PR number, or by branch where the provider names the head owner (Vercel); a miss is kept.
  • Fly apps have no created_at, so age is the oldest machine's; app_pattern is required so production apps are never in scope.

Install Chaffbroom Winnow

Deletes preview environments whose pull request is merged, closed or gone, or that are past their TTL.