Indeed, sounds like he's working something out. Perhaps working through the ins and outs of strong emotions (anger, frustration, etc.), or aggressive behaviors. Seems to me, he's found a way to work through whatever it is in a way where he no anyone else gets hurt. He knows what he needs to do and he's doing it, while you're there (no doubt for that extra support).
I recently read Playful Parenting which gives wonderful insights to this type of behavior. My DS (3.5) recently went through a very similar phase and by playing along and even helping him work deeper in, I found out that he was working out some rough feelings about another playmate who hits him on occasion. DS in turn, had begun hitting another playmates younger sibling in sort of "testing" mode. After we started doing the stuffed animal hitting play (he initiated, me playing along), he seemed to work through it and is no longer hitting his friends younger brother, and is more assertive with his other friend when he gets too aggressive. DS even named the game "hit back" where we would both have an animal or puppet and we would take turns hitting (fairly gently) back and talking things through ("Ouch! That hurt. I won't let you hurt me." to which DS would say, "I'm sorry, I didn't mean to hit you and I won't do it again). We'd repeat the game over and over, trading places and such. Wow, it seemed like such a long big deal at the time but it occurs to me now that he worked things through rather quickly.
The fact that he does this while you're there make me wonder if he doesn't want you to play along. I'm already getting way to rambly here, but by playing along you might gain some insight as to why he's doing it. Kid's work out pretty much everything through play. It's their MO so to speak. Keeps your ears and eyes open, you may come across something you can help him with.
Sorry for the ramble! This has become a subject that truly interests me and since reading the book, I feel like I'm understanding more and more all the "seemingly" nutty things DS does!