Weekly cleanup of stale Neon branches that cost you money

Every Monday, find the leftover preview databases nobody is using, check them against closed pull requests, remove the safe ones, and report back in Slack.

Agentic Task
NeonGitHubSlackEngineeringOperationsAI ReportsNotifications & AlertsResearch & Monitoring
PromptCreate

Every Monday at 8am, sweep my Neon projects for stale preview branches that are quietly running up storage and compute costs, and clean up the ones that are safe to remove.

Start with Neon List projects to get every project I have access to. For each project, use List branches sorted by updated_at so the least recently touched branches surface first, and use Retrieve branch consumption metrics to find out how much compute and storage each branch has been consuming. Use Retrieve branch details when you need a branch's parent, size, or exact timestamps to make a judgement call.

Then cross-reference the branch names against GitHub using List Pull Requests, filtering by state so you can tell which pull requests are already closed or merged and which are still open. Preview branches are normally named after the pull request or the git branch they were created for, so match on that naming convention, and do not force a match that is not really there.

Delete a branch with Delete branch only when both conditions hold: its pull request is closed or merged, and the branch has not been updated in more than 14 days. Never touch a project's default branch, and never touch any branch matching a protected pattern such as main, prod, or keep-*.

When a branch is ambiguous, list it in the Slack summary as a suggestion rather than deleting it. Ambiguous means there is no matching pull request at all, or there is an open pull request that looks abandoned. I would rather review those myself than have you guess.

Finish by posting a summary to Slack with Send a Message. Cover what was deleted, what was kept and why, and how much compute each deleted branch had been burning so I can see where the savings came from. Group the results by project, and put the ambiguous suggestions in their own clearly labelled section.

Close the summary with a reminder that Neon soft-deletes branches for seven days, so anything removed by mistake can still be restored with Recover a deleted branch inside that window.

What does this prompt do?

  • Checks every one of your Neon projects each Monday morning and surfaces the branches nobody has touched in weeks
  • Matches each leftover branch to the pull request it came from, so you can see which ones belong to work that already shipped or got abandoned
  • Removes branches whose pull request is closed and that have sat untouched for more than two weeks, while leaving your default and protected branches completely alone
  • Posts a Slack summary covering what was removed, what was kept and why, and how much compute each removed branch had been quietly burning

What do I need to use this?

  • A Neon account with access to the projects you want swept
  • A GitHub login for the repositories whose pull requests should be checked
  • A Slack workspace and a channel where the weekly summary should land
  • A short list of branch names you never want touched, such as main, prod, or anything starting with keep-

How can I customize it?

  • Change the schedule. Monday at 8am works well as a start-of-sprint tidy-up, but Friday afternoon or the first of the month works just as well.
  • Adjust how old a branch has to be before it counts as stale. Two weeks is a safe default, but a fast-moving team might drop it to one.
  • Add your own protected name patterns so branches like demo, release, or anything belonging to a long-running project never get removed.

FAQs

What happens if it removes a branch I still needed?
Neon keeps deleted branches for seven days before they are gone for good, so a mistake is recoverable. The weekly summary reminds you of this every time it runs, along with the names of everything it removed.
Could this ever delete my production database?
No. The workflow always skips each project's default branch, and it skips anything matching a protected name pattern such as main, prod, or keep-anything. You can add more patterns of your own.
What if a branch does not match any pull request?
It gets listed in the Slack summary as a suggestion for you to look at, never deleted. The same goes for a branch whose pull request is still technically open but looks abandoned. Anything ambiguous is your call, not the workflow's.
Neon can expire branches automatically now. Why do I need this?
Built-in expiration only applies to branches created after you turn it on, so it does nothing about the sprawl you have already accumulated. A recurring sweep clears the existing backlog and keeps catching branches that were created without an expiry set.
Will I actually save much?
It depends on how many preview branches your team creates, but storage is the cost that compounds quietly month over month. Once a branch falls outside your history retention window it starts adding to your bill, and most teams never notice until it is already expensive.

Related templates

Auto-fix your calendar when a flight slips, and flag what's at risk

When your flight moves, your calendar times get corrected automatically and you get a Slack note naming the meetings you're about to miss.

Google Calendar
AviationStack
Slack
Agentic Task
Trace phishing emails to the sending IP and report abuse

Every 15 minutes, forwarded phishing reports get traced back to the server that really sent them, with a verdict in Slack and the worst senders reported.

AbuseIPDB
Gmail
Slack
Agentic Task
Turn procurement portal tenders into CRM deals each morning

Every weekday at 7am, sign in to the tender portals you track, filter new notices against your bid criteria, and open a deal for the ones worth chasing.

Anchor Browser
Google Sheets
HubSpot
+1
Agentic Task
Replay failed SQS messages when a bug fix is merged

When you merge a fix in GitHub, this agent checks the matching dead-letter queue, replays the failed messages, and reports back on the pull request and in Slack.

Amazon SQS
GitHub
Slack Bot
Agentic Task
Turn each week's football fixtures into a venue staffing plan

Every Monday, rank the week's matches by expected demand, put the big ones on your venue calendar, and post a rota-ready summary to Slack.

API-Sports
Google Calendar
Slack
Agentic Task
Turn 5 star Yotpo reviews into a weekly marketing content queue

Every Tuesday we pull your best new reviews, draft social captions, email testimonials and product page quotes, then stage them in Notion for approval.

Yotpo
Notion
Slack
Agentic Task

Stop paying for preview databases nobody uses.

Set this up once and your Neon bill stops quietly growing with every sprint.