|Cogito ergo sum|
Logic and rhetoric
Ad hoc is a phrase (literally, "for this") that describes ideas which are created solely for a specific task and not intended to be generalizable in any way.
Ad hoc is a fallacious debating tactic (also called a "just so story" or an "ad hoc rescue") in which an explanation of why a particular thing may be is substituted for an argument as to why it is; since it is therefore not an argument, it is not technically a fallacy, but is usually listed as one because it is a substitution for a valid argument. It is similar in form to moving the goalposts, but protects the argument by adding additional speculative terms rather than changing the meaning of existing ones.
Users of ad hoc claims generally believe the excuses and rationalizations serve to shore up the original hypothesis, but in fact each additional speculative term weakens it. This is both due to the speculations being based simply on the faith that there might be an explanation, and because each additional term makes the hypothesis weaker according to the principle of parsimony.
"Possibly," "probably," "maybe," "might", and "could" are all good markers of ad hoc claims.
Many creationists and woo pushers use ad hoc explanations to explain away evidence that contradicts their underlying beliefs, rather than revising those beliefs. For example, many alternative medicines have been disproven or shown to be mere placebos, but believers will make up excuses as to why the controlled and properly conducted experiment was wrong. Some homeopaths, for instance, will cry that the succussion process was carried out incorrectly (as if 9 bangs rather than 10 makes all the difference), or that (inexplicably) it is impossible to do a "double-blind" test on homeopathy. Creationist explanations for how the Grand Canyon is explained via the global flood while similar canyons aren't seen everywhere are varied and ad hoc.
Alice: "It is clearly said in the Bible that the Ark was 450 feet long, 75 feet wide and 45 feet high."
Bob: "A purely wooden vessel of that size could not be constructed; the largest real wooden vessels were Chinese treasure ships which required iron hoops to build their keels. Even the Wyoming, which was built in 1909 and had iron braces, had problems with her hull flexing and opening up and needed constant mechanical pumping to stop her hold flooding."
Alice: "It's possible that God intervened and allowed the Ark to float, and since we don't know what gopher wood is, it is possible that it is a much stronger form of wood than any that comes from a modern tree."
Here, Alice has merely offered hypothetical explanations for how the Ark could have existed, rather than offering explicit proof that it could have.
In politics, ad hoc refers to the creation of "temporary" committees or processes to handle new situations — similar to the valid uses of ad hoc arrangements described above, the situations are new, so can't really be dealt with in any other way. In some cases, notably due to laziness, these temporary creations end up becoming permanent. The constant "ad hoc tinkering" often creates solutions that work well in the short term, but end up creating a system that no one would have intentionally devised, given the time to work it out properly at the beginning. However, due to path dependency, it's basically impossible to go back and redesign the whole system from scratch. Instead, people make small ad hoc changes to the system again, and the process continues, with each new implementation causing a sort of partially-directed evolution of government.
Depression and anxiety
A particularly pernicious form of anxiety called "imposter syndrome" is effectively ad hoc as applied to the self: the sufferer's sense of self-criticism is such that they cannot internalise their own successes, instead inventing an endless stream of justifications for why these successes somehow do not count. Note that both imposter syndrome and the suffering that it can cause are real; it's the process of creating negative delusions about the self which is ad hoc.
In fiction writing, the term "plot spackle" is used to describe the same method, where additional terms/characters/scenes/etc. are made up to pave over the cracks in a plot.
Ad hoc explanations are not always an illegitimate exercise; if a new phenomenon is discovered, early explanations are likely to be technically ad hoc until experimentation or study can be conducted on it. In this sort of use and more general use, ad hoc arrangements are unavoidable because no one can predict the unpredictable (except maybe Derren Brown) — e.g., examiners putting ad hoc arrangements on exam marks because they didn't predict a spelling error, or role-players making up rules as they go along because the source book never said what to do if a Level 12 Sorceress cast that spell from that location while this rule was in effect under those rules in that building, which just produces a silly result. In science or when investigating pseudoscience, it is important to make sure that ad hoc claims are falsifiable and repeatable.