fix(code): apply SessionStart hook env to UI git/gh commands#1915
Draft
posthog[bot] wants to merge 1 commit intomainfrom
Draft
fix(code): apply SessionStart hook env to UI git/gh commands#1915posthog[bot] wants to merge 1 commit intomainfrom
posthog[bot] wants to merge 1 commit intomainfrom
Conversation
The Commit and Create PR buttons run git/gh in the main process via `simple-git` and `execGh`, both of which were inheriting bare `process.env`. That ignored the env updates the Claude Agent SDK applies for each session via SessionStart-style hooks (which the SDK writes as `<event>-hook-N.sh` files under `<CLAUDE_CONFIG_DIR>/session-env/<sessionId>/` and sources before its own bash tool commands). Most visibly, when a user has the Secretive code-signing hook installed and launches PostHog Code from the Dock (so the parent process inherits the default macOS launchd `SSH_AUTH_SOCK`), the agent can sign commits but the UI buttons cannot — the same `SSH_AUTH_SOCK` repoint never reached the git subprocess they spawn. Mirror the SDK's behavior in the main process: - New `loadSessionEnvOverrides(sessionId)` util sources the SDK's hook files via bash and returns the env diff (skipping shell internals). - `AgentService.getSessionEnvForTask(taskId)` resolves the most recent active session for a task and returns its overrides. - Plumb an optional `env` through `@posthog/git` (`execGh`, `GitSagaInput`, `ExecuteOptions`) so it reaches both the simple-git client and `gh`. - `GitService.commit` and `createPr` look up the session env when a `taskId` is present and thread it through commit / push / publish / `gh pr create`. Generated-By: PostHog Code Task-Id: 86938233-5c7d-4285-b996-6bd9cf09b57c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Commit and Create PR buttons run git/gh from the main process (via
simple-gitandexecGh), and both were inheriting bareprocess.env. That ignored the env updates the Claude Agent SDK applies per session through SessionStart-style hooks — the SDK writes each hook's output to<CLAUDE_CONFIG_DIR>/session-env/<sessionId>/<event>-hook-<N>.shand sources those files before each of its own bash tool commands.Most visibly: when a user has the Secretive code-signing hook installed and launches PostHog Code from the Dock (so the parent inherits the default macOS launchd `SSH_AUTH_SOCK`), the agent can sign commits but the UI Commit / Create PR buttons cannot — the `SSH_AUTH_SOCK` repoint the hook performs never reaches the git subprocess they spawn.
Changes
Mirror the SDK's session-env behavior in the main process so UI-triggered git/gh sees the same env the agent does:
Test plan
Created with PostHog Code