Cursor does not automatically add license headers to generated code, which can cause compliance issues in open-source projects. By adding license header rules to .cursorrules and creating a file template that Cursor references, you ensure every new file includes the correct license notice. This tutorial covers SPDX identifiers, header formats, and automated compliance checking.
Handling license headers in Cursor output
Open-source projects require consistent license headers in every source file. Cursor never adds these by default. This tutorial configures Cursor to include your project's license header in every new file it creates and shows how to retroactively add headers to existing files.
Prerequisites
- Cursor installed with an open-source project
- A chosen license (MIT, Apache 2.0, GPL, etc.)
- Understanding of your project's license requirements
- Familiarity with Cmd+K and Cmd+I in Cursor
Step-by-step guide
Add license header rules to .cursor/rules
Add license header rules to .cursor/rules
Create a rule that includes your exact license header text. Cursor will prepend this to every new file it generates.
1---2description: License header requirements3globs: "src/**/*.ts,src/**/*.tsx,src/**/*.js"4alwaysApply: true5---67## License Header8Every new source file MUST start with this exact header:9```10// Copyright (c) 2026 MyOrg Contributors11// SPDX-License-Identifier: MIT12```1314- Add the header as the FIRST lines of every new file15- Do NOT add the header when modifying existing files that already have one16- Do NOT modify or remove existing license headers17- The header goes BEFORE all importsExpected result: Cursor adds the license header to every new file it generates.
Create a file template for Cursor to reference
Create a file template for Cursor to reference
Create a template file that shows the correct license format. Reference this template when asking Cursor to create new files.
1// Copyright (c) 2026 MyOrg Contributors2// SPDX-License-Identifier: MIT34// This file is part of MyProject.5// See LICENSE file in the root directory for full license text.67import type { Config } from '@/types';89// ... file contentExpected result: A reference template that Cursor can follow for correct header placement and format.
Add license headers to existing files
Add license headers to existing files
Use Composer Agent mode to add the license header to all existing files that are missing it.
1// Composer prompt (Cmd+I):2// @.cursor/rules/license.mdc @src/3// Add the license header to all .ts and .tsx files in4// src/ that do not already have one. Place the header5// before all imports. Do not modify files that already6// have a copyright or SPDX header. Process one file at7// a time.Expected result: All source files receive the correct license header without disturbing existing headers.
Audit the project for missing headers
Audit the project for missing headers
Use Cursor Chat to verify that all files have the correct license header. This catches any files that were missed or created without the rule active.
1// Cursor Chat prompt (Cmd+L, Ask mode):2// @codebase Check all .ts and .tsx files in src/ for the3// license header. List any files that:4// 1. Are missing the header entirely5// 2. Have a different license header than required6// 3. Have the header in the wrong position (not first lines)Expected result: A report of all files with missing or incorrect license headers.
Set up a CI check for license compliance
Set up a CI check for license compliance
Ask Cursor to generate a simple script that verifies license headers in CI. This prevents future commits from missing the header.
1// Cursor Chat prompt (Cmd+L):2// Generate a Node.js script at scripts/check-license.ts3// that scans all .ts files in src/ and verifies each4// starts with 'Copyright (c) 2026 MyOrg Contributors'.5// Exit with code 1 and list violating files if any are missing.6// This will run in our CI pipeline.Expected result: A CI-ready script that enforces license header compliance on every commit.
Complete working example
1---2description: License and copyright header requirements3globs: "src/**/*.{ts,tsx,js,jsx}"4alwaysApply: true5---67## License Header8Every NEW source file must start with this exact header:910```11// Copyright (c) 2026 MyOrg Contributors12// SPDX-License-Identifier: MIT13```1415## Rules16- Place the header as the FIRST two lines of the file17- Add one blank line between the header and imports18- Do NOT add headers when editing existing files19- Do NOT modify existing copyright notices20- Do NOT add headers to generated files (*.generated.ts)21- Do NOT add headers to type declaration files (*.d.ts)22- Do NOT add headers to configuration files (tsconfig, etc.)2324## SPDX Reference25- MIT: SPDX-License-Identifier: MIT26- Apache 2.0: SPDX-License-Identifier: Apache-2.027- GPL 3.0: SPDX-License-Identifier: GPL-3.0-only28- BSD 3-Clause: SPDX-License-Identifier: BSD-3-Clause2930## Example Complete File31```typescript32// Copyright (c) 2026 MyOrg Contributors33// SPDX-License-Identifier: MIT3435import { something } from './module';3637export function example(): string {38 return 'hello';39}40```Common mistakes when handling license headers in Cursor output
Why it's a problem: Cursor adds the header inside a JSDoc comment instead of as line comments
How to avoid: Show the exact format (// line comments) in your .cursor/rules and include the 'this exact header' phrasing.
Why it's a problem: License header placed after imports
How to avoid: Explicitly state 'The header goes BEFORE all imports' in your rules.
Why it's a problem: Different license text in different files
How to avoid: Include the exact header text in your .cursor/rules, not a description of what it should contain.
Best practices
- Include the exact license header text in .cursor/rules, not a paraphrased description
- Use SPDX identifiers for machine-readable license declarations
- Place license headers before all imports as the first lines of every file
- Set up a CI check script to enforce license header compliance
- Use Composer Agent to retroactively add headers to existing files
- Do not add headers to generated files, type declarations, or config files
- Commit .cursor/rules/license.mdc to Git so all team members follow the same header format
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
Create a .cursorrules configuration for an MIT-licensed open-source project that ensures every new TypeScript file starts with a copyright notice and SPDX identifier. Include the exact header format, placement rules, and exceptions for generated and config files. Also generate a Node.js script that checks all files for the header in CI.
In Cursor Composer (Cmd+I): @.cursor/rules/license.mdc @src/ Add the MIT license header to all .ts and .tsx files in src/ that are missing it. Place the header before imports. Skip files that already have a copyright line. Process one file at a time.
Frequently asked questions
Will Cursor accidentally change my license to a different one?
Not if you use the exact header text in your .cursor/rules. Cursor follows the literal text. Add 'Do NOT modify existing copyright notices' as an extra safeguard.
Should I use SPDX identifiers or full license text?
Use SPDX identifiers in file headers and keep the full license text in a LICENSE file at the project root. SPDX identifiers are machine-readable and take up less space.
What about files generated by code generators?
Exclude generated files (*.generated.ts, *.d.ts) from license header rules. Add this exception to your .cursor/rules file.
Can Cursor handle dual-licensed projects?
Yes. Update the SPDX expression in your rule: 'SPDX-License-Identifier: MIT OR Apache-2.0'. The SPDX standard supports OR and AND operators for multi-license projects.
Do license headers in generated code have legal implications?
The license header indicates the file is part of your project and subject to your project's license. Generated code is generally treated the same as handwritten code under your project license. Consult a lawyer for specific legal questions.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation