Купи какой‐нибудь хлеб. Купи какого-нибудь хлеба.
You can use either accusative or genitive in this sentence The meaning is slightly different. The accusative signifies the item itself or the whole item.
The genitive means "some," "a little". Some nouns have the special form of genitive which is called the partitive. Хлеб doesn't have it. You can see the partitive in action when you hear "сахару" for example. There are three possible variants:
Хочешь сахар? - accusative. It refers to a substance as a class. Соли нет, хочешь сахар?
Хочешь сахара? - genitive. One of the multiple functions of genitive is to refer to some amount of a substance: "стакан воды", "ложка сахара".
Хочешь сахару? - partitive. It's the special form of genitive to refer to some amount of a substance: "ложка сахару".
Какой‐нибудь is a pronoun in Russian (terminology is different in Russian and in English ) and is used as a determiner to a noun хлеб, so it should be declined какого-нибудь хлеба (used attributively) Купи хлеба would mean "some bread", when you add a pronoun, you mean "a sort", "a kind". It is not used as a noun or its substitution.We use что‐нибудь in that case. In a conversation the noun хлеб can be left out
Какой хлеб/какого хлеба купить? – Да купи какой‐нибудь, не важно.