# How to handle license headers in Cursor output

- Tool: Cursor
- Difficulty: Beginner
- Time required: 10-15 min
- Compatibility: Cursor Free+, any language
- Last updated: March 2026

## 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.

## Before you start

- 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.

```
---
description: License header requirements
globs: "src/**/*.ts,src/**/*.tsx,src/**/*.js"
alwaysApply: true
---

## License Header
Every new source file MUST start with this exact header:
```
// Copyright (c) 2026 MyOrg Contributors
// SPDX-License-Identifier: MIT
```

- Add the header as the FIRST lines of every new file
- Do NOT add the header when modifying existing files that already have one
- Do NOT modify or remove existing license headers
- 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.

```
// Copyright (c) 2026 MyOrg Contributors
// SPDX-License-Identifier: MIT

// This file is part of MyProject.
// See LICENSE file in the root directory for full license text.

import type { Config } from '@/types';

// ... 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.

```
// Composer prompt (Cmd+I):
// @.cursor/rules/license.mdc @src/
// Add the license header to all .ts and .tsx files in
// src/ that do not already have one. Place the header
// before all imports. Do not modify files that already
// have a copyright or SPDX header. Process one file at
// 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 (Cmd+L, Ask mode):
// @codebase Check all .ts and .tsx files in src/ for the
// license header. List any files that:
// 1. Are missing the header entirely
// 2. Have a different license header than required
// 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 (Cmd+L):
// Generate a Node.js script at scripts/check-license.ts
// that scans all .ts files in src/ and verifies each
// starts with 'Copyright (c) 2026 MyOrg Contributors'.
// Exit with code 1 and list violating files if any are missing.
// This will run in our CI pipeline.
```

**Expected result:** A CI-ready script that enforces license header compliance on every commit.

## Complete code example

File: `.cursor/rules/license.mdc`

```markdown
---
description: License and copyright header requirements
globs: "src/**/*.{ts,tsx,js,jsx}"
alwaysApply: true
---

## License Header
Every NEW source file must start with this exact header:

```
// Copyright (c) 2026 MyOrg Contributors
// SPDX-License-Identifier: MIT
```

## Rules
- Place the header as the FIRST two lines of the file
- Add one blank line between the header and imports
- Do NOT add headers when editing existing files
- Do NOT modify existing copyright notices
- Do NOT add headers to generated files (*.generated.ts)
- Do NOT add headers to type declaration files (*.d.ts)
- Do NOT add headers to configuration files (tsconfig, etc.)

## SPDX Reference
- MIT: SPDX-License-Identifier: MIT
- Apache 2.0: SPDX-License-Identifier: Apache-2.0
- GPL 3.0: SPDX-License-Identifier: GPL-3.0-only
- BSD 3-Clause: SPDX-License-Identifier: BSD-3-Clause

## Example Complete File
```typescript
// Copyright (c) 2026 MyOrg Contributors
// SPDX-License-Identifier: MIT

import { something } from './module';

export function example(): string {
  return 'hello';
}
```
```

## Common mistakes

- **Cursor adds the header inside a JSDoc comment instead of as line comments** — Without an exact format in the rule, Cursor may use /** */ block comments which do not match license scanning tools. Fix: Show the exact format (// line comments) in your .cursor/rules and include the 'this exact header' phrasing.
- **License header placed after imports** — Cursor generates imports first by default, then adds the header below them. Fix: Explicitly state 'The header goes BEFORE all imports' in your rules.
- **Different license text in different files** — Without a standardized rule, Cursor may paraphrase the license or use a different format in each file. Fix: 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

## 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.

---

Source: https://www.rapidevelopers.com/cursor-tutorial/how-to-manage-licensing-disclaimers-in-cursor-ai-s-generated-docstrings-for-open-source-projects
© RapidDev — https://www.rapidevelopers.com/cursor-tutorial/how-to-manage-licensing-disclaimers-in-cursor-ai-s-generated-docstrings-for-open-source-projects
