Skip to content

chore(code): add worktree config for posthog code#52566

Merged
adboio merged 1 commit intomasterfrom
03-27-chore_code_add_worktree_config_for_posthog_code
Mar 30, 2026
Merged

chore(code): add worktree config for posthog code#52566
adboio merged 1 commit intomasterfrom
03-27-chore_code_add_worktree_config_for_posthog_code

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Mar 27, 2026

Problem

this PR adds support for .worktreeinclude and .worktreelink in posthog code: PostHog/code#1344

and we want posthog worktrees to be easy in posthog code :)

Changes

  • adds .worktreeinclude, .worktreelink, and posthog code env setup script to the posthog main repo
  • adds a cache layer to the flox claude setup hook

How did you test this code?

manual testing

worktrees are working smoothly in posthog code with the posthog main repo now

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Publish to changelog?

Docs update

Copy link
Copy Markdown
Contributor Author

adboio commented Mar 27, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adboio adboio force-pushed the 03-27-chore_code_add_worktree_config_for_posthog_code branch 2 times, most recently from cca81ff to c2df7a0 Compare March 28, 2026 01:49
@adboio adboio requested a review from robbie-c March 28, 2026 01:50
@adboio adboio marked this pull request as ready for review March 28, 2026 01:52
@assign-reviewers-posthog assign-reviewers-posthog bot requested a review from a team March 28, 2026 01:52
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 28, 2026

Important Files Changed

Filename Overview
.claude/hooks/setup-flox.sh Added a cache layer for the flox env snapshot; cache never auto-invalidates when flox.toml changes, and mkdir -p ordering is slightly off.
.worktreeinclude New file listing .env, .env.local, .envrc to be copied into each worktree — correct and minimal.
.worktreelink New file symlinking .flox into each worktree so the shared flox environment is available everywhere.
.posthog-code/environments/posthog.toml New posthog-code environment definition with direnv allow . as the setup script.
.posthog-code/.gitignore Ignores worktrees/ and worktrees-dev/ directories generated by the worktree tool.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: .claude/hooks/setup-flox.sh
Line: 22-26

Comment:
**Cache never auto-invalidates on flox environment changes**

The fast path loads the cache unconditionally. If someone updates `flox.toml` (adds/removes packages, changes `[vars]`) and restarts a Claude session, Claude will silently continue using the stale environment — new tools won't be on `PATH`, removed vars will persist, etc. The comment documents manual invalidation, but this is easy to miss in practice.

Consider checksumming the flox manifest to auto-invalidate:

```bash
# Fast path: reuse cached env if flox manifest hasn't changed
FLOX_MANIFEST="$PROJECT_DIR/.flox/env/manifest.toml"
MANIFEST_HASH=""
if command -v md5sum &>/dev/null; then
  MANIFEST_HASH=$(md5sum "$FLOX_MANIFEST" 2>/dev/null | awk '{print $1}')
elif command -v md5 &>/dev/null; then
  MANIFEST_HASH=$(md5 -q "$FLOX_MANIFEST" 2>/dev/null)
fi

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

And then prefix the cache file with `# manifest-hash: $MANIFEST_HASH` on write. Even if `md5sum`/`md5` isn't available, falling through to the slow path is safe.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: .claude/hooks/setup-flox.sh
Line: 46-48

Comment:
**`mkdir -p` called after writing to env file, before writing cache**

The `mkdir -p "$(dirname "$CACHE_FILE")"` is called after `$CLAUDE_ENV_FILE` is written but before the cache file is written. If `.flox/cache/` doesn't exist for some reason (e.g., fresh flox setup without the venv yet), `printf '%s' "$ENV_CONTENT" > "$CACHE_FILE"` will fail silently, and the next session will skip directly to the slow path again (because no cache file exists). This won't cause incorrect behavior, but it means the caching optimization will never take effect in that edge case.

Moving `mkdir -p` before the `$CLAUDE_ENV_FILE` write would be more defensive:

```suggestion
mkdir -p "$(dirname "$CACHE_FILE")"
printf '%s' "$ENV_CONTENT" >> "$CLAUDE_ENV_FILE"
printf '%s' "$ENV_CONTENT" > "$CACHE_FILE"
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "chore(code): add worktree config for pos..." | Re-trigger Greptile

Comment on lines +22 to +26
# Fast path: reuse cached env. Invalidate with: rm .flox/cache/claude-env-cache
if [ -f "$CACHE_FILE" ]; then
cat "$CACHE_FILE" >> "$CLAUDE_ENV_FILE"
exit 0
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cache never auto-invalidates on flox environment changes

The fast path loads the cache unconditionally. If someone updates flox.toml (adds/removes packages, changes [vars]) and restarts a Claude session, Claude will silently continue using the stale environment — new tools won't be on PATH, removed vars will persist, etc. The comment documents manual invalidation, but this is easy to miss in practice.

Consider checksumming the flox manifest to auto-invalidate:

# Fast path: reuse cached env if flox manifest hasn't changed
FLOX_MANIFEST="$PROJECT_DIR/.flox/env/manifest.toml"
MANIFEST_HASH=""
if command -v md5sum &>/dev/null; then
  MANIFEST_HASH=$(md5sum "$FLOX_MANIFEST" 2>/dev/null | awk '{print $1}')
elif command -v md5 &>/dev/null; then
  MANIFEST_HASH=$(md5 -q "$FLOX_MANIFEST" 2>/dev/null)
fi

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

And then prefix the cache file with # manifest-hash: $MANIFEST_HASH on write. Even if md5sum/md5 isn't available, falling through to the slow path is safe.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .claude/hooks/setup-flox.sh
Line: 22-26

Comment:
**Cache never auto-invalidates on flox environment changes**

The fast path loads the cache unconditionally. If someone updates `flox.toml` (adds/removes packages, changes `[vars]`) and restarts a Claude session, Claude will silently continue using the stale environment — new tools won't be on `PATH`, removed vars will persist, etc. The comment documents manual invalidation, but this is easy to miss in practice.

Consider checksumming the flox manifest to auto-invalidate:

```bash
# Fast path: reuse cached env if flox manifest hasn't changed
FLOX_MANIFEST="$PROJECT_DIR/.flox/env/manifest.toml"
MANIFEST_HASH=""
if command -v md5sum &>/dev/null; then
  MANIFEST_HASH=$(md5sum "$FLOX_MANIFEST" 2>/dev/null | awk '{print $1}')
elif command -v md5 &>/dev/null; then
  MANIFEST_HASH=$(md5 -q "$FLOX_MANIFEST" 2>/dev/null)
fi

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

And then prefix the cache file with `# manifest-hash: $MANIFEST_HASH` on write. Even if `md5sum`/`md5` isn't available, falling through to the slow path is safe.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto invalidating would be nice if its not too much overhead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added!

@adboio adboio force-pushed the 03-27-chore_code_add_worktree_config_for_posthog_code branch from c2df7a0 to 722ed34 Compare March 30, 2026 15:23
@adboio adboio requested a review from gantoine March 30, 2026 15:23
Copy link
Copy Markdown
Member

@gantoine gantoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@adboio adboio merged commit a60b28c into master Mar 30, 2026
140 checks passed
@adboio adboio deleted the 03-27-chore_code_add_worktree_config_for_posthog_code branch March 30, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants