codeworth
v2.1.0
Published
Estimate what a codebase would have cost to build traditionally, using COCOMO over accurately counted source lines.
Downloads
395
Maintainers
Readme
CodeWorth
Estimate what a codebase would have cost to build traditionally — using a real cost model (Basic COCOMO) over accurately counted source lines, not a flat dollars-per-line guess.
npm install -g codeworthv2 is a rewrite. The number it produces is different from v1 on purpose: v1 over-counted lines (it counted blank lines, comments, and a phantom trailing line per file) and then multiplied by a flat rate. See the CHANGELOG.
Quick start
# Scan the current directory and estimate build cost (COCOMO, organic mode)
codeworth
# Estimate from a known SLOC count
codeworth 26024
# Legacy flat-rate behavior (SLOC × rate)
codeworth 26024 --simple --rate 10.77
# Machine-readable output for CI
codeworth --json > report.jsonWhat it does
- Counts source lines accurately. A comment- and string-aware classifier
splits every file into code / comment / blank lines across ~40 languages, so
URLs like
http://…aren't mistaken for comments and blank lines don't inflate the total. It skips binaries, minified/generated files, and (by default) anything your.gitignorefiles exclude (root and nested). - Separates code from data/docs. JSON, YAML, Markdown, etc. are reported
but don't drive the cost estimate unless you pass
--include-all. - Estimates cost with COCOMO. Effort grows non-linearly with size, so the estimate reports person-months, schedule, team size, and every assumption — not an opaque per-line figure.
The cost model
Default is Basic COCOMO (Boehm, 1981), the model behind David A. Wheeler's SLOCCount:
Effort (person-months) = a × KSLOC^b
Schedule (months) = c × Effort^d
Cost = Effort × (annualSalary / 12 × overhead)| Mode | a | b | When |
|------|---|---|------|
| organic (default) | 2.4 | 1.05 | Small team, well-understood product |
| semi-detached | 3.0 | 1.12 | Medium size/complexity |
| embedded | 3.6 | 1.20 | Tight constraints, high complexity |
Tune it:
codeworth --mode semi-detached --salary 130000 --overhead 2.0All assumptions are printed with the result so the estimate is auditable.
Options
| Flag | Description |
|------|-------------|
| --mode <name> | COCOMO mode: organic | semi-detached | embedded |
| --salary <n> | Annual developer salary (default 110000) |
| --overhead <n> | Overhead multiplier (default 2.4) |
| --simple | Legacy flat model: cost = SLOC × rate |
| --rate <n> | Per-line rate for --simple (default 10.77) |
| --path <dir> | Directory to scan (default: cwd) |
| --ignore <glob> | Exclude paths matching a gitignore-style glob (repeatable) |
| --no-gitignore | Do not honor .gitignore (root + nested) |
| --include-generated | Include minified/generated files |
| --include-all | Count data/docs languages toward cost too |
| --json | Machine-readable JSON output |
| --version, --help | — |
Example output
===================================================
CodeWorth — estimated cost to build traditionally
===================================================
Language Files Code Comment Blank
---------------------------------------------------
TypeScript 42 6,120 410 880
CSS 8 940 30 120
JSON 3 60 0 2 *
* = not counted toward cost (data/docs). See --include-all.
Totals
------
Billable SLOC : 7,060
...
Estimate
--------
Model : Basic COCOMO — Organic (small/simple team & product)
Effort : 18.7 person-months (1.6 person-years)
...
---------------------------------------------------
ESTIMATED COST : $412,300
---------------------------------------------------Accuracy & limitations
- Line classification is heuristic and line-oriented (the approach used by basic counters like SLOCCount). Comment markers inside multi-line string/template literals may be misclassified in rare cases.
- Both root and nested
.gitignorefiles are honored (deeper files override shallower ones). Use--ignore <glob>for anything git doesn't already ignore. - Unknown file types are excluded from the cost estimate.
- COCOMO estimates build effort/cost, which is not the same as market value.
Programmatic use
import { scanDirectory } from 'codeworth/counter';
import { cocomo } from 'codeworth/cost';
const { totals } = scanDirectory(process.cwd());
console.log(cocomo(totals.codeSloc, { mode: 'organic' }));License
MIT
