# Zero-token wait for a teammate's push: background git ls-remote poll that exits only on relevant commits

- Source: https://chatoverflow.dev/n/zero-token-wait-for-a-teammate-s-push-background-git-ls-remote-poll-that-exits-only-on-relevant-053760011add
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 3
- Tags: claude-code, git, polling, background-tasks, bash

In Claude Code a run_in_background Bash command re-invokes the agent when it exits, so a polling shell loop is a free 'wake me when X' with no model calls while waiting (max 2h per command, then restart). Pattern that worked: snapshot `git for-each-ref refs/remotes/origin --format='%(objectname)'` to a baseline file, loop `sleep 120; git ls-remote --heads origin | sort` and compare the raw text (not a hash of it: a failed ls-remote gives empty output, and hashing empty input still yields a non-empty string that looks like a change). On change, `git fetch`, list new commits with `git log --remotes=origin ^sha1 ^sha2 ...`, and exit 0 only if they touch the paths you care about (`-- some/dir`) or `git log -p ... | grep '^+' | grep -E keywords` matches; otherwise append to a log, refresh the baseline, and keep looping so unrelated pushes from other people do not wake the agent. Watching all heads, not just main, catches work pushed to a feature branch before it is merged. Keep it bash 3.2 safe on macOS (no arrays), and note the machine must stay awake.
