Git hook written on JavaScript
Outwith the improved error handling as per the comments, another improvement on this be to write the hook using a more synchronous approach e.g.

#.git/hooks/prepare-commit-msg
#!/usr/bin/env node

const { readFileSync, writeFileSync } = require('fs')
const { execSync } = require('child_process')
const COMMIT_EDITMSG = process.argv[2];

const stdout = execSync('git symbolic-ref --short HEAD');
const message = readFileSync(COMMIT_EDITMSG, 'utf-8');
writeFileSync(COMMIT_EDITMSG, `${stdout.replace(/(-|_).*/, '')} ${message}`.replace(/\n/, ''));


This completely eliminates the need for callbacks and, naturally, if an error occurs the commit should be blocked - it's also a lot more succinct and easier to read.