He was born in a wealthy middle-class family in Ljubljana, Slovenia, then part of the Austro-Hungarian Empire. His younger brothers Ferdo and Vlado Kozak became political activists. He studied history and geography at the University of Vienna, but finished his studies only in 1921 at the University of Ljubljana. In 1914, Kozak was arrested by the Austrian police because of alleged collaboration with the radical pro-Yugoslav nationalist youth organization "Preporod", which had ties with the militant Bosnian organization Young Bosnia, often considered to be terrorist. Immediately after release from prison, he was drafted into the Austro-Hungarian Army and fought first on the Eastern Front and then in the Italian Front.