Skip to content

Comments

feat: add Claude Code Git-linked Agent Tracing automation#3

Draft
jannikmaierhoefer wants to merge 14 commits intomainfrom
codex/git-linked-agent-tracing-claude-code
Draft

feat: add Claude Code Git-linked Agent Tracing automation#3
jannikmaierhoefer wants to merge 14 commits intomainfrom
codex/git-linked-agent-tracing-claude-code

Conversation

@jannikmaierhoefer
Copy link

Summary

Adds Phase 2 Claude Code automation commands to langfuse-cli:

  • langfuse enable
  • langfuse disable
  • langfuse status
  • langfuse traces

This automates Claude hook setup, per-repo tracing config, and git-linked trace manifests while keeping existing langfuse api ... and langfuse get-skill behavior intact.

What Changed

  • Added command routing in src/cli.ts for enable, disable, status, and traces.
  • Implemented new command modules:
    • src/commands/enable.ts
    • src/commands/disable.ts
    • src/commands/status.ts
    • src/commands/traces.ts
  • Added shared utilities for:
    • repo root detection and git metadata
    • safe JSON read/merge/atomic write
    • Claude hook add/remove/idempotency
    • script install/backup/replace behavior (--force)
    • manifest parsing/listing
  • Added hook script templates:
    • ~/.claude/hooks/langfuse_hook.py (Stop hook)
    • ~/.claude/hooks/langfuse_git_commit_hook.py (PostToolUse Bash hook)
  • Hook behavior now supports:
    • session handoff file: .langfuse/current-session.json
    • git-commit observation span linked via trace_context.trace_id
    • compact manifest writes to .langfuse/traces/<session-id>.json
  • Added docs in README.md for new commands, setup model, and manifest schema.

Behavioral Notes

  • enable is idempotent and avoids duplicate hook entries.
  • Existing hook scripts are not overwritten unless --force; differing files emit a warning.
  • disable removes only exact Langfuse hook command entries and preserves unrelated settings.
  • traces --json always returns a JSON array (empty array when no manifests are present).

Validation

bun is not available in this execution environment, so bun run build could not be executed here.

Smoke checks were run via deno eval --unstable-sloppy-imports against src/cli.ts:

  • langfuse --help shows new commands.
  • langfuse enable --dry-run --non-interactive --public-key ... --secret-key ... shows planned changes and warnings.
  • langfuse status --json returns expected shape/fields.
  • langfuse traces --json returns [] when manifests are absent.
  • langfuse disable --dry-run --remove-scripts shows planned removals.

Commits

  • feat: add Claude Code tracing automation commands
  • docs: document Claude Code tracing automation workflow

jannikmaierhoefer and others added 14 commits February 20, 2026 16:01
…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
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>
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>
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.

1 participant