codecrucible
CodeCrucible is a command-line security analysis tool for source code
repositories. It uses large language models to review application code for
exploitable vulnerabilities, validates findings through a dedicated audit pass,
and writes standards-compliant SARIF v2.1.0
for GitHub Code Scanning and other SARIF-compatible workflows.
Overview
CodeCrucible is designed for cost-aware, reproducible security scans of real
repositories. It ingests source files, filters low-value inputs, chunks large
codebases into model-safe prompts, runs configurable LLM analysis and audit
phases, and preserves phase artifacts for debugging and review.
- No Node.js/Python runtime — single binary, distroless Docker image (<50MB)
- Structured output enforcement — JSON Schema (
response_format) for GPT/Gemini, tool_use for Claude
- Per-phase LLM configuration — run feature detection, analysis, and audit on different models, providers, keys, and params
- Streaming responses — SSE for Anthropic keeps long generations alive past edge idle timeouts
- Token-aware chunking — large repos are split into budget-safe chunks with cross-file manifests
- Retry with backoff — exponential backoff on 429/5xx,
Retry-After header respect
- Aggressive filtering — test, vendor, binary, and doc file exclusion saves 20–40% token budget
- Valid SARIF every time — even on LLM failure, partial results produce schema-valid SARIF
Quick Start
# Build
make build
# Databricks-backed scan
export DATABRICKS_HOST=https://your-workspace.databricks.com
export DATABRICKS_TOKEN=your-token
./codecrucible scan /path/to/repo --output results.sarif
# Direct Anthropic API scan
export ANTHROPIC_API_KEY=your-anthropic-key
./codecrucible scan /path/to/repo --provider anthropic --model claude-sonnet-5
# Anthropic API scan with higher effort
./codecrucible scan /path/to/repo \
--provider anthropic \
--model claude-sonnet-5 \
--model-params '{"output_config":{"effort":"high"}}'
# Or use Claude Code CLI auth (SSO/login) with no API key
claude auth status
./codecrucible scan /path/to/repo --provider anthropic --model claude-sonnet-5
# In Claude CLI auth mode, Anthropic beta headers are forwarded via `claude --betas`
# (for example: --custom-headers "anthropic-beta: context-1m-2025-08-07").
# Direct OpenAI API scan
export OPENAI_API_KEY=your-openai-key
./codecrucible scan /path/to/repo --provider openai --model gpt-5.6
# Direct Google Gemini scan (OpenAI-compat endpoint)
export GOOGLE_API_KEY=your-google-key
./codecrucible scan /path/to/repo --provider google --model gemini-3.5-flash
# Mix providers per phase: opus for analysis, gemini for audit
export ANTHROPIC_API_KEY=your-anthropic-key
export GOOGLE_API_KEY=your-google-key
./codecrucible scan /path/to/repo \
--model claude-opus-4-8 \
--audit-provider google --audit-model gemini-3.1-pro-preview \
--fd-model gemini-3.5-flash --fd-provider google
# Preview scope without making API calls
./codecrucible scan /path/to/repo --dry-run
# Scan specific paths in a monorepo
./codecrucible scan /path/to/repo --paths src/ --paths lib/
When --output results.sarif writes to a file, CodeCrucible also writes
phase artifacts beside it: results.feature-detection.json,
results.analysis.sarif, results.audit.sarif (when audit runs), and
results.lineage.jsonl. Use
--phase-output-dir DIR to choose an explicit artifact directory, including
for stdout workflows.
The versioned lineage file records model responses, immutable observations before
merge/filtering, subsequent finding revisions and each observation's final
disposition. SARIF results link to it through properties.provenance; existing
finding IDs and partial fingerprints remain the correlation keys. Original
observations remain available even when the final result is suppressed or its
evidence is refined. A missing run-complete event indicates an interrupted run
or a lineage write failure.
Lineage contains source excerpts and model output, like the other phase artifacts;
request headers and API credentials are not recorded. It is written incrementally
with owner-only permissions. No lineage file is written for stdout-only scans
without an artifact directory.
Before audit, duplicate reports are consolidated in two passes. Results are
first grouped by primary file, start line, and normalized CWE. Rule IDs and
model wording (title, message, summary, details, remediation) are not part of
the key, so the same defect reported in different words by overlapping chunks
merges. Each group is then split by structural anchors: the first and last
location of every code-flow thread (source and sink), any
reportedLocations, and every structured finding_evidence reference except
guards (initialEvidence in SARIF), compared as file:line. Intermediate flow
steps and guards are ignored, so a flow and structured evidence that cite the
same source and sink match. Results with the same anchors merge and keep the highest severity.
Different sources or sinks at the same location stay separate findings. A
result with no anchors joins the group's anchored results only when they share
exactly one anchor set; otherwise it merges only with other anchorless
results in that group. When the higher-severity result has no code flow, the
merged result keeps the other result's flow. A merged result keeps every
original observation ID in properties.provenance, and the lineage records the
merge as a merged_from revision.
Lineage recording is best effort. If the lineage file cannot be opened, written,
or synced, or an event is rejected, the scan logs a warning and continues. SARIF
output, audit verdicts, token usage and cost, and the exit code are unaffected.
After a write failure, no further events are written. A rejected event is
dropped on its own, and later events are still recorded. Either way, the final
SARIF records execution.lineageIncomplete: true. Treat lineage from such a run
as partial.
The v2 ledger binds observations to model responses (including repair operations),
records individual accepted, retried and unresolved audit decisions, and supports
split and semantic duplicate relationships. Validate either ledger version and
optionally reconcile final SARIF with:
codecrucible validate-lineage results.lineage.jsonl --sarif results.sarif
The ledger is single-line JSONL: one compact JSON record per line, as the writer
emits it. Hand-formatted records that span several lines are rejected. A final
record that is torn or not valid JSON, followed only by whitespace, is reported
as partial lineage (complete: false) with
reasons: ["truncated final record"] in the JSON report; unresolved
observations from the valid prefix are preserved. Such a record followed by more non-whitespace content is corruption
and fails validation, as does a final record that is valid JSON but not a valid
event. Reconciliation with --sarif remains strict for partial ledgers.
Read reasons whenever complete is false; currently its only value is
truncated final record. A ledger is also partial, with no reasons entry,
when it has no run-complete event or its run-complete event records
lineageIncomplete: true.
A recorded model verdict or source quote is not proof of exploitability.
When a prompt set allows audit additions, additions that repeat an analysis finding
or another addition are discarded, with lineage reasons duplicate of analysis finding
or duplicate audit addition. A missing code path carries over to the surviving finding.
To compare audit prompts or models without analysis variance, replay the audit
on saved findings: codecrucible scan REPO --audit-from results.analysis.sarif.
Replay ingests REPO with the same filters, skips feature detection and analysis,
and audits the saved claims under their original finding IDs. Only audit
requests are sent, and the cost preflight excludes analysis. The input can be
an analysis artifact or the final output of a --skip-audit scan; audited SARIF
is rejected, as is a replay where none of the findings' files are in REPO.
recipe.auditReplay in the run metadata records the input's SHA-256 and counts
findings whose file or snippet no longer matches the checkout; verdicts for
those findings are not comparable. Replay never rewrites the analysis artifact.
Dry runs show source-input cost plus a separate rough input-and-output estimate.
The planning estimate assumes 25% input overhead, output tokens equal to 1/16
of padded input, and one repository-sized audit pass when audit is enabled.
It displays a 2–3× allowance, not a ceiling. Separate feature detection,
context compression, retries, and repeated audit batches are excluded.
The existing preflight budget check uses source-input cost; runtime accounting
uses reported token usage. All dollar values depend on configured model rates.
Installation
From Source
git clone <repo-url> && cd codecrucible
make build
Docker
make docker-build
docker run --rm \
-e DATABRICKS_HOST=https://your-workspace.databricks.com \
-e DATABRICKS_TOKEN=your-token \
-v /path/to/repo:/repo:ro \
codecrucible:latest scan /repo --output /dev/stdout
Usage
codecrucible scan [repo-path] [flags]
Per-phase LLM selection
Four symmetric flag families. The unprefixed flags configure the analysis
phase; feature-detection, audit, and context-compress inherit any knob
they don't set.
| analysis |
feature-detection (alias: --fd-*) |
audit |
context-compress (alias: --cc-*) |
--model |
--feature-detection-model |
--audit-model |
--context-compress-model |
--provider |
--feature-detection-provider |
--audit-provider |
--context-compress-provider |
--api-key |
--feature-detection-api-key |
--audit-api-key |
--context-compress-api-key |
--base-url |
--feature-detection-base-url |
--audit-base-url |
--context-compress-base-url |
--model-params |
--feature-detection-model-params |
--audit-model-params |
--context-compress-model-params |
Providers: anthropic, openai, google, cerebras, ollama, openai-compat, databricks. Auto-detected from env vars when unset.
Cerebras
Set CEREBRAS_API_KEY in your environment, then discover available model IDs:
codecrucible list-models --provider cerebras
codecrucible scan ./target --provider cerebras --model "$CEREBRAS_MODEL" --dry-run
codecrucible scan ./target --provider cerebras --model "$CEREBRAS_MODEL" --output results.sarif
CEREBRAS_MODEL here is a shell variable containing your selected model ID;
CodeCrucible reads the model from --model (or YAML / PHASES_ANALYSIS_MODEL).
You can select this deployment with --provider cerebras --model kimi (or
PHASES_ANALYSIS_MODEL=kimi). Kimi aliases are case-insensitive and tolerate
spaces, hyphens, underscores, and dots: Kimi, kimi-k2, and
kimi-k2.6 resolve to kimi-k2.6. For an account-specific deployment ID,
set model in model-params (or PHASES_ANALYSIS_MODEL_PARAMS_JSON in your
local environment); this overrides the API model name without changing the
registry entry used for sizing and estimates. Exact custom registry entries
win; unknown versions and unrelated names are not rewritten.
Cerebras requires an explicit model. kimi-k2.6 has a provisional registry
entry with assumed rates of $2/M input and $8/M output, not verified contract
pricing. It retains fallback limits of 128K context and 8192 output tokens and
uses live-verified JSON Schema output support. Every scan selecting it emits a
warning. Override the entry under models: once deployment settings are known.
Use --fd-model, --audit-model, and --cc-model to choose different models,
and the corresponding provider flags to mix providers.
The default base URL is https://api.cerebras.ai. Base URL overrides use the
same convention as the OpenAI provider: omit /v1, since the client appends
/v1/chat/completions (and model discovery appends /v1/models).
For a model absent from the registry, configure verified context/output limits,
pricing, and supports_structured_output: true under models: when the model
supports JSON Schema. See “Adding models via config” below. Unknown models use
128K context, 8192 output tokens, and no schema enforcement; these assumptions
may not match your endpoint. Use --context-limit and --max-output-tokens to
override limits. Cerebras models with no configured pricing emit a warning:
reported costs exclude their usage. Under the default --max-cost that spend is
not enforced; an explicit limit rejects the scan (see
Cost estimates and --max-cost).
Model listing discovers IDs; it does not populate pricing or capabilities.
The zai-glm-5.3-flash profile is an explicit opt-in for Cerebras deployments
that support JSON Schema output. It requires a full, case-insensitive name
match; shorter or custom IDs retain unknown-model defaults. Keep the actual
endpoint ID in local configuration, for example:
export PHASES_ANALYSIS_MODEL=zai-glm-5.3-flash
export PHASES_ANALYSIS_MODEL_PARAMS_JSON='{"model":"YOUR_DEPLOYMENT_ID","reasoning_effort":"max"}'
codecrucible scan ./target --provider cerebras --dry-run
codecrucible scan ./target --provider cerebras --output results.sarif
The profile uses the upstream model limits: 1,048,576 context tokens and
131,072 output tokens (including reasoning). Cerebras supports low, high,
and max reasoning effort for this model and defaults to max; reasoning
cannot be disabled. The example makes max explicit. See the
model documentation and
Cerebras reasoning controls