I've been wondering how AI companies are legally allowed to train models on publicly available code and other copyrighted material. If public code repositories and similar platforms had never been available, many current models probably would not exist. I don't remember agreeing to let my code be used for commercial AI training when I started publishing it years ago.
These models can also generate substantial portions of copyrighted code, and even code under permissive licenses such as MIT may have attribution requirements. Is the legal basis fair use, the hosting platform's terms of service, the individual software license, or something else?
5 Answers
There can also be a terms-of-service angle. Hosting services often receive broad licenses to store, display, index, analyze, and improve their products using uploaded content. That may allow the platform to operate features built around public repositories, but it does not necessarily mean every AI company has permission to use every file, nor does it override the license attached to the code.
So the practical answer is that the legal situation was uncertain, and companies moved ahead while relying on favorable interpretations of existing law. Laws written before modern generative models do not clearly say whether training is copying, research, transformation, or something else. Lawsuits may establish boundaries, but they are unlikely to make the already completed training data disappear overnight.
Open-source licenses still matter when the model produces recognizable code. A license such as MIT usually permits reuse as long as the required notice and attribution are preserved. Companies argue that training itself is not distribution of the original code, but a generated answer that closely reproduces a file or meaningful section could raise attribution, license-compliance, or infringement concerns.
They generally did not obtain explicit permission from every creator. Their main argument is that training qualifies as fair use or a similar legal exception. The model is supposed to learn statistical patterns rather than redistribute the original files, although outputs that reproduce substantial portions of protected work can create a separate copyright issue. Courts are still deciding how these arguments apply to large-scale commercial training.
Publicly visible does not automatically mean copyright-free, but companies argue that accessing and analyzing material available on the open internet is different from publishing copies of it. The analogy they use is that a person can read books or study public code, then create something new based on what they learned. Whether a machine doing this at enormous scale should receive the same treatment is the unresolved part.

That makes sense. So the key distinction is between using material to train a model and having the model reproduce protected material, with the first issue still being argued under fair use.