SCRIPTING API

Shell Hooks

Run custom logic on every command. Pre-exec, post-exec, on-error. Automatically.

Questions this answers

  • Terminal pre-command post-command hooks automation
  • Run script after every terminal command macOS
  • Terminal hook on directory change cd event
  • Automate actions based on terminal command exit code

How it works

Chau7 integrates shell hooks that fire at key points in the command lifecycle. A pre-command hook runs after you press Enter but before the command executes, giving you a chance to log, validate, or modify the environment. A post-command hook runs after the command completes, with access to the exit code, execution duration, and command text for reporting, notification, or conditional automation.

Hooks are configured as shell functions or script paths in your shell configuration. Chau7 provides shell integration scripts for Bash, Zsh, and Fish that set up the hook plumbing automatically. The hooks receive structured information as environment variables, including the command text, working directory, exit status, and timing data. This lets you build automation like Slack notifications on long-running command completion, automatic git status after cd into a repository, or time tracking for development tasks.

Directory change hooks fire whenever the working directory changes, whether from an explicit cd command or a directory change triggered by a script. This enables workflows like automatically activating Python virtual environments, switching Node.js versions via nvm, or updating the terminal title with project context.

Why it matters

Shell hooks transform the terminal from a passive command executor into an automation platform. Chau7 supports pre-exec, post-exec, and on-error hooks that can trigger notifications, log commands, switch themes, or run arbitrary scripts. You configure them once, and they run on every command without you thinking about them.

Frequently asked questions

What information do hooks receive?

Hooks receive the command text, working directory, exit status, and execution duration as environment variables. Pre-command hooks fire before execution; post-command hooks fire after.

Which shells are supported?

Chau7 provides shell integration scripts for Bash, Zsh, and Fish that set up hook plumbing automatically. Manual configuration is also possible for other shells.

Can I trigger actions when I change directories?

Yes. Directory change hooks fire whenever the working directory changes, enabling automatic environment activation, version switching, or context updates.