I've been looking for various licenses that I can use for an open-source project of mine, but all of the projects that I've seen, with all kinds of licenses, appear to have a giant, obnoxious (in my opinion) notice in each source file that states that the file is listed under a certain license. I don't think that I've found a single source project that isn't public domain that doesn't have a notice like that.

This just seems like a waste of time and file space. I plan on putting @license and @author tags in my projects, but I don't see why I need to list such a giant notice in each individual file if I don't want to make my code public domain.

Is there any reason why I would want to include such a notice in my projects, or would simply including a notice in the README and a @license tag be good enough? Does this affect the "clearly stated" rule of most licenses, or is it just overkill so that people won't argue?

  • 1
    Realistically, if someone steels your code, renames a variable and remove the copyright would a court of law consider these 2 files identical?
    – NoChance
    Dec 18, 2011 at 17:01
  • 5
    @Emmad: No, a court would not say they are identical. (But they might be "essentially identical".) Yes, a court would say it's copyright infringement. Dec 18, 2011 at 18:49
  • 1
    Relevant: softwareengineering.stackexchange.com/a/19653/94635
    – 0 _
    Jan 19, 2017 at 20:54
  • Also: opensource.stackexchange.com/a/322/7022
    – 0 _
    Jan 19, 2017 at 20:57
  • "Do you have to include a license notice with every source file?" --- No, you do not. It is recommended that you do so in order to avoid the risk of the code getting disconnected from the license. I think adding a @author and @license in each file is sufficient, and of course adding the LICENSE file to the root of the project. Complete it by saying in the README of the program that all files in the repository fall under this license.
    – Daniel
    Jan 30, 2017 at 11:22

7 Answers 7


I've seen many projects which only mention the license in the README or in a LICENSE or COPYING file.

Your software is automatically covered under copyright, as agreed in international law. (Unless you are working for the US government or some other organization for which copyright does not apply.)

If someone uses your software then they must make sure to follow the license agreement, or follow the fair use restrictions on what they can do.

Suppose that person wants to use one of the files in your code distribution, which of course requires a copy and hence copyright law applies. By default they do NOT have the right to use your software under copyright law. It's only when they know and follow the license restrictions that they are allowed to use it.

So if they use a file without a software license then they are breaking copyright law. Since all the licenses say something like "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software", they are obliged to put that license somewhere.

That can be in the file itself, or when I've used code as library I put the relevant portions into its own directory and added a "README" or "LICENSE" into that subdirectory.

In short, you don't need to put the license in each file. I think it's overkill. There's no extra legal protection in doing so. It does help a downstream user somewhat, but not by much.

I think the tradition of lots of comment-based metadata (license, creation date of each function, changelog, etc.) are very old traditions which exist because they are easy to do and which more a talisman than useful.

For example, the default Eclipse template adds what I think of as useless metadata before each function, which I think is much better captured by version control. But that practice is common in many shops.

  • 2
    For example, I don't see anything related to licensing in Rails source files at all. Dec 18, 2011 at 18:49
  • 5
    And of the 200 files in the top-level Python standard library, only 34 contain the word "copyright", and only 4 of those are for the Python Software Foundation, which controls the copyright to Python. Dec 18, 2011 at 18:58
  • yeah, i don't think per-file copyright notices are going to last... it's just way too much.. it just can't be the way of the future.. think DRY... root level LICENSE, and let's call it a day.. i think mostly everything on npm is already doing it this way May 12, 2019 at 8:23
  • My project is using many open source libraries. Being distinct from the project's own license, where do each licenses of the libaries go into project source code directory / binary(or web service's separate page)?
    – rosshjb
    Apr 20, 2021 at 0:01

In my understanding, the GPLv3 strongly suggests (or even perhaps requires, at least that how I understand the text How to Apply These Terms to Your New Programs, after its section 17) a copyright notice in every source file. It says

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year>  <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

And GNU projects which are FSF owned, like GCC, have such a notice in every file.

