Skip to content
mentoor

Topic 2 of 5 · 4 min read

Tracing where generated code came from

Goal: Decide whether an AI-generated block may be copied from a licensed project and which checks would confirm it.

Provenance means knowing where a piece of code came from; for AI-written code, the question is whether the model reproduced someone else's licensed code and whether you can show how a change was made. Models learn from huge amounts of public code. Most output is new combinations, but a model can sometimes repeat a distinctive passage close to word for word.

Check yourself · 1 of 3

A generated 150-line function has an unusual structure and a comment naming another project. What is the best next step?

Choose one answer

Why it matters

Whether AI output can be copyrighted, and who owns it, depends on the country and is still being settled. What you can control today is simpler: do not ship code that is a copy of licensed work without meeting its licence, and keep records so you can answer a question later.

Where copying risk is highest

  • Long, distinctive blocks: a complete algorithm with odd variable names, or a whole file.
  • Code with a comment, header or licence line still attached.
  • Narrow niches with few public examples, so the model has little else to draw from.
  • Prompts that ask for "the code from project X".

Short, common idioms, such as a loop that reads a file, are not a concern.

Three practical checks

  1. Turn on the vendor filter. Some assistants, including GitHub Copilot, can flag or block suggestions that match public code. Know whether your tool has one, whether it is on, and what it does not cover, such as agent edits.
  2. Search for a distinctive line. Put a unique string or comment from the block into a code search engine. A hit in a licensed repo is a lead.
  3. Run a scanner on the change. A licence and copyright scanner such as ScanCode finds licence text and headers inside files.

Record the origin

Keep a short trail: the commit message or PR says which tool wrote it, and the prompt or issue it came from. Many teams add a trailer such as Assisted-by: <tool>. This is not a legal shield. It lets a reviewer know which changes deserve a closer look.

Before and after

Weak: "The agent wrote a 120-line parser. It works, so I merged it." Better: "The parser has an unusual state table and a comment naming another project. I searched two distinctive lines, found a GPL project, and asked the agent to rewrite it from our spec."

What goes wrong

  • Trusting "the model wrote it" as a defence. If the result is a copy, the licence still applies.
  • A filter treated as a guarantee. It matches known public code. It does not prove anything about private or unindexed code.
  • No trail. Months later nobody can say which tool produced a file.

Examples

The leftover header

/* Copyright (c) 2014 Acme Audio Labs
 * Licensed under the GPL v2 */
static int fft_bins(int n) { /* ... */ }

A generated file arrives with a header from another project. Do not delete the header and move on. That is evidence of a copy. Stop, find the source, and either comply with the licence or have the code rewritten.

A commit trail

Add retry with jitter to the upload client

Assisted-by: Claude Code
Prompt: issue #482, section "Retry policy"

This costs five seconds and tells a later reviewer which changes came from an assistant.

Key points

  • Models can occasionally reproduce distinctive public code almost verbatim, so provenance is still your job.
  • Risk is highest for long, distinctive blocks and code that still carries comments or headers from another project.
  • Use the assistant's public-code match filter if it has one, and know what it does not cover.
  • Search a distinctive line and scan the change before merging a large generated block.
  • Record which tool and prompt produced a change so reviewers know where to look harder.

Common mistakes

  • Deleting a copyright header from generated code instead of investigating it.
  • Assuming a code-match filter covers agent edits, chat answers and private code.
  • Skipping the search because the code "looks generic" even when it is long and unusual.
  • Keeping no record of which tool produced which change.

Check yourself · 2 of 3

Which generated code is the LEAST likely to raise a copying concern?

Choose one answer

Check yourself · 3 of 3

Your assistant has a public-code match filter turned on. What does that tell you?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic