feat: add Claude Code Git-linked Agent Tracing automation#3
Draft
jannikmaierhoefer wants to merge 14 commits intomainfrom
Draft
feat: add Claude Code Git-linked Agent Tracing automation#3jannikmaierhoefer wants to merge 14 commits intomainfrom
jannikmaierhoefer wants to merge 14 commits intomainfrom
Conversation
…ecode` Introduces a two-level command hierarchy (`integration` → `claudecode`) so commands are now invoked as `langfuse integration claudecode enable` instead of `langfuse enable`. This structure supports future integrations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the embedded STOP_HOOK_SCRIPT with the advanced version from the Langfuse documentation featuring incremental transcript reading, file locking, proper turn assembly with nested spans/generations/tool observations, and state stored in ~/.claude/state/. Update GIT_COMMIT_HOOK_SCRIPT with _build_release_tag() and _update_env_release() functions from the installed version. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Automatically appends a `Langfuse-Trace: <url>` trailer to commit messages made during Claude Code sessions, linking commits to their Langfuse traces. - Stop hook now persists trace info to ~/.claude/state/langfuse_last_trace.json - New prepare-commit-msg Python script reads trace state and appends trailer - Shell wrapper in .git/hooks/ chains pre-existing hooks via .pre-langfuse backup - enable/disable/status commands updated for the new hook lifecycle - GIT_COMMIT_HOOK_SCRIPT fixed to read from new state file with legacy fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add test comment to .gitignore to trigger prepare-commit-msg hook and verify Langfuse trace trailers are appended correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update test comment to confirm prepare-commit-msg hook appends Langfuse-Trace trailer when TRACE_TO_LANGFUSE is exported. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Langfuse-Trace: https://cloud.langfuse.com/trace/5621f51aff823caa37a049eda480e811
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Langfuse-Trace: https://cloud.langfuse.com/trace/cd9d4bfc05c99cc8b5ad5a8d876e6308
Add a PreToolUse hook (langfuse_session_init_hook.py) that generates a deterministic Langfuse trace ID from the session_id on the first tool use, using langfuse.create_trace_id(seed=session_id) per Langfuse docs. This ensures prepare-commit-msg references the current session's trace rather than a stale one from a previous session. The Stop hook now reads the pre-generated trace_id and passes it via trace_context so emitted turns land under the same deterministic trace. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Langfuse-Trace: https://cloud.langfuse.com/trace/bc1555cd04ce2bc585d9d24fa2e0cf3a
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Langfuse-Trace: https://cloud.langfuse.com/trace/e1dc11168ab4dce48277f991752c20a8
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Langfuse-Trace: https://cloud.langfuse.com/trace/4545f39af1f0169318412c58a790207d
The `||` short-circuit caused pattern-based removal to be skipped when the exact-match removal succeeded, leaving behind .venv/bin/python3 variant hooks. Switched to `|` (bitwise OR) so both passes always run. Also added missing PreToolUse hook removal and session init script cleanup that were not present in the original disable command. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Adds Phase 2 Claude Code automation commands to
langfuse-cli:langfuse enablelangfuse disablelangfuse statuslangfuse tracesThis automates Claude hook setup, per-repo tracing config, and git-linked trace manifests while keeping existing
langfuse api ...andlangfuse get-skillbehavior intact.What Changed
src/cli.tsforenable,disable,status, andtraces.src/commands/enable.tssrc/commands/disable.tssrc/commands/status.tssrc/commands/traces.ts--force)~/.claude/hooks/langfuse_hook.py(Stop hook)~/.claude/hooks/langfuse_git_commit_hook.py(PostToolUse Bash hook).langfuse/current-session.jsontrace_context.trace_id.langfuse/traces/<session-id>.jsonREADME.mdfor new commands, setup model, and manifest schema.Behavioral Notes
enableis idempotent and avoids duplicate hook entries.--force; differing files emit a warning.disableremoves only exact Langfuse hook command entries and preserves unrelated settings.traces --jsonalways returns a JSON array (empty array when no manifests are present).Validation
bunis not available in this execution environment, sobun run buildcould not be executed here.Smoke checks were run via
deno eval --unstable-sloppy-importsagainstsrc/cli.ts:langfuse --helpshows new commands.langfuse enable --dry-run --non-interactive --public-key ... --secret-key ...shows planned changes and warnings.langfuse status --jsonreturns expected shape/fields.langfuse traces --jsonreturns[]when manifests are absent.langfuse disable --dry-run --remove-scriptsshows planned removals.Commits
feat: add Claude Code tracing automation commandsdocs: document Claude Code tracing automation workflow