{
  "question": "How do I check if AI-generated code copied open-source code?",
  "slug": "how-to-check-if-ai-generated-code-copied-open-source-code",
  "url": "https://www.rightshold.com/answers/how-to-check-if-ai-generated-code-copied-open-source-code",
  "short_answer": "Use the matching feature your assistant has, and scan the code yourself before you ship. GitHub Copilot can block suggestions that match public code on GitHub, or show you the matching repos and their licenses (it compares a suggestion plus about 150 characters of surrounding code). Amazon Q Developer logs accepted suggestions that resemble open-source code, with the license, in a code reference log. Many other assistants show nothing, so run a snippet scanner such as SCANOSS over the repo: it finds files and fragments that match known open-source code and reports their licenses. When you find a match, read that project's license: permissive code needs its notice kept, copyleft code may oblige you to release your source, and you can always rewrite or remove it.",
  "checklist": [
    "Copilot: in Copilot settings on GitHub, set Suggestions matching public code to Block (individual plans), or ask your org admin (Business and Enterprise seats inherit the org policy). If you set Allow, open the code references for matches before accepting.",
    "Amazon Q Developer: keep Show Code With References on and check the code reference log, which lists the license and the referenced source for each accepted suggestion.",
    "For any other tool, or for agent-written code, scan before release: scanoss-py scan -o scan-output.json . flags full-file and snippet matches with the matched component and license.",
    "Treat each match by license: MIT, BSD, ISC, Apache-2.0 means keep the copyright and license notice (and Apache's NOTICE); GPL, LGPL, AGPL or MPL means check whether its source duties fit your product; no license found means you have no permission to copy it.",
    "Fix or document: add the attribution, isolate the code under its license, or have it rewritten from a description of what it does, not from the matched code.",
    "Re-scan in CI on each release, since agents keep writing code after the first check.",
    "Keep the scan output with the release; it shows what you checked and when."
  ],
  "sections": [
    {
      "heading": "What Copilot's public-code check covers, and what it doesn't",
      "points": [
        "GitHub's docs say the check compares a suggestion and about 150 characters of surrounding code against an index of public code on GitHub.com. The index doesn't include private repos or code hosted outside GitHub, and it's refreshed periodically, so it can miss new code.",
        "For inline suggestions, Copilot only checks accepted, unchanged suggestions. GitHub says matches typically occur in less than one percent of inline suggestions.",
        "On GitHub, chat responses can show a reference beneath the output, and Copilot cloud agent session logs link to details when a delegated task generated matching code.",
        "It finds near-verbatim text, not code that does the same thing in a different way. Absence of a match is not proof the code is original."
      ]
    },
    {
      "heading": "Does turning the filter on change indemnity?",
      "points": [
        "Not since April 3, 2026. Microsoft's Customer Copyright Commitment page says GitHub offerings have no additional required mitigations and the Duplicate Detection filter is no longer required for coverage. It remains available to use.",
        "Older advice (and GitHub's 2024 Copilot terms) said the filter had to be set to Blocked to keep GitHub's defense obligations. Those Copilot Product Specific Terms were deprecated on March 5, 2026 for new subscriptions and renewals. Check which terms your plan is on."
      ]
    },
    {
      "heading": "How snippet scanners work",
      "points": [
        "SCANOSS fingerprints each file locally (winnowing hashes of overlapping code fragments) and sends the fingerprints, not the source, to its knowledge base, which returns full-file or snippet matches with component, license and line ranges.",
        "The default public API needs no key. The fingerprint file includes your file paths, so review it if paths are sensitive. SCANOSS also documents an offline fingerprint-then-scan flow.",
        "ScanCode Toolkit is a different job: it detects license texts, notices and copyrights already present in your files and dependencies. Use it to find licenses you already pulled in, and a snippet scanner to find copied code with no notice."
      ]
    }
  ],
  "checks": [
    {
      "label": "A matched MIT snippet, edited, in an app you sell",
      "license": "MIT",
      "license_name": "MIT License",
      "intended_use": {
        "commercial_use": true,
        "modification": true,
        "redistribution": true
      },
      "verdict": "permitted",
      "answer": "Yes",
      "findings": [
        "Every use you described is granted by MIT, and nothing you described is prohibited."
      ],
      "duties": [
        "attribution",
        "license_notice"
      ],
      "official_text": "https://opensource.org/license/mit"
    },
    {
      "label": "A matched GPL-3.0 snippet, edited, in an app you sell",
      "license": "GPL-3.0-only",
      "license_name": "GNU General Public License v3.0",
      "intended_use": {
        "commercial_use": true,
        "modification": true,
        "redistribution": true
      },
      "verdict": "permitted",
      "answer": "Yes",
      "findings": [
        "Every use you described is granted by GPL 3.0, and nothing you described is prohibited."
      ],
      "duties": [
        "attribution",
        "license_notice",
        "state_changes",
        "share_alike",
        "source_disclosure"
      ],
      "official_text": "https://www.gnu.org/licenses/gpl-3.0.html"
    }
  ],
  "checks_note": "Yes means the license grants the use, on the duties listed. Duties such as source_disclosure, share_alike and network_source_offer are the ones that conflict with keeping a product closed-source.",
  "ask_rightshold": {
    "start": "https://www.rightshold.com/start?ref=seo",
    "mcp_endpoint": "https://www.rightshold.com/mcp",
    "ask": "My scanner says this function matches code in a GitHub repo. What license does that repo declare, and can I keep the code in a commercial closed-source app?",
    "mcp_call": {
      "tool": "check_license",
      "arguments": {
        "source_url": "https://github.com/expressjs/express",
        "intended_use": {
          "commercial_use": true,
          "modification": true,
          "redistribution": true
        }
      }
    },
    "also": [
      "Free, no key. Pass the matched repo's GitHub page (or its npm or PyPI page) as source_url; Rightshold reads the license it declares and returns the verdict and the duties for your use. No license found answers needs_review, which means you have no grant to rely on.",
      "attribution_string writes the credit line a license asks for once you decide to keep the code.",
      "check_rights_batch checks up to 100 matched sources at once."
    ],
    "scope": "Rightshold doesn't scan your code or detect copying. It reads the license the matched project declares and tells you what that license allows and requires. Use a matching tool (your assistant's or a snippet scanner) to find matches first."
  },
  "sources": [
    {
      "title": "GitHub Docs: References to matching public code",
      "url": "https://docs.github.com/en/copilot/concepts/completions/code-referencing"
    },
    {
      "title": "GitHub Docs: Managing Copilot policies as an individual subscriber (block or allow matching public code)",
      "url": "https://docs.github.com/en/copilot/how-tos/manage-your-account/manage-policies"
    },
    {
      "title": "Microsoft: Customer Copyright Commitment required mitigations (GitHub offerings, April 3, 2026)",
      "url": "https://learn.microsoft.com/en-us/legal/cognitive-services/openai/customer-copyright-commitment"
    },
    {
      "title": "GitHub: Copilot Product Specific Terms (deprecated March 5, 2026)",
      "url": "https://github.com/customer-terms/github-copilot-product-specific-terms"
    },
    {
      "title": "AWS: Amazon Q Developer, Using code references",
      "url": "https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-reference.html"
    },
    {
      "title": "SCANOSS docs: How scanning works (fingerprints, not files)",
      "url": "https://docs.scanoss.com/en/latest/poc/evaluation/introduction"
    },
    {
      "title": "SCANOSS docs: Scanning a file or directory (full vs snippet matches)",
      "url": "https://docs.scanoss.com/en/latest/core/engine/scanning-file-or-directory"
    },
    {
      "title": "SCANOSS docs: Fingerprint-only scanning",
      "url": "https://docs.scanoss.com/en/latest/developer-tools/recipes/fingerprint-only-scanning"
    },
    {
      "title": "scanoss-py (default API needs no key)",
      "url": "https://github.com/scanoss/scanoss.py"
    },
    {
      "title": "ScanCode Toolkit",
      "url": "https://github.com/aboutcode-org/scancode-toolkit"
    }
  ],
  "related": [
    {
      "title": "Who owns code written by an AI coding agent?",
      "url": "https://www.rightshold.com/answers/who-owns-code-written-by-an-ai-coding-agent"
    },
    {
      "title": "Can I use code from GitHub in my product?",
      "url": "https://www.rightshold.com/answers/can-i-use-code-from-github-in-my-product"
    },
    {
      "title": "Can I use GPL code in proprietary software?",
      "url": "https://www.rightshold.com/answers/can-i-use-gpl-code-in-proprietary-software"
    },
    {
      "title": "How to stop an AI coding agent from installing hallucinated packages",
      "url": "https://www.rightshold.com/answers/how-to-stop-an-ai-coding-agent-from-installing-hallucinated-packages-slopsquatting"
    }
  ],
  "computed_from": "Curated guidance; license verdicts computed from Rightshold's license profiles at render time. Not legal advice.",
  "updated": "2026-10-30"
}