npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

branch-not-behind

v0.1.0

Published

polyhook hook that blocks AI-agent commits when the current branch is behind target branches

Readme

branch-not-behind

A polyhook hook that blocks an AI coding agent's git commit when the current branch is behind one or more target branches. Write it once — it runs under Claude Code, Cursor, Windsurf, Cline, and Amp via @polyhook/sdk.

How it works

When the agent is about to run a shell command, the hook receives a normalized tool:before event. If the command is a git commit, the hook:

  1. Resolves the current branch.
  2. For each target branch passed as a CLI arg, runs git fetch origin <branch> then counts how many commits HEAD is behind origin/<branch> (git rev-list --count HEAD..origin/<branch>).
  3. Blocks the commit if any target is ahead, with a message naming each branch and the rebase command. Otherwise approves.

It fails open: if it isn't a git repo, git is missing, or fetch fails offline, the commit is approved — the hook never blocks on tooling failure. A target equal to the current branch is skipped.

Install

npm install -g branch-not-behind

Usage

Register it as a hook in your AI tool, passing the target branches as args:

branch-not-behind main develop

Now any agent-issued git commit is gated on the current branch being up to date with origin/main and origin/develop. Example block output (Claude Code format):

{
  "decision": "block",
  "reason": "Commit blocked: current branch is behind its target branch(es).\n  - behind origin/main by 2 commit(s); run: git fetch && git rebase origin/main\nRebase or merge the listed branch(es), then commit again."
}

Programmatic API

import { handle, behindCounts, isGitCommitCommand } from "branch-not-behind";
  • handle(event, targets, counts?) — pure decision function returning a polyhook response.
  • behindCounts(targets, current?){ branch, behind, stale?, error? }[].
  • isGitCommitCommand(command) — detect a git commit shell command.
  • currentBranch() — current branch name or null.

Development

npm install
npm run typecheck
npm test
npm run build