Millimeter wave systems require narrow beam communication to achieve high throughput. To this end, beam alignment is achieved via a proper beam sensing protocol, which specifies how to allocate amplitude and phase at each antenna array element (a codeword) to sense the mobile user's position, through appropriate beam pointing. However, beam imperfections - such as the presence of sidelobes - and noise may cause errors in the detection process. Thus, correct alignment between transmitter and receiver may not be achieved. Therefore, it is of great importance to design the sensing codebook to attain optimal detection performance. In this paper, a Neyman-Pearson codebook design is proposed. The sensing codeword is optimized so as to minimize the mis-detection probability, under false-alarm, power and hybrid beamforming constraints. Due to the intractability of the problem, aworst-case relaxation is carried out. It is shown that the dual problem can be recast as a semidefinite program, and the optimal codebook is the principle eigenvector of a weighted array response matrix. It is shown numerically that the proposed design outperforms a state-of-the art algorithm, with improvement of up to 33% in detection performance.