Skip to content

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

fix(exporter): capture PowerShell commands, not only Bash

shukieshah4ad1bb9fa2bd
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
index 9e92d461..a97550a8 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go
@@ -521,7 +521,19 @@ func NormalizeClaudeToolResult(event *Event, attrs map[string]interface{}) {
params := JSONMapAttr(attrs, "tool_parameters")
switch strings.ToLower(toolName) {
- case "bash":
+ // PowerShell alongside Bash, because they are the same signal under different names.
+ //
+ // Claude Code ships a native PowerShell tool that replaces Bash as the default shell on
+ // Windows, and it reports the command in the same tool_input.command field. With only "bash"
+ // here the event was still classified as command.executed -- but with an empty
+ // e.command.command, which is the leaf every rules/risky-command/ rule matches on. Command
+ // threat detection was therefore silently disabled on Windows while the telemetry carried the
+ // command all along.
+ //
+ // This is the same failure Bash had before v1.0.6, recurring under a new tool name, which is
+ // why the match is a set rather than one more literal: a shell tool is whatever the runtime
+ // calls the thing that runs commands.
+ case "bash", "powershell", "pwsh":
command := claudeCommand(input, params)
event.Event.Action = "command.executed"
event.Event.Category = "command"
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
index f0ac84c7..14599a8b 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter_test.go
@@ -1148,3 +1148,42 @@ func TestHarnessNameHonorsBrowserExtensionAttr(t *testing.T) {
t.Errorf("HarnessName = %q, want claude_web", got)
}
}
+
+// Claude Code ships a native PowerShell tool that replaces Bash as the default shell on Windows,
+// and it reports the command in the same tool_input.command field. Handling only "bash" left the
+// event classified as command.executed with an empty e.command.command -- the leaf every
+// rules/risky-command/ rule matches on -- so command threat detection was silently disabled on
+// Windows while the telemetry carried the command all along.
+//
+// The attributes below are copied from a real Windows session captured by the w00-probe scenario,
+// rather than invented, so this fails if the runtime's shape changes rather than only if the
+// mapping does.
+func TestClaudeShellToolsPopulateTheCommandDetectionSurface(t *testing.T) {
+ const want = `Write-Output 'BEACON_SANDBOX_2922d672fb2f' | Tee-Object -FilePath 'C:\beacon-sandbox\work\w00.sentinel'`
+
+ for _, toolName := range []string{"PowerShell", "pwsh", "Bash", "bash"} {
+ t.Run(toolName, func(t *testing.T) {
+ event := &Event{}
+ NormalizeClaudeToolResult(event, map[string]interface{}{
+ "tool_name": toolName,
+ "tool_input": `{"command":"` + strings.ReplaceAll(want, `\`, `\\`) + `","description":"write the sentinel"}`,
+ "duration_ms": int64(386),
+ })
+
+ if event.Event.Action != "command.executed" {
+ t.Fatalf("action = %q, want command.executed", event.Event.Action)
+ }
+ if event.Command == nil || event.Command.Command != want {
+ t.Fatalf("command.command = %#v, want %q -- this is the field every "+
+ "rules/risky-command/ rule matches on, so an empty value disables them all",
+ event.Command, want)
+ }
+ if event.Tool == nil || event.Tool.Command != want {
+ t.Errorf("tool.command = %#v, want the command mirrored", event.Tool)
+ }
+ if event.Command.DurationMS != 386 {
+ t.Errorf("duration_ms = %d, want 386", event.Command.DurationMS)
+ }
+ })
+ }
+}