A glitch (グリッチ) or bug (バグ) is an unusual and unintended feature of any video game (or any computer system) that's not usually discovered until the game is released. They can range from the misuse of sprites to the game crashing. Most glitches in the games of the Touhou Project are caused by programming errors within the game's coding. An example of a well-known glitch in the Touhou Project was the "billion points bug", where the game Undefined Fantastic Object crashed when the player reaches a billion points on their score, but this was fixed in a later version of the game.
As ZUN programs his games, he ought to be following the rules similar to the systems development life cycle, where he'll analyse the requirements, design the overall game, do the implementations, test all coding and maintain the game to fix any issues. At some point in this cycle, ZUN would've missed out a bug that he didn't know that existed and never tested it. If he does, or if someone reported the bug, he'll then jump back to a particular stage to reprogram and fix that bug, and release a new version of the game in a patch. Trial versions of a game may contain more glitches and bugs than their full released version.
When glitches occur, either something unusual will happen (such as randomly dying for no apparent reason) or the screen will freeze/crash and sometimes some random sprites will or will not appear. Glitches can also include incorrectly displayed graphics, collision detection errors, sound errors and other issues. Some only activate when the player presses a certain sequence of button commands. Glitches can either be helpful (i.e. cheating), trivial & no issue to gameplay, annoying, or a serious issue to a game that causes the data to corrupt. Glitches needn't be performed by just the player, but may also have script errors that happen by default (i.e. the player doesn't do anything out of the ordinary, but the scripts still tells the program show something unusual). Replays seem to cause the most glitches throughout the Touhou games that may desynchronise with the original gameplay or it does not add up the score correctly.
Outside sources can also cause glitches or bugs. Some glitches may occur due to damage to the original cartridge or CD, even if there are no errors in the game's programming. Utilities that are listed in the Game Tools and Modifications article and the unofficial English patches can also make unnatural glitches appear in the game that didn't originally existed. Emulators that allows players to play the PC-98 games on modern computers may not be up to full standards and can act a bit buggy, such as playing a game on Anex86 that makes gameplay lag and not run smooth.
Glitches can also extend to the compatibility of what system or operating system a Touhou game can play on. For example, the games Embodiment of Scarlet Devil to Phantasmagoria of Flower View are able to play on Windows Vista/7, but in some cases, the title screen won't display properly and that it doesn't show the image of Reimu Hakurei, along with EoSD crashing when launched, but enabling Windows Aero will help. Another example is Shuusou Gyoku, which will simply not work properly when played on said Windows operating systems.
Glitches and bugs have been mentioned in the Touhou Project. ZUN mentions in the manual of Story of Eastern Wonderland Q&A section that the reason the game doesn't start is because there might be a bug. He also mentions in the interview on Nae Radio that the "billion points bug" in Undefined Fantastic Object was a copy-paste error, where something went wrong with the if statements.
In the story of Retrospective 53 minutes, Maribel Hearn mentions about a bug in a screen-controlling program. In Trojan Green Asteroid, it's said that the TORIFUNE space station lost its control due to a mysterious computer bug.
Various glitches that've existed in the Touhou Project are parodied in the fanbase, such as treating Merlin Prismriver rebellious or even crazy due to her glitch and that Gensokyo is going to corruption due to Undefined Fantastic Objects billion points glitch. These glitches are even sometimes considered to be part of the canon. Some even say that when someone hacks a Touhou game, this causes the original story to go glitchy.