Often I meet, in real and virtual world, taijiquan practitioners or ex-practitioners complaining about knee pain.
During taijiquan practice, maintaining the correct posture of the body both in static positions and during movement stresses our lower limbs. In my mind , the right posture of the lower limbs is more important than the stance of the upper ones, as the body weight amplifies any issue on lower joints.
A simple way to check knee correct position is the alignment between the foot and the knee:
“Looking at toes, knee and the foot lay on the same line“
The image below shows Master Chen Peishan in ma-bu position; the green line represents the eye-knee-foot alignment.

First requirement: posture. The body is upright and centered, the weight is correctly distributed as the pose requires (in this case, the ma-bu position). After that, using my peripheral vision so as not to affect my posture, I check knee alignment.
Looking towards my right toe, I see what is shown in the following image (the following images are point-of-view shots)

The eye-knee-foot line crossing points are indicated using the green color. The knee is on the eye-foot diagonal without bending sideways: inside on the left of the image or outside on the right.
The same principles apply to all taijiquan poses. The following images refer to the left-side gong bu pose (the left leg is out).
Looking towards my left toe, I see what is shown in the following image

In this pose, the sideways deviation, from the right position, is even more evident.
The next image shows what I see looking at the right toe (the right leg is the back one in this pose)

Like body posture, we have to govern knee position in both static poses and while moving from one stance to another, avoiding ‘strange’ knee movements while we shift our weight / body