Skip to main content

Code Duplication

Skylos finds copy-pasted code blocks across Python, TypeScript/JavaScript, Java, Go, C#, Rust, PHP, Ruby, C/C++, Kotlin, Swift, Dart, Shell, and SQL using rolling-hash token matching (with Rust acceleration via skylos_fast when available).

Quick start​

# Report duplicated blocks across a repository
skylos . --duplication

# Fail a PR if more than 3% of new code is duplicated
skylos . -a --diff origin/main --gate --max-new-duplication 3

# Enforce both overall and new-code limits
skylos . -a --diff origin/main --gate \
--max-new-duplication 3 \
--max-duplication 5

For full Cloud scans that keep findings repository-wide while still measuring new-code duplication against a pull request base, pass --code-health-base:

skylos . -a --upload --code-health-base "$BASE_SHA" --duplication

Noise controls and refactor-aware checks​

  • Ignores boilerplate headers: Comments, docstrings, and standard import blocks (import, using, #include, use) do not trigger duplication alerts.
  • Same-language matching: Files are compared only within the same language family (for example, .ts, .tsx, .js, and .jsx together).
  • Refactor-aware new-code checks: Moving code that already existed on the base commit does not fail the new-code duplication gate unless the edit creates a new duplicate block. Disable with --no-refactor-aware-duplication or refactor_aware = false.
  • Small-diff floor (min_new_lines, default 20): Tiny diffs under 20 new lines report duplication without failing the new-code gate.
  • Exit codes: Exits 1 when duplication exceeds your limit (compared before rounding) and 2 if in-scope files could not be read or analysis hit a safety limit.

Configuration​

Add settings to pyproject.toml (under [tool.skylos.*]) or skylos.toml:

[tool.skylos.duplication]
enabled = true
min_lines = 10
min_tokens = 50
min_new_lines = 20
# Skips duplication only; security and secret checks still run on these paths.
exclude = ["**/generated/**", "**/proto/**"]
include_tests = false
ignore_identifiers = false
ignore_literals = false
refactor_aware = true

[tool.skylos.gate]
max_new_duplication = 3.0
max_duplication = 5.0

In Skylos Cloud​

When you upload a scan with --duplication (and --code-health-base on PRs), Skylos sends only bounded line counts, percentages, refactor-exemption counts, and up to 10 duplicated block ranges — never source code:

  • Every plan can view the Code health panel on the scan page.
  • Workspace plans can enforce max_duplication and max_new_duplication in Policy, sync limits to CI (skylos sync pull), list duplicated block ranges in GitHub checks and PR comments, and approve logged Merge anyway overrides.