spawn-bin.ts
Shared helper for the hooks: resolves and spawns gstack's bash bins on Windows, and provides a contained runner for external executables.
- Kind
- Hook
- Works with
- Claude Code
- Languages
- TypeScript / JavaScript, Shell
- Source
- garrytan/gstack @ 01593aa67c94
- Path
- hosts/claude/hooks/spawn-bin.ts
- License
- MIT
- Jobs
- Implementation
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
/**
* Windows-safe resolution + spawn for gstack's bash bins. Two Windows-only
* bugs made every hook subprocess a silent no-op; both are fixed here so all
* call sites are covered at once.
*
* 1. `new URL(import.meta.url).pathname` yields `/C:/Users/...`; path.resolve
* then rebases it onto the drive root as `C:\C:\Users\...`. fileURLToPath
* is the correct conversion. (ENOENT before the bin ever ran.)
* 2. `bin/gstack-*` are extensionless bash scripts. Windows has no shebang
* support, so they must be handed to bash explicitly.
*
* Also home to runExternal: the contained runner for EXTERNAL executables
* (third-party binaries a hook hands data to; see its doc comment). Unlike
* runBin it refuses win32, because its guarantee is process-group containment.
*/
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
import { spawn, spawnSync, type SpawnSyncOptions } from 'child_process';
// Forward slashes on purpose: Bun's spawnSync on Windows returns ENOENT for a
// backslash exe path containing spaces.
const GIT_BASH = 'C:/Program Files/Git/bin/bash.exe';
…