From 3d29ae060ed4247a41e4c63b14a39bf8a06dace1 Mon Sep 17 00:00:00 2001 From: Richie Caputo Date: Tue, 28 Apr 2026 10:36:08 -0400 Subject: [PATCH] fix(cli): send managed-agents beta for session-scoped file operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Session-scoped files (scope-id prefixed with "sesn_") require both the files-api and managed-agents beta headers. Without managed-agents, the API returns 404 for downloads and metadata lookups against session files. list — added when --scope-id starts with "sesn_" download / retrieve-metadata — added unconditionally, since these accept only a file ID and can't tell from flags whether the target is session- scoped. The header is harmless on non-session files. --- pkg/cmd/betafile.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/cmd/betafile.go b/pkg/cmd/betafile.go index b1aacb4..3fc5e8a 100644 --- a/pkg/cmd/betafile.go +++ b/pkg/cmd/betafile.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "os" + "strings" "github.com/anthropics/anthropic-cli/internal/apiquery" "github.com/anthropics/anthropic-cli/internal/requestflag" @@ -15,6 +16,21 @@ import ( "github.com/urfave/cli/v3" ) +const managedAgentsBeta = "managed-agents-2026-04-01" + +// addManagedAgentsBetaForFiles appends the managed-agents beta header when the +// request targets a session-scoped file (scope-id prefixed with "sesn_"). +// Session-scoped file operations require this header in addition to the +// files-api beta; without it the API returns 404. +func addManagedAgentsBetaForFiles(cmd *cli.Command, options []option.RequestOption) []option.RequestOption { + if cmd.IsSet("scope-id") { + if scopeID, ok := cmd.Value("scope-id").(string); ok && strings.HasPrefix(scopeID, "sesn_") { + return append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta)) + } + } + return options +} + var betaFilesList = cli.Command{ Name: "list", Usage: "List Files", @@ -162,6 +178,7 @@ func handleBetaFilesList(ctx context.Context, cmd *cli.Command) error { if err != nil { return err } + options = addManagedAgentsBetaForFiles(cmd, options) format := "explore" explicitFormat := cmd.Root().IsSet("format") @@ -275,6 +292,10 @@ func handleBetaFilesDownload(ctx context.Context, cmd *cli.Command) error { if err != nil { return err } + // Download takes only a file ID, so we can't tell from flags whether the + // target is session-scoped. Send the managed-agents beta unconditionally; + // it is harmless on non-session files and required on session files. + options = append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta)) response, err := client.Beta.Files.Download( ctx, @@ -315,6 +336,7 @@ func handleBetaFilesRetrieveMetadata(ctx context.Context, cmd *cli.Command) erro if err != nil { return err } + options = append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta)) var res []byte options = append(options, option.WithResponseBodyInto(&res))