"Afterthought" is a word that's highly specific to English, in that it has a strong connotation of lesser importance or relevance, which isn't inherently connected to the idea of not thinking of something until later. Russian is probably far from the only language to not have an established term for that particular combination of ideas.
Russian has its own highly idiomatic verb which, connotation-wise, may be the opposite of "afterthought": спохватиться, "to suddenly [and almost belatedly] remember or realise". The implied importance here is greater, not lesser.
As for your example, I'd rephrase it as Потом добавил(а) гвоздику и корицу — чуть не забыл(а). (Since I think I can safely presume that я was used in the preceding sentence, the pronoun drop here makes it flow better.)