MemtraceDOCS

Git hooks

Install native git hooks so Memtrace can guard pushes and, optionally, add lightweight blast-radius context before commits.

Memtrace uses native git hooks because they run no matter how git is invoked: a terminal, an editor, or an agent. The default hook protects git push. The optional pre-commit hook gives local blast-radius context without blocking commits.

Why two hooks#

Pushes are the right place for a blocking gate: code is about to leave the machine, and fixing it locally is still cheap. Commits happen much more often, so the pre-commit hook is opt-in and advisory.

terminal
$ memtrace install-hooks
# installs the pre-push gate only

$ memtrace install-hooks --pre-commit
# installs pre-commit warnings only

$ memtrace install-hooks --pre-commit --pre-push
# installs both managed hooks
PASS BOTH FLAGS TO INSTALL BOTH HOOKS

--pre-commit does not add to the default. It selects the pre-commit hook by itself. To install both hooks, pass --pre-commit --pre-push.

Pre-push gate#

memtrace install-hooks with no flags installs a managed pre-push block. When you rungit push, Memtrace runs its local gate first. If the gate passes, the push proceeds. If it fails, git stops the push so you can fix the issue before it leaves your machine.

Push gateFLOW
passfail
git push
Memtrace gatelocal
Push proceeds
Fix locally
TRIGGERSUPPORTINGSUCCESSREMEDIATION
VariableDefaultDescription
MEMTRACE_PREPUSHTemporary bypass for the installed pre-push hook. Set to off, 0, or false for the current shell.

Pre-commit warnings#

memtrace install-hooks --pre-commit adds an advisory hook before commits. It looks at the staged diff, maps changed lines to symbols in the local graph, and prints a short heads-up about callers that may be affected. It never blocks the commit.

terminal
$ MEMTRACE_PRECOMMIT=off git commit -m "wip"
# bypass just for this shell

$ MEMTRACE_PRECOMMIT_MODE=agent git commit -m "wip"
# return quickly and finish analysis in the background
VariableDefaultDescription
MEMTRACE_PRECOMMITTemporary bypass for the installed pre-commit hook. Set to off, 0, or false for the current shell.
MEMTRACE_PRECOMMIT_MODEblockingSet to agent when an automated commit flow should not wait on analysis.
MEMTRACE_PRECOMMIT_TIMEOUT_MS1500Time budget for the advisory analysis.
TIP

The pre-commit hook stays quiet when the repo has not been indexed yet or Memtrace is not reachable. Commit speed wins over advisory output.

Managed blocks#

Memtrace writes clearly marked blocks into .git/hooks/pre-push and/or .git/hooks/pre-commit. It preserves any hook content you already had above or below those blocks. Re-running memtrace install-hooks refreshes the Memtrace block in place;memtrace uninstall-hooks removes only Memtrace's block.

Git hook file showing existing hook content preserved outside a clearly marked Memtrace managed block.
Managed hook block