I have had the same symptons on and off for 3 years, which has certainly limited my long runs and races.

Mine is put down to patella tracking disorder, knee cap not running correctly in the groove and hitting bone hence causing pain.

I need to keep my inner quad strong and outside leg stretched as someone described above.

A very good phyio recomended I sort my whole core stability out as it could be coming off my ankles and possibly due to weak glutes.

I manage to keep this at bay by doing 4 basic exercises and lots of stretching. If I get lazy on the exercises this thing comes back to remind me to get back on the exercises. I also do two core stability classes a week.

My 4 basic lunchtime at work exercises are

Quarter Squats - I have a wooden triangular wedge, I put my heel on that and do one legged squats. Ensuring I dont go down all the way to a full squat and irritiate the knee cap. These will target the inner quad.

The plank - google it - squeeze the bum cheeks as your doing it. Imagine someone has wedged a £50 note in your arse crack and they are trying to take it back out. Squeeze hard whilst in the plank position. Hold it as long as you can, When I do this my knee always clicks.

One legged balancing whilst catching a ball, builds my ankles which were identified as a possible cause of throwing the knee out.

Glutes bridges - google them.

Do lots of stretching as well

These have really helped me and got me back running, I had/still have the exact same things going on as you.

Downhill shooting pains and constant aching and clicking, its not good

Cheers
Jamie