Tool hooks are experimental. Expect breaking changes while we iterate.
What do you want to do?
Block dangerous commands
Prevent force pushes, rm -rf, etc.
Lint after file edits
Run ruff, eslint, tsc after changes
Set up environment
direnv, nvm, virtualenv
Block dangerous commands
Create.mux/tool_pre to validate commands before they run. Exit non-zero to block:
Lint after file edits
Create.mux/tool_post to run validation after tools complete:
hook_output and the agent can fix them.
Set up environment
Create.mux/tool_env to configure your shell environment. This file is sourced before every bash tool call:
Unlike hooks,
tool_env doesn’t need to be executable—it’s sourced, not run. It only affects
bash tools.Reference
Environment Variables
Environment Variables
All hooks receive these environment variables:
Post-hook only (
| Variable | Description |
|---|---|
MUX_TOOL | Tool name: bash, file_edit_replace_string, file_read, etc. |
MUX_TOOL_INPUT | JSON string with tool arguments (placeholder if large) |
MUX_TOOL_INPUT_PATH | Path to full input JSON (when input is large) |
MUX_WORKSPACE_ID | Current workspace identifier |
MUX_PROJECT_DIR | Workspace root directory |
tool_post):| Variable | Description |
|---|---|
MUX_TOOL_RESULT | Tool result JSON (truncated if large) |
MUX_TOOL_RESULT_PATH | Path to full result JSON file |
Exit Codes
Exit Codes
| Exit Code | tool_pre behavior | tool_post behavior |
|---|---|---|
0 | Tool executes normally | Success, output shown to agent |
| Non-zero | Tool blocked, error shown to agent | Failure, error shown in hook_output |
Hook Priority & Location
Hook Priority & Location
mux searches for each hook file in this order:
- Project-level:
.mux/<hook> - User-level:
~/.mux/<hook>
tool_pre, tool_post, and tool_env.For SSH workspaces, hooks execute on the remote machine.Timeouts
Timeouts
Hooks must complete within 5 minutes or they’re terminated. Long-running tools (builds, tests) don’t count against this—only hook execution time.
Comparison
Comparison
| Feature | .mux/tool_pre | .mux/tool_post | .mux/tool_env |
|---|---|---|---|
| Purpose | Block dangerous commands | Lint/validate results | Environment setup |
| Runs | Before tool | After tool | Sourced in bash shell |
| Applies to | All tools | All tools | bash tool only |
| Use case | Block force-push | Run ruff/eslint | direnv, nvm, virtualenv |
More examples
Format files after edits
Format files after edits
Log tool execution times
Log tool execution times
Python hook
Python hook