We are beginning siman 6. The Gemara discusses a situation in which a person begins a bracha incorrectly and realizes their mistake. The Gemara discusses whether we follow the person’s original bracha or their corrected version.
The Rif understands the case of the Gemara as where the person finished their incorrect bracha, and then immediately corrected themselves. For example, they took a cup of beer and said baruch atah . . .borei pri hagefen shehakol ni’hiyeh bidvaro. The Rif clarifies that the Gemara is not discussing a situation in which either bracha could work (e.g., shehakol and then hagefen on wine), because such a case obviously works bedieved. Rather, the Gemara is discussing a case in which the incorrect bracha would not work even bedieved, such as hagefen on beer. The Rif explains that the safeik of the Gemara is that, on the one hand, the person corrected themselves toch k’dei dibbur. On the other hand, since the bracha was completed, maybe it is too late to correct it.
Rashi learns the safeik of the Gemara as occurring already at the beginning of the bracha, by the words baruch atah Hashem. Rashi understands that the Gemara’s safeik is whether already at this point in the bracha, if a person does not have the correct kavanah for the bracha they intend to make (e.g., their intent is to make a hagefen but in reality they need to make a shehakol), maybe they must start again. The Gemara’s safeik includes a situation in which they realize their mistake before reciting the wrong bracha (e.g., before getting to borei pri hagefen/ shehakol ni’hiyeh bidvaro). Even though someone listening to the bracha would not detect any issues, the Gemara considers that maybe if the kavanah is incorrect, the bracha must be repeated.
We can derive from Rashi that certainly lechatchilla a person must have kavanah for the purpose of their bracha before they begin reciting it. Thus, the Chayei Adam writes that a person should have kavanah for their bracha before they begin, so that when they get to Hashem’s name, which is the primary part of the bracha, they have the correct kavanah.
Lechatchilla, a person should have kavanah for the bracha they are about to recite before beginning to recite it.