Skip to main content
RapidDev - Software Development Agency
cursor-tutorial

How to handle license headers in Cursor output

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.

What you'll learn

  • How to add license header rules to .cursorrules
  • How to create file templates with correct license notices
  • How to use Cursor to add headers to existing files
  • How to audit a project for missing license headers
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner6 min read10-15 minCursor Free+, any languageMarch 2026RapidDev Engineering Team
TL;DR

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

1

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.

.cursor/rules/license.mdc
1---
2description: License header requirements
3globs: "src/**/*.ts,src/**/*.tsx,src/**/*.js"
4alwaysApply: true
5---
6
7## License Header
8Every new source file MUST start with this exact header:
9```
10// Copyright (c) 2026 MyOrg Contributors
11// SPDX-License-Identifier: MIT
12```
13
14- Add the header as the FIRST lines of every new file
15- Do NOT add the header when modifying existing files that already have one
16- Do NOT modify or remove existing license headers
17- The header goes BEFORE all imports

Expected result: Cursor adds the license header to every new file it generates.

2

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.

templates/file-header.ts
1// Copyright (c) 2026 MyOrg Contributors
2// SPDX-License-Identifier: MIT
3
4// This file is part of MyProject.
5// See LICENSE file in the root directory for full license text.
6
7import type { Config } from '@/types';
8
9// ... file content

Expected result: A reference template that Cursor can follow for correct header placement and format.

3

Add license headers to existing files

Use Composer Agent mode to add the license header to all existing files that are missing it.

Cursor Composer prompt
1// Composer prompt (Cmd+I):
2// @.cursor/rules/license.mdc @src/
3// Add the license header to all .ts and .tsx files in
4// src/ that do not already have one. Place the header
5// before all imports. Do not modify files that already
6// have a copyright or SPDX header. Process one file at
7// a time.

Expected result: All source files receive the correct license header without disturbing existing headers.

4

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.

Cursor Chat prompt
1// Cursor Chat prompt (Cmd+L, Ask mode):
2// @codebase Check all .ts and .tsx files in src/ for the
3// license header. List any files that:
4// 1. Are missing the header entirely
5// 2. Have a different license header than required
6// 3. Have the header in the wrong position (not first lines)

Expected result: A report of all files with missing or incorrect license headers.

5

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.

Cursor Chat prompt
1// Cursor Chat prompt (Cmd+L):
2// Generate a Node.js script at scripts/check-license.ts
3// that scans all .ts files in src/ and verifies each
4// 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

.cursor/rules/license.mdc
1---
2description: License and copyright header requirements
3globs: "src/**/*.{ts,tsx,js,jsx}"
4alwaysApply: true
5---
6
7## License Header
8Every NEW source file must start with this exact header:
9
10```
11// Copyright (c) 2026 MyOrg Contributors
12// SPDX-License-Identifier: MIT
13```
14
15## Rules
16- Place the header as the FIRST two lines of the file
17- Add one blank line between the header and imports
18- Do NOT add headers when editing existing files
19- Do NOT modify existing copyright notices
20- 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.)
23
24## SPDX Reference
25- MIT: SPDX-License-Identifier: MIT
26- Apache 2.0: SPDX-License-Identifier: Apache-2.0
27- GPL 3.0: SPDX-License-Identifier: GPL-3.0-only
28- BSD 3-Clause: SPDX-License-Identifier: BSD-3-Clause
29
30## Example Complete File
31```typescript
32// Copyright (c) 2026 MyOrg Contributors
33// SPDX-License-Identifier: MIT
34
35import { something } from './module';
36
37export 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.

ChatGPT Prompt

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.

Cursor Prompt

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.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.