GuideJuly 1, 20256 min read

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:

~/.configsync/config.yaml
hooks: pre_push: - "code --list-extensions > ~/.config/vscode-extensions.txt" - "brew bundle dump --file=~/.Brewfile --force" post_push: - "echo 'Push complete at $(date)' >> ~/.configsync/sync.log" pre_pull: - "cp ~/.zshrc ~/.zshrc.backup" post_pull: - "brew bundle install --file=~/.Brewfile --no-lock" - "source ~/.zshrc"

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 TypeOn FailureUse Case
pre_pushAborts the pushValidation, capture dependencies
post_pushWarns but continuesLogging, notifications
pre_pullAborts the pullBackup current files
post_pullWarns but continuesInstall 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:

Available environment variables
$CONFIGSYNC_HOOK # Current hook name: "pre_push", "post_pull", etc. $CONFIGSYNC_ENV # Active environment: "development", "production", etc. $CONFIGSYNC_PROFILE # Active profile name: "work", "personal", etc.

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.

Timeout: Each hook command has a 5-minute timeout. If a command takes longer than 5 minutes, it is killed and treated as a failure. For long-running installations, consider running them in the background within your hook script.

Practical Hook Examples

Here are hooks that solve real problems developers face when syncing between machines:

Capture VS Code extensions before push
hooks: pre_push: - "code --list-extensions > ~/.config/vscode-extensions.txt"
Install everything after pull
hooks: post_pull: # Install Homebrew packages - "brew bundle install --file=~/.Brewfile --no-lock" # Install VS Code extensions - "cat ~/.config/vscode-extensions.txt | xargs -L 1 code --install-extension" # Reload shell config - "source ~/.zshrc"
Backup before pull
hooks: pre_pull: - "mkdir -p ~/.configsync-backups/$(date +%Y%m%d)" - "cp ~/.zshrc ~/.configsync-backups/$(date +%Y%m%d)/ 2>/dev/null || true" - "cp ~/.gitconfig ~/.configsync-backups/$(date +%Y%m%d)/ 2>/dev/null || true"

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:

Team hook configuration
hooks: pre_push: # Ensure ESLint config is valid - "npx eslint --print-config .eslintrc.js > /dev/null" # Capture current tool versions - "node --version > ~/.config/tool-versions.txt" - "python3 --version >> ~/.config/tool-versions.txt" post_pull: # Install team CLI tools - "brew bundle install --file=~/.Brewfile --no-lock" # Set up git hooks for all repos - "find ~/work -name .git -type d -exec sh -c 'cd {}/.. && npx husky install 2>/dev/null' \;" # Verify required tools are installed - "command -v docker || echo 'WARNING: Docker not installed'"

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.