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(ci): keep model context when a CI job turns Claude Code's bodies on
Kyle Elliottc847c8d61258
diff --git a/cli/beacon/internal/ci/harness.go b/cli/beacon/internal/ci/harness.goindex 96b628ae..476113ad 100644--- a/cli/beacon/internal/ci/harness.go+++ b/cli/beacon/internal/ci/harness.go@@ -227,6 +227,16 @@ func percentEncodeResourceValue(value string) string {return strings.ReplaceAll(url.QueryEscape(value), "+", "%20")}+// inlineRawBodies reports whether an OTEL_LOG_RAW_API_BODIES value has Claude Code put API bodies+// inline in its log events, rather than leave them off or write them to files Beacon never reads.+func inlineRawBodies(value string) bool {+ switch strings.ToLower(strings.TrimSpace(value)) {+ case "1", "true":+ return true+ }+ return false+}+func envMap(values []string) map[string]string {out := map[string]string{}for _, value := range values {diff --git a/cli/beacon/internal/ci/session.go b/cli/beacon/internal/ci/session.goindex 8685e99d..c42b1341 100644--- a/cli/beacon/internal/ci/session.go+++ b/cli/beacon/internal/ci/session.go@@ -135,6 +135,10 @@ func Provision(opts Options) (*Session, error) {cfg.Collector.HTTPPort = httpPortcfg.Collector.HealthPort = endpointconfig.DeriveHealthCheckPort(grpcPort, httpPort)cfg.Collector.IncludeCodexSpans = opts.IncludeCodexSpans+ // A CI job opts in to model-context capture by setting OTEL_LOG_RAW_API_BODIES itself, and the+ // collector is this job's alone, so it keeps what the job asked Claude Code to send. Without+ // this the collector would drop every body the job turned on.+ cfg.ClaudeCaptureModelContext = inlineRawBodies(os.Getenv("OTEL_LOG_RAW_API_BODIES"))forward, err := normalizeForward(opts.Forward)if err != nil {return nil, errdiff --git a/cli/beacon/internal/ci/session_test.go b/cli/beacon/internal/ci/session_test.goindex ff9cb2d7..f994d9c1 100644--- a/cli/beacon/internal/ci/session_test.go+++ b/cli/beacon/internal/ci/session_test.go@@ -3,6 +3,7 @@ package ciimport ("context""encoding/json"+ "fmt""os""path/filepath""runtime"@@ -206,6 +207,33 @@ func TestRunChildPassesTheCallersWebFetchOptIn(t *testing.T) {}}+// The collector a CI job runs is its own, so it keeps what the job asked Claude Code to send: inline+// bodies the job turned on reach the collector config as capture_model_context, and anything else+// leaves it dropping every body.+func TestProvisionCapturesModelContextWhenTheJobTurnsInlineBodiesOn(t *testing.T) {+ collector := fakeExecutable(t, "collector", "#!/bin/sh\nsleep 60\n")+ oldResolve := resolveCollectorBinary+ resolveCollectorBinary = func(string) (string, error) { return collector, nil }+ t.Cleanup(func() { resolveCollectorBinary = oldResolve })+ for value, want := range map[string]bool{"": false, "0": false, "file:/tmp/claude-bodies": false, "1": true, "true": true} {+ t.Run(fmt.Sprintf("OTEL_LOG_RAW_API_BODIES=%q", value), func(t *testing.T) {+ t.Setenv("RUNNER_TEMP", t.TempDir())+ t.Setenv("OTEL_LOG_RAW_API_BODIES", value)+ session, err := Provision(Options{CollectorPath: collector, Harness: "claude"})+ if err != nil {+ t.Fatalf("Provision returned error: %v", err)+ }+ data, err := os.ReadFile(session.ConfigPath)+ if err != nil {+ t.Fatal(err)+ }+ if got := strings.Contains(string(data), "capture_model_context: true"); got != want {+ t.Fatalf("collector config capture_model_context = %t, want %t:\n%s", got, want, data)+ }+ })+ }+}+func TestRunChildInjectsClaudeEnvAndBeaconPaths(t *testing.T) {testenv.RequirePOSIXExecutableFixtures(t)dir := t.TempDir()diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdxindex 257b3426..184613cd 100644--- a/docs/runtimes/claude-code.mdx+++ b/docs/runtimes/claude-code.mdx@@ -80,7 +80,7 @@ beacon endpoint install --claude-capture-model-contextThe choice is recorded as `claude_capture_model_context` in Beacon's `config.json` and kept until an install or repair changes it, so package upgrades, MDM repairs, and self-updates that re-run install without the flag leave it as it was. To turn capture off, pass `--claude-capture-model-context=false`. A package or MDM install can set `BEACON_CLAUDE_CAPTURE_MODEL_CONTEXT=1` or `0` instead of the flag.-With capture on, install sets `OTEL_LOG_RAW_API_BODIES=1` in `~/.claude/settings.json` if it is unset, and marks the settings it wrote in `BEACON_CLAUDE_MODEL_CONTEXT` in the same `env` block. With capture off, install removes only what that marker names. A value you set yourself, including `0`, `1`, and `file:<dir>` (bodies written to files), is never changed. `beacon ci exec` does not set the variable; a CI job opts in by setting `OTEL_LOG_RAW_API_BODIES=1` in its own environment.+With capture on, install sets `OTEL_LOG_RAW_API_BODIES=1` in `~/.claude/settings.json` if it is unset, and marks the settings it wrote in `BEACON_CLAUDE_MODEL_CONTEXT` in the same `env` block. With capture off, install removes only what that marker names. A value you set yourself, including `0`, `1`, and `file:<dir>` (bodies written to files), is never changed. `beacon ci exec` does not set the variable; a CI job opts in by setting `OTEL_LOG_RAW_API_BODIES=1` (or `true`) in its own environment, and the job's collector then keeps the same context an opted-in endpoint does.Whatever turned the bodies on, the collector filters them in its `claude_api_body` processor. The processor runs before every destination, including the local runtime log, Falcon, and Splunk HEC. With capture on, it keeps only the context listed below. With capture off, it drops every body, so turning `OTEL_LOG_RAW_API_BODIES` on yourself sends Beacon nothing it keeps. The `claude_code.api_request` event already records each model call.