Files
OpenFlare/.dmux-hooks/examples/worktree_created.example
T
2026-06-18 10:29:48 +08:00

49 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Example: worktree_created hook
#
# This hook runs after a new worktree is created and before the agent launches.
# Use it to set up the worktree environment (install deps, copy configs, etc.)
# Stdout/stderr is streamed into the new pane's setup UI while this hook runs.
# dmux waits for this hook without a fixed timeout.
set -e # Exit on error
status() {
if [ "${DMUX_PROGRESS:-0}" = "1" ]; then
echo "${DMUX_STATUS_PREFIX:-DMUX_STATUS:} $*"
else
echo "[Hook] $*"
fi
}
status "Setting up worktree: $DMUX_SLUG"
cd "$DMUX_WORKTREE_PATH"
# Install dependencies before the agent launches.
if [ -f "pnpm-lock.yaml" ]; then
status "Installing dependencies with pnpm"
pnpm install --prefer-offline
elif [ -f "package-lock.json" ]; then
status "Installing dependencies with npm"
npm install
elif [ -f "yarn.lock" ]; then
status "Installing dependencies with yarn"
yarn install
fi
# Copy environment file if it exists
if [ -f "$DMUX_ROOT/.env.local" ]; then
status "Copying .env.local"
cp "$DMUX_ROOT/.env.local" "$DMUX_WORKTREE_PATH/.env.local"
fi
# Keep existing git author identity.
# Do not set git user.name/user.email in this hook.
# Create a log entry
echo "[$(date)] Created worktree: $DMUX_SLUG | Agent: $DMUX_AGENT | Prompt: $DMUX_PROMPT" \
>> "$DMUX_ROOT/.dmux/worktree_history.log"
status "Worktree setup complete"