diff --git a/pkg/cmd/betafile.go b/pkg/cmd/betafile.go index f5564fb..eb65c9c 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", @@ -163,6 +179,7 @@ func handleBetaFilesList(ctx context.Context, cmd *cli.Command) error { if err != nil { return err } + options = addManagedAgentsBetaForFiles(cmd, options) params := anthropic.BetaFileListParams{} @@ -276,6 +293,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)) params := anthropic.BetaFileDownloadParams{} @@ -316,6 +337,7 @@ func handleBetaFilesRetrieveMetadata(ctx context.Context, cmd *cli.Command) erro if err != nil { return err } + options = append(options, option.WithHeaderAdd("anthropic-beta", managedAgentsBeta)) params := anthropic.BetaFileGetMetadataParams{}