How the scan works

Cosmic is a free, independent tool for developers and team leads who need to show where code is hard to work with. It applies fixed rules to source text in your browser. There is no AI model and no server that receives your code.

What is read

Source files in the languages listed on the home page, up to 400 KB each. Folders such as node_modules, vendor, dist and build are skipped, as are minified files and files marked as generated. If a project has more files than your limit, the largest are read first and the report says so.

What is counted

  • Lines. A line is blank, a comment (nothing but comment text), or code. Python docstrings count as comments.
  • Cyclomatic complexity. Each function starts at 1. Add 1 for each if, loop, case, catch or except, spaced ternary, and each "and" or "or" operator. Rust match arms count too. A nested function is counted on its own.
  • Nesting. The deepest stack of control blocks inside a function.
  • Duplication. Eight or more consecutive code lines that match elsewhere after spacing is normalised. Comments, imports and lines shorter than four characters are ignored. Renamed variables will not match. HTML and CSS are not compared.
  • Notes. TODO, FIXME, HACK and XXX in capitals inside comments.
  • Tests. Files recognised by name or folder, such as tests/ or .test.js. This is not test coverage.

Debt points per file

SignalPoints
Function complexity above 102 for each step above 10
Function longer than 60 lines1 for each 10 extra lines
File with more than 400 lines of code1 for each 25 extra lines
Nesting deeper than 43 for each extra level
Duplicated lines1 for each 5 lines
Notes in comments1 per TODO, 2 per FIXME, HACK or XXX

Test files count at half weight, their function length is not scored, and the fix list hides them unless you ask. 25 points or more is high (red), 8 or more is watch (yellow), and anything lower is green. A job is called large at 50 points and medium at 15.

The 10 for complexity follows the limit Thomas McCabe suggested when he introduced the measure in 1976. The other thresholds and all the weights are choices made for this tool. They are not an industry standard, so use them to compare files within one project rather than to grade teams.

The money figures

The yearly estimate is developers × salary × (1 + overhead) × the share of time lost. You supply all of them. The per-file figure in the fix list divides the quarterly estimate in proportion to debt points. It helps with ordering and is not a measured cost.

Known limits

  • Functions are recognised from text patterns. Macros, unusual formatting, regular expressions in odd positions and JSX text can cause misses or miscounts.
  • The scan sees the code as it is now. It does not read commit history, so it cannot tell how often a file changes.
  • It does not find security problems or bugs.
  • GitHub allows a limited number of anonymous requests each hour.