Clamping a vector in world space

I’m trying to find a solution to get the target location for the elbow for a VR IK system, I’m having problems with clamping the value to the elbow doesn’t end up in the torso.
I managed to get it to work in local space, where I would clamp the x axis to the limits of the capsule, this would place the elbow target location only outside of the capsule, but this solution fell apart whenever my character rotated.

So I started working with world location, which works well even if my character rotates, but I can’t figure out how to clamp the location (I want to clamp only 1 axis, the one that goes from left to right of the character) so it doesn’t end up inside the capsule

Here you can see what I’ve done so far, the “right hand IK” is in world space.
Pls help me figure this out, I can work with either local or world locations, as long as it doesn’t fall apart if the character rotates

I managed to get it to work, here’s the solution for those interested.
It works in local space

This is too small to read…