4. Given that point $A$ in the first quadrant lies on the graph of the inverse proportion function $y=\frac{1}{x}$, and point $B$ in the second quadrant lies on the graph of the inverse proportion function $y=\frac{k}{x}$. If $O A \perp O B, \tan A=$ $\frac{\sqrt{2}}{2}$, then $k=(\quad)$.
(A) $\frac{1}{4}$
(B) $-\frac{1}{4}$
(C) $\frac{1}{2}$
(D) $-\frac{1}{2}$
4. D.

Draw $A M \perp x$-axis through point $A$, and draw $B N \perp x$-axis through point $B$, with the feet of the perpendiculars being $M$ and $N$ respectively.
$$
\begin{array}{l}
\text { Since } O A \perp O B \Rightarrow \angle A O B=90^{\circ} . \\
\Rightarrow \angle M A O=\angle B O N \\
\Rightarrow \triangle A O M \backsim \triangle O B N \\
\Rightarrow \frac{S_{\triangle 1 O M}}{S_{\triangle B O N}}=\frac{O M \cdot A M}{O N \cdot B N}=\left(\frac{A O}{B O}\right)^{2} \\
\Rightarrow \frac{1}{|k|}=\left(\frac{1}{\tan A}\right)^{2}=2 \\
\Rightarrow|k|=\frac{1}{2} .
\end{array}
$$

Since $k<0$, thus $k=-\frac{1}{2}$.