Aditya Singh is charged with felony criminal trespass to a restricted area of an airport and misdemeanour theft.
Mr Singh, who survived on food from other passengers, is unemployed and lives in the city of Orange, California. It was unclear why he was in Chicago.
Cook County Judge Susana Ortiz reacted with surprise when a prosecutor set out the allegations, according to the Chicago Tribune.
She reportedly told the court: “So if I understand you correctly, you’re telling me that an unauthorised non-employee individual was allegedly living within a secure part of the O’Hare airport terminal from 19 October 2020 to 16 January 2021 and was not detected? I want to understand you correctly.”
On Saturday, two employees from United Airlines were said to have approached Mr Singh and asked for his identification.
The badge apparently belonged to an operations manager who had reported it missing on 26 October.
Assistant public defender Courtney Smallwood said Mr Singh does not have a criminal background and has a master’s degree in hospitality – and said the unusual allegations were not violent, reported the Tribune.
If he is able to post the $1,000 (£738) for bail, Mr Singh will be barred from entering the airport.
Judge Ortiz added: “The court finds these facts and circumstances quite shocking for the alleged period of time that this occurred.”
The Chicago Department of Aviation said that while the incident remains under investigation, it had been able to “determine that this gentleman did not pose a security risk to the airport or to the travelling public”.