So I think this bears repeating:
https://neuromatch.social/@jonny/116388666325458566
The way that Claude code differentiates human written messages from LLM written messages within the "user message" type (yes, user message does not necessarily mean messages from the user) is that some "origin" property is undefined .
Some of the types were stripped out in the sourceMap, so the MessageOrigin type is missing, but we do have the comment in the image.
So yeah, if something goes wrong in the labyrinth of Claude code that causes this to be undefined, treating messages as if they came from the user is the fallback.
Which is one of hundreds of possible explanations for why Claude code was able to autonomously scrap some expensive thing like in the posts upthread of the quoted post.