Skip to main content

Trace Augment Code with Langfuse

Augment Code Tracing with Langfuse

What is Augment Code? Augment Code is an agentic AI platform specifically engineered for professional teams, featuring a specialized Context Engine that maintains a deep, semantic understanding of large-scale, multi-repository codebases. It utilizes autonomous agents to plan and execute end-to-end development tasks from complex refactors and high-precision code reviews to implementing full features directly from Jira or Linear tickets while ensuring architectural consistency and security compliance.

What is Langfuse? Langfuse is the open-source LLM engineering platform. It helps teams trace AI workflows, debug issues, evaluate quality, and monitor usage in production. Use Langfuse Cloud (hosted by Langfuse, free tier, no infrastructure to run) or self-host it.

What Can This Integration Trace?

By using Augment's hooks system, this integration captures both per-tool activity and the final conversation summary, then sends them to Langfuse. In this documentation you'll leverage 2 hooks to monitor:

  • User prompts and assistant responses from the final conversation payload
  • Per-tool executions through the PostToolUse hook
  • Tool metadata such as tool name, MCP details, timestamps, and error state
  • File-change context recorded after tool calls
  • Conversation-level traces emitted by the Stop hook
  • Generation and tool observations nested under the final conversation trace

UX Demo

1min demo of the tracing UX Auggie CLI => Langfuse

How It Works

Augment supports globally registered hooks in ~/.augment/settings.json. This integration uses both the PostToolUse and Stop hooks.

  1. Global hooks are configured to run after each tool call and after each completed Augment response.
  2. The shell wrapper scripts receive Augment's hook payload on stdin, write local audit entries, and forward the unchanged JSON payload to Python.
  3. The Python scripts load Langfuse configuration, convert Augment payloads into Langfuse traces and observations, and fail open if tracing is disabled or config is missing.
  4. Tracing is opt-in per workspace because the Python scripts first search the active workspace roots for .env.langfuse.local, then fall back to ~/.augment/hooks and ~/.augment.

Quick Start

Set up Langfuse

  1. Sign up for Langfuse Cloud or self-host Langfuse.
  2. Create a new project and copy your API keys from the project settings.

Install Dependencies

Make sure the machine running Augment has:

  • jq
  • /usr/bin/python3
  • the Python langfuse package

Install the Python SDK and create the hooks directory:

python3 -m pip install langfuse
mkdir -p ~/.augment/hooks

Create the Hook Files

Create these four files under ~/.augment/hooks/:

~/.augment/hooks/
├── langfuse_hook_posttooluse.sh
├── langfuse_hook_posttooluse.py
├── langfuse_hook_stop.sh
└── langfuse_hook_stop.py

Use the shell wrappers as the executable hook entry points, and use the Python files for the Langfuse tracing logic.

Make the shell wrappers executable:

chmod +x ~/.augment/hooks/langfuse_hook_stop.sh
chmod +x ~/.augment/hooks/langfuse_hook_posttooluse.sh

Register the Hook

Add both hooks to your global Augment settings at ~/.augment/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.augment/hooks/langfuse_hook_posttooluse.sh"
          }
        ],
        "metadata": {
          "includeConversationData": true,
          "includeUserContext": true
        }
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.augment/hooks/langfuse_hook_stop.sh"
          }
        ],
        "metadata": {
          "includeConversationData": true,
          "includeUserContext": true
        }
      }
    ]
  }
}

This registers the hooks globally so they run for all Augment sessions.

Enable Tracing Per-Project

For each workspace where you want tracing enabled, create a .env.langfuse.local file in the workspace root:

TRACE_TO_LANGFUSE=true
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_BASE_URL=https://cloud.langfuse.com
AUGGIE_LANGFUSE_DEBUG=false
AUGGIE_LANGFUSE_MAX_CHARS=20000

Note

Tracing is opt-in per workspace. The hooks are installed globally, but the Python scripts immediately exit unless TRACE_TO_LANGFUSE is set to "true" in a discovered .env.langfuse.local file.

The Python hooks look for .env.langfuse.local in this order:

  1. the current workspace roots
  2. ~/.augment/hooks
  3. ~/.augment

Environment Variables:

VariableDescriptionRequired
TRACE_TO_LANGFUSESet to "true" to enable tracingYes
LANGFUSE_PUBLIC_KEYYour Langfuse public keyYes
LANGFUSE_SECRET_KEYYour Langfuse secret keyYes
LANGFUSE_BASE_URLLangfuse base URL (https://cloud.langfuse.com for EU, https://us.cloud.langfuse.com for US)No (defaults to EU)
AUGGIE_LANGFUSE_DEBUGSet to "true" for verbose debug loggingNo
AUGGIE_LANGFUSE_MAX_CHARSMax characters kept per field (default 20000)No

Start Using Augment Code

Now open a workspace with tracing enabled and use Augment normally. Once the hooks are registered, PostToolUse and Stop events are sent automatically whenever tracing is enabled.

View Traces in Langfuse

Open your Langfuse project to see the captured traces. You'll see:

  • PostToolUse – <tool> traces for individual tool executions, including file changes, error state, user/model/timestamp details, and MCP metadata.
  • Auggie Conversation traces from the Stop hook, containing the final conversation-level generation plus extracted tool observations from the full payload.

Troubleshooting

No traces appearing in Langfuse

  1. Confirm .env.langfuse.local is present in the workspace root, ~/.augment/hooks, or ~/.augment.
  2. Verify TRACE_TO_LANGFUSE=true and confirm the Langfuse keys are populated.
  3. Check the local hook logs:
tail -f /tmp/auggie-hook-stop.log
tail -f /tmp/auggie-hook-posttooluse.log
tail -f ~/.augment/hooks/langfuse_hook_stop.log
tail -f ~/.augment/hooks/langfuse_hook_posttooluse.log
  1. Verify the Python dependency is importable:
/usr/bin/python3 -c "import langfuse; print('langfuse ok')"

Hooks are registered but still not sending traces

  • Make sure both hook commands in ~/.augment/settings.json point to executable shell scripts.
  • Confirm the shell wrappers forward the original payload to the Python scripts instead of consuming it.
  • Check ~/.augment/audit-api.jsonl to confirm the shell wrappers are receiving events even if Langfuse emission fails.
  • Remember that this setup is designed to fail open: Augment continues even if tracing fails, so the logs are the best source of truth.

Authentication or region issues

Verify the keys and base URL in .env.langfuse.local:

  • EU Cloud: https://cloud.langfuse.com
  • US Cloud: https://us.cloud.langfuse.com
  • Self-hosted: your own Langfuse base URL

Resources