This interests me a lot, thanks for any answers!
The Imperial Japanese Navy maintained extremely tight operational security, both during the planning of the Pearl Harbor attack, and in the immediate run-up to the attack. Knowledge of the plan — and specifically, of the target location — was limited to a small circle of senior IJN officers; the location was never mentioned in signals traffic that might be intercepted by US intelligence, and as the task force moved into position they maintained absolute radio silence, communicating instead by flag and light signals.
Ken Kotani, one of the few intelligence historians writing about Japan (at least in English), concludes that "it was impossible for the US to anticipate the Japanese target; this was not American failure, but the success of Japanese security." Certainly, the fact that the Japanese carrier group managed to elude US naval intelligence's sight was both a striking success for the Japanese and a remarkable failure of American intelligence: in late November and early December 1941, the US had essentially no idea where a large portion of the IJN's carrier force was, assuming them to be in Japanese home waters even as they were steaming towards Hawaii.
But US military planners were absolutely aware that Pearl Harbor was a likely target in the event of war, given its status as the HQ of the US Pacific Fleet. In February 1941, for example, Secretary of the Navy Frank Knox sent the following dispatch to Admiral Husband Kimmel, commander-in-chief of the Pacific Fleet:
- The following is forwarded for your information. Under date of 27 January the American Ambassador at Tokyo telegraphed the State Department to the following effect:
"The Peruvian Minister has informed a member of my staff that he has heard from many sources, including a Japanese source, that in the event of trouble breaking out between the United States and Japan, the Japanese intend to make a surprise attack against Pearl Harbor with all of their strength and employing all of their equipment. The Peruvian Minister considered the rumors fantastic. Nevertheless he considered them of sufficient importance to convey this information to a member of my staff."
- The Division of Naval Intelligence places no credence in these rumors. Furthermore, based on known data regarding the present disposition and employment of Japanese Naval and Army forces, no move against Pearl Harbor appears imminent or planned for in the foreseeable future.
In hindsight, that looks fatally naive, but relations between Japan and the US were at very different stages in February and December 1941, and you can debate what exactly Knox meant by "the foreseeable future". But it does serve to illustrate the point that Pearl Harbor was widely seen as a likely target in the event of war. In 1945, a congressional investigation into Pearl Harbor concluded that:
Virtually everyone was surprised that Japan struck the Fleet at Pearl Harbor at the time that she did. Yet officers, both in Washington and Hawaii, were fully conscious of the danger from air attack; they realized this form of attack on Pearl Harbor by Japan was at least a possibility; and they were adequately informed of the imminence of war.
The joint committee also criticised the Intelligence and War Plans Divisions of the War and Navy Departments specifically for failing to pay close enough attention to a number of specific intercepts: a series of dispatches from Tokyo to Honolulu in September and November 1941, and a diplomatic cable early on the morning of 7 December (the 'one o'clock message'.)
The Tokyo-Honolulu messages were sent to Takeo Yoshikawa, Japan's vice-consul in Hawaii and a naval intelligence officer. On 24 September, Tokyo requested that Yoshikawa provide a map of US Navy berths at Pearl Harbor. Throughout November, Yoshikawa was ordered to provide more detailed information about the ships currently in port at Pearl Harbor. Again quoting from the congressional report on Pearl Harbor:
On November 15, 18, 20, and 29 the Japanese government urgently called for information about the location of ships in Pearl Harbor. On November 15 the Japanese Consul in Honolulu was directed to make his "ships in harbor report" irregular but at the rate of twice a week. The reports were to give vessel locations in specific areas of the harbor, using the symbols established in September. The greatest secrecy was enjoined, because rehitions between Japan and the United States were described as "most critical."
These dispatches were decrypted by US codebreakers in the first days of December; the congressional committee concluded that US naval commanders should have realised that the Japanese were showing a specific interest in the disposition of the US fleet at Pearl Harbor alone, and that the information being requested could be used for targeting in an aerial attack.
The "one o'clock" message, meanwhile, was a communique from the Japanese foreign ministry to the embassy in Washington, intercepted on the morning of 7 December and decrypted around four hours before the attack. The message read, in part:
Will the Ambassador please submit to the United States Government (if possible to the Secretary of State) our reply to the United States at 1:00 p.m. on the 7th, your time.
The 'reply' in question was Japan's final ultimatum (really, a declaration of war), to be delivered simultaneously with the attack on Pearl Harbor. The message went on to instruct embassy staff to immediately destroy their cipher machine and codebooks. That message was correctly interpreted as the prelude to something significant, and US military bases were put on alert — but due to radio interference, the message didn't reach Honolulu until some six hours after the attack.
There are many more potential missed signals beyond the major ones I've detailed here; again, hindsight is perfect, but there's a strong case to be made that given the broad range of incriminating information that the Office of Naval Intelligence, Army Signal Intelligence Service and FBI collected throughout 1941, the US should have been much more prepared for an attack, and should have foreseen that Pearl Harbor was a likely target.
Ultimately, the Pearl Harbor disaster boils down to a failure of intelligence analysis, rather than collection: the US was able to intercept and decrypt significant quantities of Japanese diplomatic communications (the PURPLE code; Japanese naval communications were significantly more secure, though not impenetrable.) The problem is that they repeatedly failed to put the whole picture together; effective intelligence analysis means understanding not just the content of the intelligence, but the wider political and strategic context into which it fits.
The intelligence failures at Pearl Harbor, and the belated recognition that a fundamental shift in inter-agency coordination and intelligence analysis was needed, played a significant role in the post-war overhaul of the US intelligence community, and the creation of the CIA and the National Security Council.
There's an enormous amount of scholarship around Pearl Harbor, but focusing on the intelligence front: I'd definitely recommend taking a look at the congressional investigation report for an incredibly detailed contemporary analysis of what went wrong. Also definitely worth checking out Ken Kotani's Japanese Intelligence in World War II, Ronald Lewin's The American Magic: Codes, Ciphers and the Defeat of Japan, and David Kahn's The Codebreakers.
A fairly relevant answer by /u/DBHT14:
and another for bonus credit
and as a extra bonus, even though you said to not worry about the FDR angle
Is the theory that Roosevelt purposely allowed Pearl Harbor to bring the USA into WW2 any credible?
There especially might be more able to be said about why the military codes specifically were hard to decrypt, and of course in general more answers are always welcome.