Pre and Post Hooks: Automate Everything Around Your Sync
Capture VS Code extensions before pushing. Install Homebrew packages after pulling. ConfigSync hooks let you automate everything around your sync operations.
What Hooks Are
Hooks are shell commands that run automatically at specific points during a sync operation. ConfigSync supports four hook points: before a push, after a push, before a pull, and after a pull. They let you extend the sync process with any automation you need.
A common pattern: before pushing, a hook captures a list of installed VS Code extensions. After pulling on a new machine, another hook installs those extensions. The sync handles your config files; hooks handle everything else.
Configuration Format
Hooks are defined in your ConfigSync configuration as arrays of shell commands:
Each hook point accepts multiple commands. They execute in order, one after another.
Pre-Hooks Abort on Failure
Pre-hooks and post-hooks behave differently when a command fails:
| Hook Type | On Failure | Use Case |
|---|---|---|
| pre_push | Aborts the push | Validation, capture dependencies |
| post_push | Warns but continues | Logging, notifications |
| pre_pull | Aborts the pull | Backup current files |
| post_pull | Warns but continues | Install deps, reload shell |
This design mirrors git hooks. Pre-hooks act as gates — if your pre_push linting step fails, the push does not proceed. Post-hooks are best-effort — if a post_pull installation step fails, your config files are already restored and you can fix the issue manually.
Environment Variables in Hooks
ConfigSync sets several environment variables that are available inside hook scripts:
This lets you write hooks that behave differently per context. For example, a post_pull hook could skip installing production dependencies when the active environment is development.
Practical Hook Examples
Here are hooks that solve real problems developers face when syncing between machines:
Real-World Team Hook Setup
For teams, hooks enforce standards and automate onboarding. Here is a setup where pre_push validates configs and post_pull installs team dependencies:
When a new developer joins the team, they pull the shared configuration and the post_pull hooks automatically install the team's Brewfile, set up git hooks, and verify that required tools are present. No onboarding wiki needed.
Ready to try ConfigSync?
Sync your entire dev environment across machines in minutes. Free forever for up to 3 devices.