You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Fix] omp-hooks.ts: Stop git guards from screaming outside repos #147
[Fix] omp-hooks.ts: Stop git guards from screaming outside repos
The problem
omp-hooks.ts was running git rev-parse --abbrev-ref HEAD on every bash command — even when you're not in a git repo. Result: stderr spam on every command:
fatal: not a git repository (or any parent up to mount point)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM)
Annoying, and it happens constantly when working outside repos.
Environment where observed: pi coding agent on Termux (Android)
Root cause
currentBranch() fired unconditionally inside the tool_call handler. No check for "am I even in a git repo?"
Fix
Added inGitRepo(cwd) — runs git rev-parse --git-dir with stdio: "ignore" so it fails silently
Early exit in the handler if not in a repo — zero git commands run
Pass cwd from event.context?.cwd to all git calls
What changed in extensions/omp-hooks.ts
New inGitRepo(cwd?: string): boolean helper
currentBranch(cwd?: string) now checks inGitRepo first, returns "" if outside a repo
tool_call handler grabs cwd from event context, bails early if !inGitRepo(cwd)
Testing
Run any command outside a git repo → silent, no errors
Run git status inside a repo → guards work normally (dangerous patterns, protected branches, Conventional Commits)
Breaking changes
None. Inside repos, behavior is identical. Outside, it just shuts up.
Note: The guard-git skill's hook scripts (scripts/hooks/*/pre-tool-git-guard.sh) already handle this correctly. This brings omp-hooks.ts in line.
Also reproduced on macOS (Darwin 27, bigpowers 2.88.9, Pi). When Pi's working directory is not a Git repository, every bash tool call prints fatal: not a git repository (or any of the parent directories): .git over the Pi editor/status area.
The cause is currentBranch() in extensions/omp-hooks.ts. It catches the exception, but execSync inherits stderr, so git's message still reaches the terminal. A one-line change fixes it for me and keeps branch detection working inside repos:
#146 had this exact change plus a regression test in scripts/omp-smoke.ts, but it was closed without review. Could #146 be reopened or the fix landed? Happy to help test.
@ak-a-ra — Thank you for filing this from Termux on Android — that alone shows dedication. Your inGitRepo(cwd) approach is exactly right: a cheap rev-parse --git-dir with stdio:ignore makes the happy path zero-cost and silent. You made this better for every constrained or unusual environment. Applying your fix now.
Thanks for the quick response and for incorporating the fix! 🙏 I appreciate you addressing this issue and getting the fix into v2.88.11. I'll test the release on my Termux setup. Thanks again for maintaining Bigpowers!
Reproduced on Termux/Android with bigpowers 2.88.16 (current npm @latest) — so this is not the stale-install case, and it is not fully covered by the fix that shipped in 2.88.11.
What I found
The 2.88.11 fix added inGitRepo() + early exit, using git rev-parse --git-dir. That covers not-a-repo. It does not cover a repo with zero commits (unborn HEAD), because git rev-parse --git-dirsucceeds there (exit 0, prints .git). The guard passes, then currentBranch() (extensions/omp-hooks.ts:207) still runs:
stderr leaks — no stdio override, so git's fatal reaches the terminal on every bash tool call in a fresh repo, even for ls/echo. The sibling helper inGitRepo() already does this right (stdio: "ignore").
protected-branch guard silently bypassed — the catch returns "unknown", so PROTECTED_BRANCHES / branch === "main" never match. First git commit on master/main in a brand-new repo is not blocked. This is the security-relevant half.
Confirmed still unfixed on main today (currentBranch at line 207 has no stdio; handler lines 418–420 call it unconditionally once inGitRepo passes).
This is also the exact leak flagged in the comment above (stdio: ["ignore","pipe","ignore"] on currentBranch) and in #146 — that half never landed.
Proof
Repro:
D=$(mktemp -d)&&cd"$D"&& git init -q .# zero commits => unborn HEAD
git rev-parse --git-dir # exit 0 => inGitRepo() passes
git rev-parse --abbrev-ref HEAD # exit 128, prints the fatal below
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Ran the real tool_call handler (loaded via scripts/omp-smoke.ts-style harness) with process.chdir() into that unborn repo, before vs after the patch:
currentBranch() impl
stderr
echo hi
git commit -m "feat: initial"
main (rev-parse --abbrev-ref HEAD)
2× the fatal above
allowed
allowed — guard missed
patched (symbolic-ref --short -q HEAD + stdio: ["ignore","pipe","ignore"])
silent
allowed
BLOCKED: Direct commits to 'master'
Regression test — core of that harness, drop into a scripts/omp-smoke.ts-style setup (handler = the registered tool_call listener, plus the node:fs / node:os / node:path / node:child_process imports it needs):
// A git repo with zero commits: `rev-parse --git-dir` succeeds, so the// inGitRepo guard passes, but `rev-parse --abbrev-ref HEAD` exits 128.constrepo=mkdtempSync(join(tmpdir(),"bigpowers-unborn-"));execSync("git init -q .",{cwd: repo,stdio: "ignore"});constpreviousCwd=process.cwd();process.chdir(repo);try{// Ordinary command must stay unblocked.if(handler({toolName: "bash",input: {command: "echo hi"}})!==undefined){thrownewError("unborn HEAD: benign command was blocked");}// First commit on the unborn protected branch MUST be blocked.constcommit=handler({toolName: "bash",input: {command: 'git commit -m "feat: initial"'},})as{block?: boolean;reason?: string}|undefined;if(!commit?.block){thrownewError("unborn HEAD: first commit on protected branch was NOT blocked "+"(currentBranch resolved to 'unknown' instead of the branch name)",);}if(!/master|main/.test(commit.reason??"")){thrownewError(`unborn HEAD: block reason lacks branch name: ${commit.reason}`);}}finally{process.chdir(previousCwd);rmSync(repo,{recursive: true,force: true});}
Result: RED on main (first commit on protected branch was NOT blocked (currentBranch resolved to 'unknown' instead of the branch name)), GREEN with the patch (PASS). scripts/omp-smoke.ts still passes with the patch applied.
What I patched
extensions/omp-hooks.ts:207:
function currentBranch(cwd: string): string {
try {
- return execSync("git rev-parse --abbrev-ref HEAD", {- encoding: "utf-8",- timeout: 3000,- cwd,- }).trim();+ // `git symbolic-ref` — NOT `git rev-parse --abbrev-ref HEAD`.+ // In a repo with no commits yet (unborn HEAD), rev-parse exits 128 with+ // `fatal: ambiguous argument 'HEAD': unknown revision or path not in+ // the working tree.` on stderr. Because stderr was not suppressed here,+ // that fatal leaked into every bash tool call in a fresh repo, and the+ // caught failure also returned "unknown" — silently disabling the+ // protected-branch commit guard for first commits on main/master.+ // `symbolic-ref --short -q HEAD` resolves the branch name even when HEAD+ // is unborn, is silent on detached HEAD, and stderr is ignored.+ return execSync("git symbolic-ref --short -q HEAD", {+ encoding: "utf-8",+ timeout: 3000,+ cwd,+ stdio: ["ignore", "pipe", "ignore"],+ }).trim();
} catch {
return "unknown";
}
}
Behavior of git symbolic-ref --short -q HEAD:
repo state
output
exit
unborn HEAD (0 commits)
master
0
normal
master
0
detached HEAD
(empty)
1 → "unknown", same as before
No change inside repos that already have commits; guards keep working on fresh ones.
Where the patch currently lives: my installed copy, ~/.pi/agent/npm/node_modules/bigpowers/extensions/omp-hooks.ts — applied there to validate it. That edit is wiped by the next npm i -g bigpowers, which is why I'm reporting it rather than just fixing it locally.
One extra finding from the same file, lower severity: line 418 uses process.cwd() for the repo gate rather than event.context?.cwd (as proposed earlier in this issue). Fails closed, but a bash command that cds into a different repo makes the gate answer with the wrong repo's branch. Worth folding into the same change.
Happy to open the PR against main with the diff + regression test wired into scripts/omp-smoke.ts — just confirm and the story tag if you want one.
Activity
tharanee-bit commentedon Oct 17, 2026
Also reproduced on macOS (Darwin 27, bigpowers 2.88.9, Pi). When Pi's working directory is not a Git repository, every bash tool call prints
fatal: not a git repository (or any of the parent directories): .gitover the Pi editor/status area.The cause is
currentBranch()inextensions/omp-hooks.ts. It catches the exception, butexecSyncinherits stderr, so git's message still reaches the terminal. A one-line change fixes it for me and keeps branch detection working inside repos:#146 had this exact change plus a regression test in
scripts/omp-smoke.ts, but it was closed without review. Could #146 be reopened or the fix landed? Happy to help test.danielvm-git commentedon Oct 25, 2026
@ak-a-ra — Thank you for filing this from Termux on Android — that alone shows dedication. Your inGitRepo(cwd) approach is exactly right: a cheap rev-parse --git-dir with stdio:ignore makes the happy path zero-cost and silent. You made this better for every constrained or unusual environment. Applying your fix now.
chore(release): 2.88.11 [skip ci]
github-actions commentedon Oct 25, 2026
🎉 This issue has been resolved in version 2.88.11 🎉
The release is available on:
Your semantic-release bot 📦🚀
ak-a-ra commentedon Oct 25, 2026
Thanks for the quick response and for incorporating the fix! 🙏 I appreciate you addressing this issue and getting the fix into v2.88.11. I'll test the release on my Termux setup. Thanks again for maintaining Bigpowers!
ak-a-ra commentedon Oct 27, 2026
Reproduced on Termux/Android with bigpowers 2.88.16 (current npm
@latest) — so this is not the stale-install case, and it is not fully covered by the fix that shipped in 2.88.11.What I found
The 2.88.11 fix added
inGitRepo()+ early exit, usinggit rev-parse --git-dir. That covers not-a-repo. It does not cover a repo with zero commits (unbornHEAD), becausegit rev-parse --git-dirsucceeds there (exit 0, prints.git). The guard passes, thencurrentBranch()(extensions/omp-hooks.ts:207) still runs:Two consequences:
stdiooverride, so git's fatal reaches the terminal on every bash tool call in a fresh repo, even forls/echo. The sibling helperinGitRepo()already does this right (stdio: "ignore").catchreturns"unknown", soPROTECTED_BRANCHES/branch === "main"never match. Firstgit commitonmaster/mainin a brand-new repo is not blocked. This is the security-relevant half.Confirmed still unfixed on
maintoday (currentBranchat line 207 has nostdio; handler lines 418–420 call it unconditionally onceinGitRepopasses).This is also the exact leak flagged in the comment above (
stdio: ["ignore","pipe","ignore"]oncurrentBranch) and in #146 — that half never landed.Proof
Repro:
Ran the real
tool_callhandler (loaded viascripts/omp-smoke.ts-style harness) withprocess.chdir()into that unborn repo, before vs after the patch:currentBranch()implecho higit commit -m "feat: initial"main(rev-parse --abbrev-ref HEAD)symbolic-ref --short -q HEAD+stdio: ["ignore","pipe","ignore"])BLOCKED: Direct commits to 'master'Regression test — core of that harness, drop into a
scripts/omp-smoke.ts-style setup (handler= the registeredtool_calllistener, plus thenode:fs/node:os/node:path/node:child_processimports it needs):Result: RED on
main(first commit on protected branch was NOT blocked (currentBranch resolved to 'unknown' instead of the branch name)), GREEN with the patch (PASS).scripts/omp-smoke.tsstill passes with the patch applied.What I patched
extensions/omp-hooks.ts:207:function currentBranch(cwd: string): string { try { - return execSync("git rev-parse --abbrev-ref HEAD", { - encoding: "utf-8", - timeout: 3000, - cwd, - }).trim(); + // `git symbolic-ref` — NOT `git rev-parse --abbrev-ref HEAD`. + // In a repo with no commits yet (unborn HEAD), rev-parse exits 128 with + // `fatal: ambiguous argument 'HEAD': unknown revision or path not in + // the working tree.` on stderr. Because stderr was not suppressed here, + // that fatal leaked into every bash tool call in a fresh repo, and the + // caught failure also returned "unknown" — silently disabling the + // protected-branch commit guard for first commits on main/master. + // `symbolic-ref --short -q HEAD` resolves the branch name even when HEAD + // is unborn, is silent on detached HEAD, and stderr is ignored. + return execSync("git symbolic-ref --short -q HEAD", { + encoding: "utf-8", + timeout: 3000, + cwd, + stdio: ["ignore", "pipe", "ignore"], + }).trim(); } catch { return "unknown"; } }Behavior of
git symbolic-ref --short -q HEAD:mastermaster"unknown", same as beforeNo change inside repos that already have commits; guards keep working on fresh ones.
Where the patch currently lives: my installed copy,
~/.pi/agent/npm/node_modules/bigpowers/extensions/omp-hooks.ts— applied there to validate it. That edit is wiped by the nextnpm i -g bigpowers, which is why I'm reporting it rather than just fixing it locally.One extra finding from the same file, lower severity: line 418 uses
process.cwd()for the repo gate rather thanevent.context?.cwd(as proposed earlier in this issue). Fails closed, but a bash command thatcds into a different repo makes the gate answer with the wrong repo's branch. Worth folding into the same change.Happy to open the PR against
mainwith the diff + regression test wired intoscripts/omp-smoke.ts— just confirm and the story tag if you want one.fix(omp-hooks): inGitRepo bail-early, accept type!(scope) form, echo …