I also know of a program (J.Pitrat's CAIA system) which has been refused on a free software community web site because it had no such notice in every file.

I am not a lawyer, but I believe that such notice is practically mandatory in every source file of a GPLv3 program.

The question becomes more interesting for software projects which are generating some (or most) of their source files, e.g. RefPerSys.

(if you use other license, notably a non-FSF one, read carefully about how to apply it; YMMV; however AFAIK writing a notice in every file won't harm.)

  • 23
    It can't be mandatory because there are systems, like Smalltalk images, which don't express source code as files. They say "safest" and "should", not "must." What they recommend is an easily understood guideline with little chance of someone making an error, but it is definitely not "practically mandatory." Dec 18, 2011 at 18:33
  • I agree, and I said "source file" on purpose. Actually, CAIA's system is a bit like Smalltalk: the image is in data files, and the CAIA "source files" I mentionned are generated C files. However, my GCC MELT (a branch of GCC, under FSF copyright) is also meta-programmed, and I do take care to generate copyright notice comments in generated C files (and I put them in hand-written C & MELT code). Dec 18, 2011 at 18:36
  • Point taken. I know now one paragraph about MELT. In general it's best that generated files include the copyright notice as it's very hard to "attach" the license otherwise. Eg, "yacc" and "lex" are restricted in what they can do. Dec 18, 2011 at 18:57
  • 1
    From personal experience: to have a project accepted on Savannah you have to have a license in every file.
    – Mael
    Sep 4, 2017 at 13:00
  • 1
    Just to clarify, according to the GPL FAQ, #LicenseCopyOnly and #NoticeInSourceFile at the time of this writing, it's not required to include the How to Apply... text to every source file; notice the language uses "should" and not "must". However, they do strongly recommend that you follow this practice.
    – ZeroKnight
    Jul 13, 2019 at 8:29

There is another practical way not yet mentioned here.

SPDX-License-Identifier tag. https://spdx.org/ids

Using it, your "legal boilerplate" in every source file header reduces to just two lines:

/* SPDX-License-Identifier: (GPL-3.0-or-later AND LGPL-2.0-only) WITH bison-exception */
/* Copyright © 1234 Project Author */

People who automate software supply-chain analyses will be thankful for your sticking to a common standard of machine-readable license description.


The problem is that it's very easy to dis-aggregate a single source code file from its larger project, such as someone just checking out, emailing, downloading one file, without the rest that contains the full copyright. And then that file can get passed along ad-infinitum into time, to Nth parties who may have no idea of the files origins.

The copyright notice at the top reminds anyone who runs across that lone file that it is in fact copyrighted, not public domain, and thus some license may or may not be involved in its distribution or use. Versus letting the finder make their own random assumptions.

  • 26
    Isn't it just as easy to dis-aggregate through copy-paste various fragments of a source file as well? What then? This argument seems inconsistent to me. Feb 19, 2015 at 23:59
  • 10
    Assuming public domain for a work without a copyright notice is the problem. If you come across a file without a copyright notice, then you should not be copying it and sending it off to others.
    – Rich Remer
    Mar 22, 2017 at 22:51
  • of course then there's the problem that it's legal to "clone and own" a file, we've put open source into our project repo directly because sometimes it's hard to fix a bug outside of the upstream project, but you can't wait for them to release either. Not saying this is a good idea, but we've done it. Jun 12, 2017 at 13:53
  • 1
    If I get a source file without any copyright and/or license note the only safe assumption is that it is copyrighted by someone I don’t know and who can sue me if I violate copyright law, and that I don’t have any license that allows me to do anything that copyright law doesn’t allow me to do.
    – gnasher729
    Dec 31, 2020 at 14:24
  • You assume most people make the "safe assumption". My guess is that is false. And very few people actually read all the fine print (on this very site) regarding posted code.
    – hotpaw2
    Dec 31, 2020 at 16:40

There is no secret superpower meeting in an underground bunker that says what you must put it in each source file.

It does make it clear to the user that this file is under whatever license and in fact most GPL software contains a short preamble saying to read license.txt. Remember projects get split up and files get reused so only putting the message in a single file might not be a good idea.

If in the unlikely event it ever went to court you might have more claim if you had clearly marked each file as your work and what license it was under - then nobody could claim they thought that this prticular file wasn't covered


I almost posted a remarkably similar question. Less about annoyances and more about technicalities. TL;DR: I believe the answer is a matter of the author's priorities. Maybe intent would be more accurate than priorities...

I believe it is okay to reference a license in your source, depending on your definition of "okay". Lets agree that the term "unaccompanied" indicates a source file that is part of a project which has been ruthlessly separated from it's loving code base. Said file contains a line like this:

# This file is covered by the LICENSING file in the root of this project.

Or a much cooler line like this:

* @license OMGBBQ <http://goodlics.com/bbq>

"But wait!", you exclaim, "you just said that file was separated from its project! And goodlics.com redirects to a domain squatter! Stop being to trixy!" You are correct, I did say that, but that might be okay, and stop yelling at me. Here is my not-a-lawyer reasoning:

  • Almost every country has agreed to the [feel the] Berne Convention, which AFAIK means that if you create something, you have copyright on it, period. You don't need a (c) line or any crap like that, but that stuff (plus a third-party VCS like GitHub) does make it easier to prove that you created it and when you created it.
  • Therefore, if you post some juicy 1337 code online that you created, you have copyright on it. Nobody is allowed to (legally) copy it. It's rare, and shocking, I know, but I've heard that people break the law sometimes. That's still possible.
  • That awesome nyancat-bcminer-algo.qbasic file you wrote and posted on LiveJournal is, believe it or not, not public domain. Not unless you say it's public domain. By default it is yours and yours alone. It's...Precious. (At least for 25-50+ years, unless you're Disney.)
  • People conventionally communicate this intent (making some or all rights not yours and yours alone) via licencingses, but you need to announce that intent; it's opt-in opt-out (HAHA GET IT? opting in to opt out of your copyright? AWESOME). Get your tickets out, we're almost there!
  • If it is okay that the aforementioned unaccompanied files are private domain--that is, not legally copyable, then using a potentially-broken reference is perfectly fine. However, if it is not okay, then I think you need to include the license text within every source file. That way, unaccompanied files are still sure to be licensed the way you prioriti--intended. Yeah, that's better.

This reasoning makes two epic and probably-invalid assumptions:

  • A "broken" license reference falls back on default (copyrighted) behavior, which may not be a valid assumption.
  • That site you posted on doesn't have some sort of posting policy (like StackExchange) that makes everything public domain.

Thank you for riding monkey-brain airways.

Disclaimer: This seems logical to me to I am 90% sure that I am 100% wrong.


There is a difference between license and preamble.

In some of my projects I am using the GNU General Public License, Version 3.0. The GNU GPL makes it necessary to have a preamble on every source code file:

The preamble and instructions are integral parts of the GNU GPL and may not be omitted.

Source: http://www.gnu.org/licenses/gpl-faq.html#GPLOmitPreamble

So here is what I do:

1. Add License.txt

To follow the rules I put a LICENSE.txt in the root of my project's repository. This is also suggested by GitHub (see "Where does the license live").

2. Add preamble using auto fold

Next I include the GPL preamble on top of every source code file BUT to make it hardly disturbing I hide it in the IDE. Most IDE's have a feature to automatically fold code blocks. NetBeans has support for Custom Code Folding and WebStorm supports folding comments too.

So here is how it looks like:

//<editor-fold desc="Preamble">
 * Company Name
 * Copyright (C) 2016 Company Name
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * ...

console.log('Here is my licensed JavaScript code.');

I think this is a very good compromise between comfortability and legal security.

If you have lots of projects where you need to add a license, then http://www.addalicense.com/ might be of help.

Please note: My advice refers to GPLv3. Other license types might not require a preamble.

  • 9
    «The GNU GPL makes it necessary to have a preamble on every source code file:» It doesn't. The part you quoted just prevents you from removing the preamble from the LICENSE file, i.e. you cannot alter the text of the GPL by dropping it. Oct 25, 2016 at 18:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.