Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(claude): drop dedupe change and trim Bash output docs

Kyle Elliottf1335401e43d
diff --git a/cli/beacon-hooks/cmd/post_tool_claude_bash_test.go b/cli/beacon-hooks/cmd/post_tool_claude_bash_test.go
index 721fc8e5..772077e1 100644
--- a/cli/beacon-hooks/cmd/post_tool_claude_bash_test.go
+++ b/cli/beacon-hooks/cmd/post_tool_claude_bash_test.go
@@ -176,34 +176,23 @@ func TestClaudeBashInterruptedOutputIsMarked(t *testing.T) {
})
}
-// Claude Code's OTLP tool_result for the same call carries no output. Whichever report is written
-// first, the hook's output must reach the log.
+// Claude Code's OTLP tool_result for the same call carries no output. The collector writes it
+// without a working directory, so its dedupe key differs from the hook's and the hook's output
+// reaches the log even when the collector's report is written first.
func TestClaudeBashOutputSurvivesAnEarlierCollectorReport(t *testing.T) {
payload := postToolPayload("Bash", map[string]interface{}{"command": "npm test"},
map[string]interface{}{"stdout": "ok\n", "stderr": "", "interrupted": false})
- otlp := map[string]interface{}{
+ otlp := claudeCommandLine(t, map[string]interface{}{
"harness": map[string]interface{}{"name": "claude_code", "collection_method": "otlp"},
+ "session": map[string]interface{}{"id": "s-743"},
"command": map[string]interface{}{"command": "npm test", "duration_ms": 24},
+ })
+ _, events := runClaudePostTool(t, payload, otlp)
+ if len(events) != 2 {
+ t.Fatalf("events = %d, want the collector's report and the hook's", len(events))
}
- cases := []struct {
- name string
- session map[string]interface{}
- }{
- // The collector does not populate the working directory for Claude Code today.
- {"as the collector writes it", map[string]interface{}{"id": "s-743"}},
- {"with the hook's working directory", map[string]interface{}{"id": "s-743", "working_directory": "/repo"}},
- }
- for _, tc := range cases {
- t.Run(tc.name, func(t *testing.T) {
- otlp["session"] = tc.session
- _, events := runClaudePostTool(t, payload, claudeCommandLine(t, otlp))
- if len(events) != 2 {
- t.Fatalf("events = %d, want the collector's report and the hook's", len(events))
- }
- if got := nested(t, events[1], "command")["output"]; got != "ok\n" {
- t.Fatalf("hook command.output = %v, want the output kept", got)
- }
- })
+ if got := nested(t, events[1], "command")["output"]; got != "ok\n" {
+ t.Fatalf("hook command.output = %v, want the output kept", got)
}
}
diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdx
index 03b8322d..22c7a65e 100644
--- a/docs/runtimes/claude-code.mdx
+++ b/docs/runtimes/claude-code.mdx
@@ -76,7 +76,7 @@ Beacon detects Claude Code through the `claude` executable and Claude settings p
|------|---------|
| Prompt telemetry | Supported when emitted through Claude Code OTLP or hooks |
| Turn identity | Supported. Claude Code's `prompt.id` is kept as `prompt.id` on OTLP events; hook events after the prompt read the same id from the session transcript, and `beacon endpoint claude sync` reads it from `promptId`. The hook-recorded prompt itself takes its id from the OTLP `user_prompt` event, because the hook runs before Claude Code records the prompt |
-| Command, tool, and file telemetry | Supported through Claude Code OTLP with detailed tool inputs enabled; with hooks installed, Bash results also carry command output and, for a failed command, its exit code |
+| Command, tool, and file telemetry | Supported through Claude Code OTLP with detailed tool inputs enabled. Command output requires hooks |
| Token usage and cost | Supported through OTLP token and cost metrics, with per-model and per-session attribution |
| Hook lifecycle and tool telemetry | Optional through `beacon endpoint hooks install --harness claude` |
| Historical session sync | Supported through `beacon endpoint claude sync`; marked as poll collection |
@@ -113,26 +113,13 @@ attributes remain under `raw.attributes`, subject to the configured redaction
and event-size controls. Future full-body `claude_code.*` lifecycle records
default to `session.activity` until Beacon assigns a more specific mapping.
-Optional hook events complement OTLP. Pre-tool observations can appear as
-`tool.invoked`. A Bash `PostToolUse` records `tool_response.stdout` followed by
-`tool_response.stderr` in `command.output`; Claude reports the two streams
-separately, so the order in which the command interleaved them is not kept, and
-no exit code is reported for a success. A failed Bash command arrives as
-`PostToolUseFailure` with no tool response, only an `error` whose first line is
-`Exit code N`, followed by the output with both streams interleaved. Beacon
-records it as a high-severity `command.executed` with `command.exit_code` set to
-N and the remaining text in `command.output`. Claude may middle-truncate long
-output or add lines of its own, such as a timeout notice. An `error` without that
-line means the shell never started; it is recorded as `tool.failed` without
-output. An interrupted command's partial output is marked
-`raw.claude_interrupted: true`. Retained output is subject to Beacon's local
-redaction and size limits.
-
-The hook event carries Claude's tool call ID, so the later `claude sync` copy of
-the same call, which has the same output, is suppressed as a duplicate. The OTLP
-`command.executed` for the call has no output and no working directory, so it is
-kept as a separate event. If a report without output is ever written first, the
-hook event is still kept, so the output is not lost.
+Optional hooks add detail that OTLP does not report. A pre-tool hook can appear
+as `tool.invoked`, and the Bash post-tool hook records the command's output in
+`command.output`. For a successful command, Claude reports stdout and stderr
+separately, so Beacon stores stdout first and stderr after it. When a command
+exits with a non-zero status, Beacon also records the exit code in
+`command.exit_code` and sets the event's severity to `high`. Output is redacted
+and size-limited like other retained content.
Detailed tool inputs can contain sensitive command arguments, paths, URLs, search terms, and MCP request data. Beacon sends this telemetry only to the configured local collector during normal endpoint execution; apply the same access, retention, and redaction controls used for other retained prompt and tool data.
diff --git a/pkg/asymptoteobserve/dedupe.go b/pkg/asymptoteobserve/dedupe.go
index b18f6ceb..e42585a7 100644
--- a/pkg/asymptoteobserve/dedupe.go
+++ b/pkg/asymptoteobserve/dedupe.go
@@ -17,13 +17,11 @@ const (
)
type endpointDedupeEvent struct {
- action string
- harness string
- key string
- callID string
- hasOutput bool
- polled bool
- ts time.Time
+ action string
+ harness string
+ key string
+ callID string
+ ts time.Time
}
// IsDuplicateEndpointEvent reports whether candidateLine duplicates a recently
@@ -91,14 +89,8 @@ func duplicateEndpointEvents(existing, candidate endpointDedupeEvent, effectiveW
// runs and the collector writes when its batch flushes, so the two reports
// of one call routinely land five seconds apart -- past the two-second
// window that is the only thing that ever collapsed them.
- //
- // The one exception is a live report that retains command output the earlier one lacks. The
- // log is append-only, so the earlier line cannot be completed; suppressing the later one would
- // silently lose the output whenever a path that has none -- Claude Code's OTLP tool_result --
- // happened to be written first. A polled copy is backfill and stays suppressed: keeping it
- // would put every command an install without hooks ran into the log twice.
if existing.callID != "" && existing.callID == candidate.callID {
- return existing.hasOutput || !candidate.hasOutput || candidate.polled
+ return true
}
// Without matching IDs, only the timing heuristic is left, and only across
// capture paths: two adjacent calls from one path can legitimately touch the
@@ -178,12 +170,7 @@ func endpointDedupeCandidate(line []byte) (endpointDedupeEvent, bool) {
strings.ToLower(workspace),
target,
}, "\x00")
- return endpointDedupeEvent{
- action: strings.ToLower(action), harness: harness, key: key, callID: callID,
- hasOutput: nestedString(event, "command", "output") != "",
- polled: nestedString(event, "harness", "collection_method") == CollectionMethodPoll,
- ts: ts.UTC(),
- }, true
+ return endpointDedupeEvent{action: strings.ToLower(action), harness: harness, key: key, callID: callID, ts: ts.UTC()}, true
}
func endpointDedupeWindow(action string, fallback time.Duration) time.Duration {
diff --git a/pkg/asymptoteobserve/dedupe_test.go b/pkg/asymptoteobserve/dedupe_test.go
index 5bc284ad..ee77d4fd 100644
--- a/pkg/asymptoteobserve/dedupe_test.go
+++ b/pkg/asymptoteobserve/dedupe_test.go
@@ -136,41 +136,6 @@ func TestIsDuplicateEndpointEventCollapsesNormalizedHarnessOnCallID(t *testing.T
}
}
-// The log is append-only, so when two reports of one call land in the "wrong" order the line
-// written first cannot be completed. A live report carrying command output the earlier one lacks
-// is therefore kept; a report that adds nothing, or a polled backfill copy, is still suppressed.
-func TestIsDuplicateEndpointEventKeepsALaterReportThatAddsCommandOutput(t *testing.T) {
- line := func(ts, method, output string) string {
- command := `{"command":"echo hi"}`
- if output != "" {
- command = `{"command":"echo hi","output":"` + output + `"}`
- }
- return `{"timestamp":"` + ts + `","event":{"action":"command.executed"},"harness":{"name":"claude_code","collection_method":"` + method + `"},` +
- `"session":{"id":"s1","working_directory":"/repo"},"command":` + command + `,"tool":{"name":"Bash","command":"echo hi"},"gen_ai":{"tool":{"call":{"id":"toolu_1"}}}}`
- }
- cases := []struct {
- name string
- existing, candidate string
- duplicate bool
- }{
- {"live output after a report without it", line("2026-08-21T18:00:01Z", "otlp", ""), line("2026-08-21T18:00:02Z", "hook", "hi"), false},
- {"report without output after one with it", line("2026-08-21T18:00:01Z", "hook", "hi"), line("2026-08-21T18:00:07Z", "otlp", ""), true},
- {"both carry output", line("2026-08-21T18:00:01Z", "hook", "hi"), line("2026-08-21T18:00:09Z", "poll", "hi"), true},
- {"polled output after a report without it", line("2026-08-21T18:00:01Z", "otlp", ""), line("2026-08-21T18:00:09Z", "poll", "hi"), true},
- }
- for _, tc := range cases {
- t.Run(tc.name, func(t *testing.T) {
- path := filepath.Join(t.TempDir(), "runtime.jsonl")
- if err := os.WriteFile(path, []byte(tc.existing+"\n"), 0644); err != nil {
- t.Fatalf("write existing event: %v", err)
- }
- if got := IsDuplicateEndpointEvent(path, []byte(tc.candidate), EndpointDuplicateWindow); got != tc.duplicate {
- t.Fatalf("duplicate = %t, want %t", got, tc.duplicate)
- }
- })
- }
-}
-
// A Claude Code Write reaches the hook through diffFields, which records
// file.operation "modify", and reaches the collector as "create" -- two words
// for one action. While the target included the operation, the pair could not