I asked before and was told that code written by the government is available by request due to the FOIA, no state secrets mind you, but it might be true of (a significant portion of) code written by contractors as well.
Does that really matter? The NSA faced scrutiny for writing its own software when commercial solutions were on the market. The US government contracts out almost all its software needs below the state secrets level anyway.