The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(claude): retain WebFetch auxiliary model input
Kyle Elliott5be4bdf07960
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.goindex 37729b1c..9569b240 100644--- a/cli/beacon/internal/endpoint/harness/harness.go+++ b/cli/beacon/internal/endpoint/harness/harness.go@@ -385,6 +385,11 @@ func ConfigureClaude(opts ConfigureOptions) (string, error) {// identity/arguments needed to reconstruct agent activity from OTel events.env["OTEL_LOG_TOOL_DETAILS"] = "1"env["OTEL_LOG_USER_PROMPTS"] = "1"+ // Inline API bodies let the collector select auxiliary model inputs without+ // following body files. Preserve an explicit user opt-out or capture mode.+ if _, configured := env["OTEL_LOG_RAW_API_BODIES"]; !configured {+ env["OTEL_LOG_RAW_API_BODIES"] = "1"+ }settings["env"] = envif err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {return "", errdiff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.goindex 25e342ab..6834428d 100644--- a/cli/beacon/internal/endpoint/harness/harness_test.go+++ b/cli/beacon/internal/endpoint/harness/harness_test.go@@ -120,6 +120,44 @@ func TestConfigureClaudeEnablesPromptLogging(t *testing.T) {}}+func TestConfigureClaudePreservesExplicitRawBodyCapturePolicy(t *testing.T) {+ for _, policy := range []string{"0", "file:/private/claude-bodies"} {+ t.Run(policy, func(t *testing.T) {+ home := t.TempDir()+ testenv.SetHome(t, home)+ path := filepath.Join(home, ".claude", "settings.json")+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ t.Fatal(err)+ }+ before, err := json.Marshal(map[string]interface{}{+ "env": map[string]string{"OTEL_LOG_RAW_API_BODIES": policy},+ })+ if err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(path, before, 0600); err != nil {+ t.Fatal(err)+ }+ for range 2 {+ if _, err := ConfigureClaude(ConfigureOptions{Endpoint: "http://127.0.0.1:4317"}); err != nil {+ t.Fatal(err)+ }+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ var settings map[string]map[string]string+ if err := json.Unmarshal(data, &settings); err != nil {+ t.Fatal(err)+ }+ if got := settings["env"]["OTEL_LOG_RAW_API_BODIES"]; got != policy {+ t.Fatalf("install or reinstall changed explicit capture policy: got %q, want %q", got, policy)+ }+ })+ }+}+func TestClaudeStatusVariants(t *testing.T) {dir := t.TempDir()tests := []struct {diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary.gonew file mode 100644index 00000000..60b6fa35--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary.go@@ -0,0 +1,80 @@+package beaconevent++import (+ "encoding/json"+ "strings"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"+)++const claudeWebFetchApplyQuerySource = "web_fetch_apply"++// NormalizeClaudeWebFetchAuxiliaryRequest promotes only user-role text from Claude Code's+// WebFetch apply request body. Claude Code 2.1.291 sets query_source=web_fetch_apply when WebFetch+// sends fetched page text to its auxiliary summarizer; other API bodies can contain the full+// conversation, system prompt, tool schemas, and file results, so none of those are retained here.+func NormalizeClaudeWebFetchAuxiliaryRequest(event *Event, attrs map[string]interface{}) {+ if event == nil || !isClaudeOTelLogHarness(event.Harness.Name) {+ return+ }+ name := ClaudeLogEventName(attrs, "")+ if name != "claude_code.api_request_body" && name != "claude_code.api_response_body" {+ return+ }+ var body string+ if name == "claude_code.api_request_body" && FirstString(attrs, "query_source") == claudeWebFetchApplyQuerySource {+ body = FirstString(attrs, "body")+ }+ delete(attrs, "body")+ delete(attrs, "body_ref")+ if body == "" {+ return+ }+ text := claudeWebFetchUserText(body)+ if text == "" {+ return+ }+ event.Prompt = &PromptInfo{Text: text}+ event.Content = asymptoteobserve.RetainedContent(text, asymptoteobserve.DefaultStringLimit)+}++// claudeWebFetchUserText decodes only text parts of user messages. It deliberately ignores system+// prompts, tool definitions and non-text blocks, any of which can carry unrelated or prohibited+// content when another API request body reaches the same telemetry pipeline.+func claudeWebFetchUserText(body string) string {+ var request struct {+ Messages []struct {+ Role string `json:"role"`+ Content json.RawMessage `json:"content"`+ } `json:"messages"`+ }+ if json.NewDecoder(strings.NewReader(body)).Decode(&request) != nil {+ return ""+ }+ var parts []string+ for _, message := range request.Messages {+ if message.Role != "user" {+ continue+ }+ var plain string+ if json.Unmarshal(message.Content, &plain) == nil {+ if plain != "" {+ parts = append(parts, plain)+ }+ continue+ }+ var blocks []struct {+ Type string `json:"type"`+ Text string `json:"text"`+ }+ if json.Unmarshal(message.Content, &blocks) != nil {+ continue+ }+ for _, block := range blocks {+ if block.Type == "text" && block.Text != "" {+ parts = append(parts, block.Text)+ }+ }+ }+ return strings.Join(parts, "\n")+}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary_test.gonew file mode 100644index 00000000..5aa88c1b--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/claude_auxiliary_test.go@@ -0,0 +1,128 @@+package beaconevent++import (+ "encoding/json"+ "strings"+ "testing"+ "time"++ "go.opentelemetry.io/collector/pdata/pcommon"+ "go.opentelemetry.io/collector/pdata/plog"+)++func TestClaudeWebFetchAuxiliaryBodyRetainsOnlyUserText(t *testing.T) {+ body := `{"model":"claude-opus-5-5","system":[{"type":"text","text":"system-private"}],"messages":[{"role":"user","content":[{"type":"text","text":"Web page content:\n---\nPAGE-CANARY\n---\nReturn the page text verbatim."},{"type":"tool_result","content":"file-private"}]},{"role":"assistant","content":[{"type":"text","text":"assistant-private"}]}],"tools":[{"name":"tool-private","description":"tool-description-private"}]}`+ record := plog.NewLogRecord()+ record.Body().SetStr("claude_code.api_request_body")+ record.SetTimestamp(pcommonTimestamp(1700000000))+ attrs := record.Attributes()+ attrs.PutStr("service.name", "claude-code")+ attrs.PutStr("service.version", "2.1.291")+ attrs.PutStr("event.name", "api_request_body")+ attrs.PutStr("query_source", claudeWebFetchApplyQuerySource)+ attrs.PutStr("request_body_id", "webfetch-body-1")+ attrs.PutStr("model", "claude-opus-5-5")+ attrs.PutStr("body", body)+ attrs.PutStr("body_ref", "/private/request.json")++ event := NewConverter(Options{}).EventFromLog(nil, record)+ if event.Prompt == nil {+ t.Fatalf("auxiliary text was not promoted: %#v", event)+ }+ text := event.Prompt.Text+ if !strings.Contains(text, "PAGE-CANARY") || !strings.Contains(text, "Return the page text verbatim.") {+ t.Fatalf("typed auxiliary text = %q, want WebFetch page and its prompt", text)+ }+ for _, forbidden := range []string{"system-private", "assistant-private", "file-private", "tool-private", "tool-description-private"} {+ if strings.Contains(text, forbidden) {+ t.Fatalf("typed auxiliary text includes unrelated %q: %q", forbidden, text)+ }+ }+ if event.Event.Action != "session.activity" || event.Prompt == nil || event.Prompt.Text != text {+ t.Fatalf("auxiliary event = action %q prompt %#v, want session.activity with typed input text", event.Event.Action, event.Prompt)+ }+ if event.Content == nil || !event.Content.Included || event.Content.Hash == "" || event.Content.Bytes != len(text) {+ t.Fatalf("content marker = %+v, want retained typed auxiliary text", event.Content)+ }+ if event.Model != "claude-opus-5-5" {+ t.Fatalf("model provenance = %q, want Claude model", event.Model)+ }+ rawAttrs, ok := event.Raw["attributes"].(map[string]interface{})+ if !ok {+ t.Fatalf("raw attributes = %#v", event.Raw)+ }+ if _, exists := rawAttrs["body"]; exists {+ t.Fatal("raw API body was retained")+ }+ if _, exists := rawAttrs["body_ref"]; exists {+ t.Fatal("raw API body file reference was retained")+ }+ if got := rawAttrs["query_source"]; got != claudeWebFetchApplyQuerySource {+ t.Fatalf("query_source provenance = %#v, want %q", got, claudeWebFetchApplyQuerySource)+ }+ encoded, err := json.Marshal(event)+ if err != nil {+ t.Fatalf("marshal event: %v", err)+ }+ for _, forbidden := range []string{"system-private", "assistant-private", "file-private", "tool-private", "tool-description-private", "/private/request.json"} {+ if strings.Contains(string(encoded), forbidden) {+ t.Fatalf("serialized event leaked unrelated body data %q", forbidden)+ }+ }+}++func TestClaudeOtherAPIBodiesAreNotPromotedOrRetained(t *testing.T) {+ for _, name := range []string{"api_request_body", "api_response_body"} {+ t.Run(name, func(t *testing.T) {+ record := plog.NewLogRecord()+ record.Body().SetStr("claude_code." + name)+ attrs := record.Attributes()+ attrs.PutStr("service.name", "claude-code")+ attrs.PutStr("event.name", name)+ attrs.PutStr("query_source", "main")+ attrs.PutStr("body", `{"messages":[{"role":"user","content":"private-body"}]}`)+ attrs.PutStr("body_ref", "/private/body.json")+ event := NewConverter(Options{}).EventFromLog(nil, record)+ if event.Prompt != nil {+ t.Fatalf("unselected body promoted as auxiliary text: %#v", event.Prompt)+ }+ encoded, err := json.Marshal(event)+ if err != nil {+ t.Fatal(err)+ }+ if strings.Contains(string(encoded), "private-body") || strings.Contains(string(encoded), "/private/body.json") {+ t.Fatalf("unselected API body or reference was retained: %s", encoded)+ }+ })+ }+}++func TestClaudeWebFetchUnavailableBodyDoesNotRetainPartialContentOrReference(t *testing.T) {+ for _, body := range []string{"", `{"messages":[{"role":"user","content":"PARTIAL-PAGE`} {+ t.Run(body, func(t *testing.T) {+ record := plog.NewLogRecord()+ record.Body().SetStr("claude_code.api_request_body")+ attrs := record.Attributes()+ attrs.PutStr("service.name", "claude-code")+ attrs.PutStr("event.name", "api_request_body")+ attrs.PutStr("query_source", claudeWebFetchApplyQuerySource)+ attrs.PutStr("body", body)+ attrs.PutStr("body_ref", "/private/unread-request.json")+ event := NewConverter(Options{}).EventFromLog(nil, record)+ if event.Prompt != nil || event.Content != nil {+ t.Fatalf("unavailable body became retained input: prompt=%#v content=%#v", event.Prompt, event.Content)+ }+ encoded, err := json.Marshal(event)+ if err != nil {+ t.Fatal(err)+ }+ if strings.Contains(string(encoded), "PARTIAL-PAGE") || strings.Contains(string(encoded), "/private/unread-request.json") {+ t.Fatalf("unavailable body or reference leaked: %s", encoded)+ }+ })+ }+}++func pcommonTimestamp(seconds int64) pcommon.Timestamp {+ return pcommon.Timestamp(uint64(time.Unix(seconds, 0).UnixNano()))+}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex 8fe8dfd7..83cfa5fe 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -643,6 +643,7 @@ func (c Converter) NormalizeClaudeLogEvent(event *Event, attrs map[string]interfif preserveCategory {event.Event.Category = originalCategory}+ NormalizeClaudeWebFetchAuxiliaryRequest(event, attrs)}func ClaudeLogEventName(attrs map[string]interface{}, body string) string {diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdxindex bb1d2af2..d003f190 100644--- a/docs/runtimes/claude-code.mdx+++ b/docs/runtimes/claude-code.mdx@@ -66,7 +66,9 @@ Beacon detects Claude Code through the `claude` executable and Claude settings p## Install or configuration support-`beacon endpoint install` configures Claude telemetry settings so Claude Code sends OTLP data to the local collector. It enables detailed tool logging so tool-result events include inputs such as Bash commands, file paths, URLs, search patterns, and MCP server/tool arguments. Claude bounds or truncates some input values; tool output content is not enabled by this setting.+`beacon endpoint install` configures Claude telemetry settings so Claude Code sends OTLP data to the local collector. It enables detailed tool logging so tool-result events include inputs such as Bash commands, file paths, URLs, search patterns, and MCP server/tool arguments. Claude bounds or truncates some input values.++Installation enables inline API-body logs (`OTEL_LOG_RAW_API_BODIES=1`) unless that setting is already present; an explicit opt-out or capture mode is preserved. These bodies can contain conversation history, system prompts, tools, and tool results. For the WebFetch summarizer request (`query_source=web_fetch_apply`), the local Collector retains only user-role text as `prompt.text` on a `session.activity` event. It removes `body` and `body_ref` from all Claude API request/response-body events and never reads referenced body files. The stored input is the fetched page and summarizer prompt, not the summary returned to the main model. Invalid or truncated JSON bodies produce no auxiliary text. Managed-ingest privacy remains a separate forwarding policy, not a switch for local collection.`beacon endpoint hooks install --harness claude` adds Beacon-managed Claude Code hooks while preserving existing Claude settings and non-Beacon hooks. `beacon endpoint hooks uninstall --harness claude` removes only Beacon-managed Claude hook entries. Install, repair, and uninstall write every non-Beacon hook back exactly as they found it, including `http`, `prompt`, and `agent` hooks and any fields Beacon does not use itself, such as an http hook's `url` and `headers`.