Hey Tomas,
The first one is correct. ............, which............. When you use "which" like this with a comma, it is almost like an afterthought. It gives extra information. Normally, relative pronouns modify nouns, however; you modify the whole sentence here. It's a non-defining relative clause.
I didn't understand the sentence which she wrote. (We modify the sentence here)
He passed all his exams, which we didn't expect at all. ( Here, the whole sentence is modified. )
Hope this helps! Feel free to check my profile :)