  We analyse what happens when the Horndeski Lagrangian is varied within the
Palatini approach by considering the metric and connection as independent
variables. Assuming the connection to be torsionless, there can be infinitely
many metric-affine versions $L_{\rm P}$ of the original Lagrangian which differ
from each other by terms proportional to the non-metricity tensor. After
integrating out the connection, each $L_{\rm P}$ defines a metric theory, which
can either belong to the original Horndeski family, or it can be of a more
general DHOST type, or it shows the Ostrogradsky ghost. We analyse in detail
the subclass of the theory for which the equations are linear in the connection
and find that its metric-affine version is ghost-free. We present a detailed
classifications of homogeneous and isotropic cosmologies in these theories.
Taking into consideration other pieces of the Horndeski Lagrangian which are
non-linear in the connection leads to more complex metric-affine theories which
generically show the ghost. In some special cases the ghost can be removed by
carefully adjusting the non-metricity contribution, but it is unclear if this
is always possible. Therefore, the metric-affine generalisations of the
Horndeski theory can be ghost-free, but not all of them are ghost-free, neither
are they the only metric-affine theories for a gravity-coupled scalar field
which can be ghost-free.
