Weekly cleanup of stale Neon branches that cost you money

By General Input

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.

Integrations

  • Neon
  • GitHub
  • Slack

Type

Agentic Task

Categories

  • Engineering
  • Operations

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.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredChat quality review board for LiveChat support leadsWin back no-show and cancelled appointments every morningLive Loop returns analytics with product-level drill-downNewsletter pre-flight and approval board for Mailjet sendsTurn a prospect spreadsheet into personalized sequence enrollmentsMailjet email delivery lookup console for support teamsCatch feature flags that never got switched on in productionKajabi customer support console for member access fixes