In July 1941, President Roosevelt signed an order naming William J Donovan Coordinator of Information. Donavan had been acting in an informal (amateurish) intelligence gathering role for FDR for some time.
Donovan (the only person to have received all four of the United States' highest awards: The Medal of Honor, the Distinguished Service Cross, the Distinguished Service Medal, and the National Security Medal) began to construct, with the help of the British, the infrastructure of an organisation that essentially combined the activities of MI6 & SOE - this included the infamous Camp-X, which was set up in Ontario (as the US was yet to join the war) with W E Fairbairn seconded from the British to teach his unsavory methods.
The Office of Strategic Services was established by a Presidential military order issued by President Roosevelt on June 13, 1942, to collect and analyze strategic information required by the Joint Chiefs of Staff and to conduct special operations not assigned to other agencies.
Prior to the formation of the OSS, the various departments of the executive branch, including the State, Treasury, Navy, and War Departments conducted American intelligence activities on an ad hoc basis, with no overall direction, coordination, or control. The US Army and US Navy had separate code-breaking departments: Signal Intelligence Service and OP-20-G. The FBI was responsible for domestic security and anti-espionage operations.
On the subject of code-breaking, the US had had an extremely effective code-breaking section, the Black Chamber, following on from the first world war. This had been completely decommissioned by 1929. The attack on Perl Harbour would come just 13 years after this was deemed unnecessary.
So the US had essentially created the same situation the British had found themselves in 100 years earlier in Afghanistan - needing to construct a clandestine network after it was needed rather than before.