update claude code tracing to not block claude from finishing#2841
Open
markjm wants to merge 3 commits intolangfuse:mainfrom
Open
update claude code tracing to not block claude from finishing#2841markjm wants to merge 3 commits intolangfuse:mainfrom
markjm wants to merge 3 commits intolangfuse:mainfrom
Conversation
When we run this stopping hook, claude does not finish until the hook is complete (and the traces are flushed). This will prevent claude from starting to process the next prompt. This change updates the script to how we have been using it to spin off the flush into the background so claude can quickly process the stop hook and then keep churning to the next prompt. There is an env variable to control this so the hook is debuggable by unbackgrounding it Figured id submit this upstream because its been valuable to us but if its not of interest to include, no worries!
|
@markjm is attempting to deploy a commit to the langfuse Team on Vercel. A member of the Team first needs to authorize it. |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
markjm
commented
Apr 22, 2026
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.
When we run this stopping hook, claude does not finish until the hook is complete (and the traces are flushed). This will prevent claude from starting to process the next prompt.
This change updates the script to how we have been using it to spin off the flush into the background so claude can quickly process the stop hook and then keep churning to the next prompt.
There is an env variable to control this so the hook is debuggable by unbackgrounding it
Figured id submit this upstream because its been valuable to us but if its not of interest to include, no worries!
Disclaimer: Experimental PR review
Greptile Summary
This PR updates the Claude Code Langfuse Stop-hook script to fork a background child process (
os.fork()+os.setsid()) before doing the heavy Langfuse flush work, so the parent exits immediately and no longer blocks Claude Code from processing the next prompt. A newCC_LANGFUSE_BACKGROUNDenv var (default\"true\") lets users opt back into synchronous mode for debugging.Confidence Score: 4/5
Safe to merge after addressing the os.fork() Windows/WSL portability gap, or after confirming the target audience is Unix-only.
The forking logic is correct on Unix — parent exits immediately, child detaches with setsid() and runs to completion. The only open concern is that os.fork() does not exist on Windows, and with BACKGROUND=true as the default, this will crash the hook rather than silently fall back to sync mode. A one-line hasattr guard resolves it. All other findings are P2 or below.
content/integrations/other/claude-code.mdx — the os.fork() call at line 560 needs a hasattr(os, 'fork') guard.
Important Files Changed
Sequence Diagram
sequenceDiagram participant CC as Claude Code participant Parent as Hook Process (parent) participant Child as Forked Child CC->>Parent: Run Stop hook Parent->>Parent: Validate keys, session, transcript alt BACKGROUND=true (default) Parent->>Child: os.fork() Parent-->>CC: return 0 (exits immediately) Child->>Child: os.setsid() (detach session) Child->>Child: Langfuse.init() Child->>Child: FileLock → read transcript → emit turns Child->>Child: langfuse.flush() Child->>Child: langfuse.shutdown() Child-->>Child: exit else BACKGROUND=false (debug) Parent->>Parent: Langfuse.init() Parent->>Parent: FileLock → read transcript → emit turns Parent->>Parent: langfuse.flush() Parent->>Parent: langfuse.shutdown() Parent-->>CC: return 0 endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "update claude code tracing to not block ..." | Re-trigger Greptile