Skip to content

Getting Started

Michael L. McKnight edited this page Dec 5, 2026 · 2 revisions

Getting Started

Canonical source: the README (Install, Quickstart, Configuration, Python API).

The latest release is v1.4.0. TypeScript, inline suppressions, [tool.code-cleaner] project defaults, Java taint tracking, and one-level Python inter-procedural taint are on main and ship in the next release. Commands and flags below that are marked "on main" are not in the v1.4.0 tag.

Requirements

  • Python 3.10 or newer (CI runs 3.10–3.13).
  • No third-party packages for the core install. Optional extras add parsers.

Install from the v1.4.0 release

# core only, standard library
pip install "git+https://github.com/ZodiacDog/Code-Cleaner@v1.4.0"
pip install "code-cleaner[all] @ git+https://github.com/ZodiacDog/Code-Cleaner@v1.4.0"

To install current main (the next release) instead, omit the @v1.4.0 tag, or clone and pip install . / pip install ".[all]":

git clone https://github.com/ZodiacDog/Code-Cleaner.git
cd Code-Cleaner
python -m venv .venv && . .venv/bin/activate     # Windows: .venv\Scripts\activate
pip install .                  # core only, standard library
pip install ".[all]"           # + tree-sitter grammars, esprima, javalang, and (on main) tomli
pip install -e ".[all]"        # editable install for development
code-cleaner version           # shows which optional components were found

Extras (on main; v1.4.0 has the same names except [toml], and [treesitter] then had 7 grammars rather than 9):

  • [treesitter] — tree-sitter and 9 grammar packages (C#, C++, Go, Ruby, Rust, SQL, JavaScript, TypeScript, Java)
  • [js] — esprima
  • [java] — javalang
  • [llm] — no dependencies; the LLM client uses the standard library
  • [toml] — tomli on Python 3.10, so [tool.code-cleaner] can be read (Python 3.11+ uses the standard library's tomllib and needs nothing). On main; ships in the next release.
  • [all] — everything

code-cleaner version lists any installed grammar it cannot use. Without installing, you can run python -m code_cleaner ... from the repository root.

Code Cleaner is not on PyPI yet.

Analyze a project

code-cleaner analyze app.py src/                     # text report; folders are walked recursively
code-cleaner analyze src/ --format json -o report.json
code-cleaner analyze src/ --format sarif -o results.sarif
code-cleaner analyze . --exclude 'tests/*' --exclude 'vendor/*'
code-cleaner analyze src/ --fail-on high --min-score 80

Useful switches (all are on code-cleaner analyze --help on main):

Flag What it does
--format {text,json,sarif} Output format (default text)
-o FILE Write the report to a file
--exclude GLOB Skip matching paths (repeatable)
--language LANG Force a language (python, javascript, typescript, java, csharp, cpp, sql, go, ruby, rust, html, scrawl). typescript is on main (not in v1.4.0).
--fail-on {critical,high,medium,low,info,none} Fail when a finding is at or above this severity (analyze defaults to none)
--min-score N Fail when any file's quality score is below N (0–100)
--disable-rule ID Suppress a rule everywhere (repeatable; ids are in Rules)
--style-rules Enable opinion/style rules (always INFO)
--no-taint / --no-ai-checks / --no-tree-sitter Turn those stages off
--project-root DIR Where requirements.txt, pyproject.toml, or package.json live
--known-module NAME Never report this module as hallucinated (repeatable). On main.
--no-config Do not read defaults from [tool.code-cleaner] in pyproject.toml. On main.
--no-inline-suppressions Ignore code-cleaner: ignore[...] comments and report every finding. On main.
--no-scrawl-compiler Do not also run the rosetta tool on SCRAWL files
--absolute-paths SARIF: keep absolute file paths

analyze skips .git, node_modules, virtualenvs, __pycache__, build, dist and target.

Project configuration and inline suppressions (on main)

These are on main and ship in the next release. They are not in v1.4.0.

The CLI (analyze and fix) reads default options from a [tool.code-cleaner] table in pyproject.toml:

[tool.code-cleaner]
exclude = ["tests/*", "vendor/*"]
disable-rule = ["ai-todo-comment"]
fail-on = "high"
min-score = 80

Keys: exclude, disable-rule, enable-rule, known-modules, fail-on, min-score, style-rules, taint, ai-checks, tree-sitter, inline-suppressions (hyphens or underscores). Command-line flags win: scalars and --enable-rule replace the file's value; --exclude, --disable-rule and --known-module are added to the file's lists. --no-config ignores the table. On Python 3.10, install code-cleaner[toml] (it adds tomli); Python 3.11+ uses tomllib. Full table: README: pyproject.toml.

To accept one finding on one line:

result = eval(expr)  # code-cleaner: ignore[security/dangerous-use-of-eval]
token = load()       # code-cleaner: ignore[ai-secret-token, taint-*]   (several ids; * wildcards)
debug(value)         # code-cleaner: ignore                             (every finding on this line)

Use the language's own comment marker (#, //, /* */, --, <!-- -->). Only that line is affected. Suppressed findings do not count towards the score or the CI gate; the count is in metrics['suppressed']. Details: README: Inline suppressions.

Exit codes

Exit code Meaning
0 OK (fix: the result passes)
1 Gate failed: a file scored below --min-score, or has a finding at or above --fail-on (fix: still failing after the last iteration)
2 Usage or input error (missing path, bad option)

Fix loop (optional)

code-cleaner fix examples/fixdemo/app.py --provider mock -o fixed.py    # offline demo

fix defaults to --min-score 90 and --fail-on high. The input file is only overwritten with --in-place. Details: Fix Loop.

SCRAWL

code-cleaner scrawl check FILE...
code-cleaner scrawl compile FILE [-o OUT]
code-cleaner scrawl run FILE          # needs the rosetta tool
code-cleaner scrawl toolchain

See SCRAWL and the user guide.

Python API

from code_cleaner import CodeCleaner, Language

cleaner = CodeCleaner()
result = cleaner.analyze_file("app.py")    # language from the extension
print(result.quality_score, result.security_grade, result.security_score)
for issue in result.issues:
    print(issue.line, issue.severity.value, issue.effective_rule_id, issue.message)

Configuration keys and more of the API are in the README. How the pipeline works: docs/architecture.md.

Next

Clone this wiki locally