Intermittent knock when cold

I have an old Toyota diesel, and sometimes it will knock intermittently when starting cold. By “knock” I don’t really mean a frightening rod-knock type of knock, but a definite occasional clack.



The bizarre thing is not all cold starts will display this phenomenon. Moreover, while it will clack faster with engine speed, it doesn’t make the sound on every revolution, its seemingly random… - - clack clack - - - clack - - - clack - - - clack clack, etc. I can’t hear it above idle - it doesn’t get any louder.



Pulling out of the garage and the noise is gone by the time I reach my first stop sign, about 1/3 mile.



Any ideas? Engine is old, ~170k miles, but has good compression, oil pressure, etc.

Sounds like piston slap to me. As the pistons get hot, they expand and the excessive clearance sort of goes away. A lot of cylinder wear or a broken piston can cause this.
I had a six cylinder Nova do this and when I disassembled the engine, I found a couple of pistons with cracked skirts.

On a diesel, it can also be a problem with the fuel injectors. The fuel is supposed to come out of the injectors burning as it sprays into the cylinder but delayed ignition causes a bunch of fuel to go off all at once causing a detonation like sound.