I made an arrangement immediately when I started. I told them I do code on the side, and that I had other people that I worked with on that code.
They agreed that they pay me for legal work, not for code. Thus, the tools I build are mine, but the analysis and output of those tools may be theirs if I am using the tools for their benefit.