Claude Code Tracing with Langfuse
What is Claude Code?: Claude Code is Anthropic’s agentic coding tool that lives in your terminal. It can understand your codebase, help you write and edit code, execute commands, create and run tests, and help you accomplish complex coding tasks with natural language. Claude Code brings the power of Claude’s AI capabilities directly into your development workflow.
What is Langfuse?: Langfuse is an open-source LLM engineering platform. It helps teams trace LLM applications, debug issues, evaluate quality, and monitor costs in production.
Why Trace Claude Code?
- Add context to code changes. Every git commit includes a link to the Langfuse session that produced it, showing the full inner workings of Claude Code — prompts, tool calls, reasoning, and more.
- Track costs. Monitor how much your Claude Code interactions cost across projects and sessions.
- Monitor latency. Observe whether Claude Code response times degrade at certain times of day (e.g. when US usage peaks).
What Can This Integration Trace?
By using the Langfuse CLI, this integration installs Claude Code hooks that capture full conversation interactions and sends them to Langfuse. You can monitor:
- User inputs: Every prompt and message you send to Claude Code
- Assistant responses: Claude’s responses and reasoning
- Tool invocations: When Claude Code uses tools like file editing, bash commands, or web searches
- Tool inputs and outputs: Data passed to and returned from each tool
- Session information: Related interactions grouped into logical sessions
- Timing information: How long operations take
- Git integration: Each commit links back to the Langfuse session, and each Langfuse trace links to the git commit
Quick Start
Set up Langfuse
- Sign up for Langfuse Cloud or self-host Langfuse.
- Create a new project and copy your API keys from the project settings.
Install the Langfuse CLI
Install the Langfuse CLI globally:
npm i -g langfuse-cliOr run it directly via npx:
npx langfuse-cliConfigure Environment Variables
Create an .env file in your project root (or any convenient location) with your Langfuse API keys. You can get the values from your Langfuse project settings.
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_HOST=https://cloud.langfuse.com # optional, this is the default
# Use https://us.cloud.langfuse.com for the US regionEnable Claude Code Integration
Run the following command to enable tracing:
langfuse --env .env integration claudecode enableThis command installs two Claude Code hooks:
- Stop hook: Runs after each Claude Code response to send the conversation turn to Langfuse as a trace.
- Pre-commit hook: Attaches a link to the Langfuse session to every git commit message, so you can navigate from a commit directly to the session that produced it.
Use Claude Code
Start using Claude Code in your project as you normally would:
cd your-project
claudeAll conversation turns are automatically traced to Langfuse. Every git commit made by Claude Code will include a link to the corresponding Langfuse session.
See Traces in Langfuse
Open your Langfuse project to see the captured traces. You’ll see:
- Turn traces: Each conversation turn (user prompt → assistant response) as a trace
- Generation spans: Claude’s LLM responses with model info
- Tool spans: Nested spans for each tool call (Read, Write, Bash, etc.)
- Session grouping: All turns from the same session are grouped via
session_id - Git commit links: Traces link back to the git commit, and commits link to the Langfuse session

Disable Tracing
To remove the Claude Code hooks and stop tracing:
langfuse integration claudecode disableTroubleshooting
No traces appearing in Langfuse
- Verify the integration is enabled by checking your Claude Code hook configuration at
~/.claude/settings.json. - Verify environment variables — ensure your
.envfile has the correct API keys (public key starts withpk-lf-). - Check the Langfuse host matches your region:
- EU region:
https://cloud.langfuse.com - US region:
https://us.cloud.langfuse.com
- EU region:
Re-running the setup
If something went wrong, disable and re-enable the integration:
langfuse integration claudecode disable
langfuse --env .env integration claudecode enableResources
- Langfuse CLI GitHub Repository
- Langfuse CLI Documentation
- Claude Code Documentation
- Claude Code Hooks
- Langfuse Sessions