Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions .claude/hooks/setup-flox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,48 @@ fi

PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}"
VENV_DIR="$PROJECT_DIR/.flox/cache/venv"
CACHE_FILE="$PROJECT_DIR/.flox/cache/claude-env-cache"
FLOX_MANIFEST="$PROJECT_DIR/.flox/env/manifest.toml"

# Step 1: Capture the flox activation environment (hook.on-activate runs,
# but [profile] scripts do NOT run in non-interactive `bash -c`).
# Checksum the flox manifest to auto-invalidate cache on env changes
MANIFEST_HASH=""
if [ -f "$FLOX_MANIFEST" ]; then
if command -v md5sum &>/dev/null; then
MANIFEST_HASH=$(md5sum "$FLOX_MANIFEST" | awk '{print $1}')
elif command -v md5 &>/dev/null; then
MANIFEST_HASH=$(md5 -q "$FLOX_MANIFEST")
fi
fi

# Fast path: reuse cached env if manifest hash matches
if [ -f "$CACHE_FILE" ] && [ -n "$MANIFEST_HASH" ]; then
CACHED_HASH=$(head -1 "$CACHE_FILE" | sed 's/^# manifest-hash: //')
if [ "$CACHED_HASH" = "$MANIFEST_HASH" ]; then
tail -n +2 "$CACHE_FILE" >> "$CLAUDE_ENV_FILE"
exit 0
fi
fi

# Slow path: capture the flox activation environment
FLOX_ENV_SNAPSHOT=$(flox activate --dir "$PROJECT_DIR" -- bash -c 'printenv' 2>/dev/null)

if [ $? -ne 0 ] || [ -z "$FLOX_ENV_SNAPSHOT" ]; then
echo "Warning: flox activate failed, skipping env setup" >&2
exit 0
fi

# Step 2: Extract key env vars from flox and write them to CLAUDE_ENV_FILE.
# We capture PATH and all FLOX_* vars, plus project-specific vars from [vars].
echo "$FLOX_ENV_SNAPSHOT" | grep -E "^(PATH|FLOX_|UV_PROJECT_ENVIRONMENT|OPENSSL_|LDFLAGS|CPPFLAGS|RUST_|LIBRARY_PATH|MANPATH|DOTENV_FILE|DEBUG|POSTHOG_SKIP_MIGRATION_CHECKS|FLAGS_REDIS_URL|RUSTC_WRAPPER|SCCACHE_)=" | while IFS='=' read -r key value; do
printf 'export %s=%q\n' "$key" "$value"
done >> "$CLAUDE_ENV_FILE"
ENV_CONTENT=""
while IFS='=' read -r key value; do
ENV_CONTENT="${ENV_CONTENT}$(printf 'export %s=%q\n' "$key" "$value")"$'\n'
done < <(echo "$FLOX_ENV_SNAPSHOT" | grep -E "^(PATH|FLOX_|UV_PROJECT_ENVIRONMENT|OPENSSL_|LDFLAGS|CPPFLAGS|RUST_|LIBRARY_PATH|MANPATH|DOTENV_FILE|DEBUG|POSTHOG_SKIP_MIGRATION_CHECKS|FLAGS_REDIS_URL|RUSTC_WRAPPER|SCCACHE_)=")

# Step 3: The flox [profile] scripts also activate the uv venv, which adds
# the venv's bin/ to PATH. Since [profile] doesn't run in `bash -c`, we do
# this manually by prepending the venv bin dir to PATH.
if [ -d "$VENV_DIR/bin" ]; then
echo "export PATH=\"${VENV_DIR}/bin:\$PATH\"" >> "$CLAUDE_ENV_FILE"
echo "export VIRTUAL_ENV=\"${VENV_DIR}\"" >> "$CLAUDE_ENV_FILE"
ENV_CONTENT="${ENV_CONTENT}export PATH=\"${VENV_DIR}/bin:\$PATH\""$'\n'
ENV_CONTENT="${ENV_CONTENT}export VIRTUAL_ENV=\"${VENV_DIR}\""$'\n'
fi

mkdir -p "$(dirname "$CACHE_FILE")"
printf '%s' "$ENV_CONTENT" >> "$CLAUDE_ENV_FILE"
printf '# manifest-hash: %s\n%s' "$MANIFEST_HASH" "$ENV_CONTENT" > "$CACHE_FILE"

exit 0
2 changes: 2 additions & 0 deletions .posthog-code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
worktrees/
worktrees-dev/
7 changes: 7 additions & 0 deletions .posthog-code/environments/posthog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id = "a53111b2-2019-4a21-a4c6-63436a0769d3" # DO NOT EDIT MANUALLY
version = 1

name = "posthog"

[setup]
script = "direnv allow ."
3 changes: 3 additions & 0 deletions .worktreeinclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
.env.local
.envrc
1 change: 1 addition & 0 deletions .worktreelink
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.flox
Loading