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.
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_usefor 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-Afterheader 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
# 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.sarifThe 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.
Enable --scope-planning (or SCOPE_PLANNING=true) to ask the configured
feature-detection model to nominate low-value, high-token artifacts before
the final budget check and chunking. It runs independently of
--skip-feature-detection. Existing scans retain their scope unless enabled.
The planner ranks admitted files locally and sends at most 32 candidates of at least 4,096 estimated source tokens. Each has a file ID, path, token estimate, and at most 1,536 header bytes plus 512 tail bytes. The JSON inventory is capped at 64 KiB and the estimated request at 16,000 input tokens, reduced further to fit the model's context with output and safety reservations. No full large file is sent just to decide whether to scan it.
Valid nominations are applied automatically, without per-run approval. The first
version accepts only recognizable MySQL/MariaDB/PostgreSQL dumps, valid JSON
under fixtures/ or __snapshots__/, and byte-identical generated duplicates
whose original remains in scope. Each nomination needs an exact sampled quote
and a reason; size alone is insufficient. Unknown IDs, paths/globs, unsupported
categories and unverifiable evidence cannot remove files. Explicit --include
patterns always win. Other large or uncertain files stay in scope.
The scope-planning.json phase artifact (or results.scope-planning.json
sidecar) and SARIF execution.scopePlan record every applied exclusion, content
fingerprint, reason and estimated source tokens saved. These files are excluded,
not analyzed or declared safe. Source coverage counts only the remaining scope.
The receipt also records rejected nominations, model usage and fallback status;
it is saved even if the subsequent budget check rejects the scan.
--dry-run makes no model calls and reports scope planning as unevaluated.
Audit replay preserves its original source scope and skips the planner. A failed,
truncated or malformed planner response retains the original scope. Planner
usage counts against the scan-wide input-token threshold and dollar allowance.
A bounded planner request may therefore incur cost even when the final scan
budget check fails. Missing planner pricing with a positive dollar limit skips
the planner; prepaid deployments can use --max-cost 0 --max-input-tokens N.
Use --fail-on-incomplete (or FAIL_ON_INCOMPLETE=true) in automation that
requires all admitted source and requested audit work to finish. CodeCrucible
writes partial SARIF and phase artifacts first, then exits 4 for incomplete
analysis/audit coverage or a failed scan invocation. Successfully recovered
requests, explicit scope exclusions, --skip-audit, audit replay's skipped
analysis, and valid unverified audit verdicts do not by themselves fail this
check. Other errors (configuration or output I/O) still exit 1; findings above
--fail-on-severity still exit 2. Without this option, existing exit behavior
is unchanged.
--max-input-tokens N (environment: MAX_INPUT_TOKENS) sets a scan-wide
reported input-token threshold, independent of model prices. It includes
feature detection, context compression, analysis, audit, and model repair or
recovery requests. Use --max-cost 0 alongside it when a deployment is prepaid
or has no configured dollar rates; an explicitly requested dollar budget still
requires pricing.
New requests stop once reported prompt-token usage reaches the threshold. Requests already running may finish over it, so this is a request-boundary budget, not a strict provider billing ceiling. All reported usage from those responses is retained. Internal transport retries without a usage response cannot be measured. A denied request or reported usage above the threshold produces partial SARIF and a failed scan, even if an optional phase normally falls back after an error. Exactly reaching the threshold on the last required request is successful. Zero (default) disables this limit; negative values are rejected. Uncached input, cache-creation input and cache-read input all count, including when using Claude CLI login. Output/reasoning tokens do not count against this input-only budget.
EXCLUDE, INCLUDE, and PATHS also accept JSON arrays of strings, for
example EXCLUDE='["generated files/**", "data/a,b.sql"]'. [] explicitly
clears the list. Native YAML arrays and repeated CLI flags continue to work;
explicit CLI flags override environment values. A string beginning with [ is
parsed as JSON and invalid/non-string elements fail configuration loading.
For a literal bracket-prefixed glob, put it inside a JSON/YAML array or pass it
with the corresponding CLI flag.
git clone <repo-url> && cd codecrucible
make buildmake 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/stdoutcodecrucible scan [repo-path] [flags]
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.
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.sarifCEREBRAS_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.sarifThe 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.
Deployment-specific limits may be lower; override them under models: or with
per-phase context/output settings when necessary. JSON Schema output, max
reasoning, and the 131,072-token output allowance were accepted in a live
request, and a complete analysis/audit scan was verified. This does not
establish maximum-length generation or a fully occupied 1M-token context.
Pricing is unconfigured: reported costs exclude this model, the default
--max-cost does not cover its spend, and an explicit --max-cost rejects the
scan. Configure contract pricing under models: before relying on cost
estimates.
When switching deployments, update the model override in local
model-params / PHASES_ANALYSIS_MODEL_PARAMS_JSON as well as the selected
profile. Request-body overrides determine the actual endpoint even after
changing --model. Clear old per-phase output-limit overrides to use the
profile's default. Set exact_match: true on custom models: entries to
exclude them from aliases and partial-name matching too.
Use --provider ollama for Ollama (no API key needed, defaults to localhost:11434):
codecrucible scan --provider ollama --model llama3.1:70b --context-limit 131072 .Use --provider openai-compat for any OpenAI-compatible API (vLLM, LM Studio, text-generation-inference):
codecrucible scan --provider openai-compat --model my-model --base-url http://localhost:8000 .Each pipeline phase (analysis, feature-detection, audit, context-compress) can use a different provider/model. Per-phase flags are hidden from --help for clarity but work as documented:
# Cheap model for feature detection, expensive model for analysis
codecrucible scan --model claude-opus-4-8 --feature-detection-model claude-sonnet-5 .Per-phase flags follow the pattern --{phase}-{flag} (e.g. --audit-model, --audit-provider, --audit-api-key, --audit-base-url). Short aliases: --fd-* for feature-detection, --cc-* for context-compress.
--audit-batch-size int split audit into N-finding batches (default 25)
--audit-confidence-threshold float reject findings below this confidence (default 0.3)
--audit-from string audit a saved analysis SARIF instead of running analysis
--semantic-dedup string v3 duplicate relationships: off or report (default report)
--base-url string override default provider URL
--compress compress whitespace in source files to save tokens
--concurrency int max parallel chunks (default 3)
--context-budget-pct int % of context window for supplementary context (default 15, max 40)
--context-limit int override model context window in tokens (0 = model default)
--context-source strings supplementary context: name=X,type=<path|repo|url|inline>,location=Y
--custom-headers strings extra HTTP headers, format 'Name: Value'
--custom-requirements string additional requirements appended to the prompt
--dry-run preview scope and cost without API calls
--exclude strings glob patterns to exclude
--fail-on-severity float exit code 2 if any finding >= this severity (0-10)
--include strings glob patterns to force-include
--include-docs include documentation files in analysis
--include-tests include test files in analysis
--max-cost float maximum cost budget in dollars (default 25)
--max-file-size int exclude files larger than this (default 102400)
--max-output-tokens int override model max output tokens (0 = model default)
-o, --output string write SARIF to file (default: stdout)
--phase-output-dir string write per-phase artifacts to this directory
--paths strings paths within the repo to analyze
--prompts-dir string prompt set directory (default: prompts/default)
--request-timeout int HTTP timeout in seconds (0 = default 600s)
--skip-audit skip CWE-specific audit phase
--skip-feature-detection skip feature detection pre-pass
Global Flags:
--config string config file (default: .codecrucible.yaml)
--verbose enable debug logging
--dry-run plans the scan without calling a model. It loads the prompt set, so
it needs the same --prompts-dir a scan would use, and splits the source into
analysis chunks with the scan's chunker and budget. It prints:
- the estimated input cost of analysis and, when enabled, audit, and their total;
- an input + maximum output upper bound for the scenario, which charges every request its configured maximum output;
- the planned analysis chunk count and per-chunk source budget;
- the audit scenario. Findings do not exist before analysis, so it assumes one
finding per source file at
--audit-batch-size. Each file appears in exactly one batch, and each batch also carries the audit prompt and up to 24K retrieval tokens, capped by the audit model's input capacity; - what the estimate excludes: feature detection, supplementary context and compression, tokenizer correction, finding payloads and CWE-specific audit sections, retries, and additional audit iterations;
- for each unpriced model,
Warning: missing pricing for <model>; estimate is incomplete, not free.
The estimate is a scenario, not a spending ceiling. --dry-run never applies
the cost gate.
Before any model call, a scan compares the estimated input cost, analysis
plus audit, against --max-cost (default $25; 0 disables the check). Output
is not part of the gate. When the check fails, the error also shows the input +
maximum output upper bound.
A model missing input or output pricing, in the registry or under models:,
cannot be costed:
- With the implicit default limit, the scan warns that the default $25 cap is not being enforced for the unpriced models and continues. Priced phases are still checked against the cap.
- With an explicit limit (
--max-cost,max-costin the config file,MAX_COST, or any value other than the default), the scan is rejected:cannot enforce --max-cost: missing pricing for …; add input and output pricing or unset max-cost (--max-cost 0). Add pricing undermodels:or pass--max-cost 0.
An agent-facing skill for running and interpreting CodeCrucible scans lives at
.agents/skills/codecrucible/SKILL.md.
It covers scan planning, model and prompt selection, cost checks, and SARIF
interpretation.
The prompts/ directory contains multiple prompt sets, each a complete set of YAML templates that control how the LLM analyzes code. The default set is prompts/default/.
To use a different prompt set:
codecrucible scan --prompts-dir prompts/carlini .Available sets:
| Set | Description |
|---|---|
default |
General-purpose security analysis (used when no --prompts-dir is specified) |
core |
Default analysis with the v3 audit contract: revision-bound claims, quoted evidence checked against admitted source, code-computed verdicts, and weakness-family cards (experimental) |
carlini |
Slim Carlini-style adversarial CTF-researcher prompts |
carlini-curated |
Carlini v2 with targeted suppression rules and line-precision guidance |
exploit-proof |
Language-agnostic set that requires a concrete exploit per finding |
exploit-proof-c-kernel |
Kernel / driver / systems C — syscalls, copy{in,out}, locking, refcounts |
exploit-proof-c-userland |
C/C++ userland daemons, setuid binaries, parsers |
exploit-proof-rust |
Rust (unsafe, FFI, serde, integer casts, web frameworks) |
exploit-proof-solidity |
Solidity / Vyper — reentrancy, oracle manipulation, access control |
exploit-proof-web-go |
Go web services (net/http, gin, chi, echo, fiber, gRPC) |
exploit-proof-web-java |
JVM web apps (Spring, Jakarta EE, Quarkus, Micronaut, Ktor) |
exploit-proof-web-js |
Node.js backends and JS/TS frontends (Express, Next.js, React, Vue) |
exploit-proof-web-python |
Python web apps (Django, Flask, FastAPI, Starlette, Tornado, aiohttp) |
nano-analyzer |
Terse attacker-first voice adapted from weareaisle/nano-analyzer |
See PROMPT_SETS.md for a fuller walkthrough of when to reach for each set.
Each prompt set directory must contain: security_analysis_base.yaml, analysis_sections.yaml, feature_detection.yaml, audit.yaml, and optionally context_compress.yaml. A legacy audit (audit.yaml without a contract) also reads cwe_deep_analysis.yaml; v2 and v3 audits require audit_families.yaml instead.
A legacy audit may also report findings the analysis missed, which appear with auditStatus: "new". Setting allow_new_findings: false in audit.yaml limits the audit to the findings it was given: the audit schema allows only an empty new_findings array, and any additions a model returns anyway are excluded before verdicts are applied. Excluded additions remain in the lineage ledger as observations with the reason audit_discovery_disabled, and their total is recorded as execution.auditAdditionsDropped in the run metadata (omitted when zero). The default set uses allow_new_findings: false, so its audit only issues verdicts on analysis findings. When the key is absent, as in the other legacy sets, additions are kept and deduplicated. v2 and v3 audits have their own contracts, so the key has no effect on them, including core.
Configuration follows a priority chain: CLI flags > environment variables > config file > defaults.
Ambient credentials — cascade to any phase that doesn't set its own key:
| Variable | Description |
|---|---|
DATABRICKS_HOST |
Databricks workspace URL |
DATABRICKS_TOKEN |
Bearer token for API authentication |
DATABRICKS_ENDPOINT |
Model serving endpoint (overrides --model) |
ANTHROPIC_API_KEY |
Anthropic API key (optional if Claude Code CLI is installed and logged in) |
OPENAI_API_KEY |
OpenAI API key |
CEREBRAS_API_KEY |
Cerebras API key |
GOOGLE_API_KEY / GEMINI_API_KEY |
Google AI Studio API key |
CODECRUCIBLE_PROVIDER |
Provider override (databricks, anthropic, openai, google, cerebras) |
CODECRUCIBLE_MODEL_PARAMS |
JSON object merged into model request body |
Per-phase overrides — PHASES_<PHASE>_<KEY> where <PHASE> is ANALYSIS,
FEATURE_DETECTION, AUDIT, or CONTEXT_COMPRESS:
| Variable | Maps to |
|---|---|
PHASES_AUDIT_PROVIDER |
--audit-provider |
PHASES_AUDIT_MODEL |
--audit-model |
PHASES_AUDIT_API_KEY |
--audit-api-key |
PHASES_AUDIT_MODEL_PARAMS_JSON |
--audit-model-params |
PHASES_AUDIT_BASE_URL |
override the provider's default base URL (proxies, Azure, Vertex) |
PHASES_AUDIT_ENDPOINT |
Databricks serving-endpoint override for this phase |
PHASES_AUDIT_REQUEST_TIMEOUT |
per-phase HTTP timeout in seconds |
PHASES_AUDIT_CONTEXT_LIMIT |
per-phase context window override |
PHASES_AUDIT_MAX_OUTPUT_TOKENS |
per-phase max output override |
Same keys with PHASES_ANALYSIS_*, PHASES_FEATURE_DETECTION_*, and
PHASES_CONTEXT_COMPRESS_*. Handy for wrapper scripts that inject
per-phase config via env.
Create .codecrucible.yaml in your repo root or home directory:
model: claude-sonnet-5
provider: anthropic
include-tests: false
include-docs: false
max-cost: 25
fail-on-severity: 7.0
concurrency: 3
model-params:
output_config:
effort: high
skip-audit: false
audit-confidence-threshold: 0.3
exclude:
- "*.generated.go"
- "**/generated/**"exclude patterns apply to every file, including .sql, .proto and GraphQL
files, which otherwise bypass the default test, vendor and size filters. An
include pattern still overrides an exclude pattern.
The pipeline has four LLM phases: feature detection (gating, skipped for small repos), analysis (the main loop), audit (validation), and context compress (optional supplementary-context summarization). Each can run on a different provider, model, API key, and params.
The flat keys above (model, provider, model-params) configure the
analysis phase and are inherited by the other phases. A phases: block
overrides selectively:
# Analysis: Opus with adaptive thinking and xhigh effort. Slow, thorough, expensive.
model: claude-opus-4-8
provider: anthropic
model-params:
thinking:
type: adaptive
output_config:
effort: xhigh
phases:
# Feature detection is a cheap gating pass on a file manifest. A small
# fast model is plenty. Skipped entirely when the repo fits in one chunk.
feature-detection:
provider: google
model: gemini-3.5-flash
api-key: ${GOOGLE_API_KEY}
# Switching providers clears inherited provider-specific parameters.
# Optional Gemini-specific parameters:
model-params:
max_tokens: 2048
# Audit is a validation pass — short, structured output. Dropping
# analysis-only adaptive-thinking params keeps it fast without hurting
# quality.
audit:
model: claude-sonnet-5
model-params:
output_config:
effort: low
# provider, api-key: inherited from analysis (anthropic + its key)Inheritance rules
- Any per-phase field left at its zero value inherits from the analysis phase.
- When the resolved provider changes, API key, base URL, endpoint, headers, and model parameters are reset before applying explicit phase overrides. The new provider uses its own ambient credentials and default URL.
model-paramsinherits on empty; a phase that sets its own params gets exactly those params (replace, not merge) — so you can drop inherited keys.--context-limit/--max-output-tokensinherit per-phase too. Previously they only applied to the main model; now--audit-model gemini-3.1-pro-previewwith--context-limit 500000gives audit the override as well.
Provider resolution, per phase: explicit --<phase>-provider, else the
model registry's hint for that phase's model, else Databricks ambient env
(Databricks proxies all providers), else whichever direct-provider key is
set, else databricks.
Security review in isolation is pattern-matching. Security review with the API spec, the threat model, and the sibling repo that implements the other side of an RPC contract is understanding. Supplementary context feeds that material to the analysis and audit prompts so the model can distinguish "unvalidated input" from "input validated by the gateway three hops upstream".
Source types:
| type | location is… |
notes |
|---|---|---|
path |
filesystem path (file or directory) | directories go through the ingest walker — .gitignore, binary-skip, and include/exclude globs all apply |
repo |
git clone URL | shallow-cloned to a temp dir, then treated as path |
url |
HTTP(S) URL | 4 MiB cap, HTML stripped to text, non-HTTP schemes and private-IP redirects refused |
inline |
the content itself | for short notes — "admin routes are mTLS-gated" |
Budget discipline. Supplementary context shares the context window with
the scan target, so it's capped at --context-budget-pct (default 15%, hard
ceiling 40%). When sources exceed the cap:
- Priority packing (always): sources are sorted by
prioritydescending and packed greedily. The last source that doesn't fully fit is truncated with a[... N tokens truncated ...]marker; anything after is dropped. - LLM compression (opt-in per source): sources with
compress: truethat exceed their fair share of the budget go through a one-shotcontext-compresspre-pass that summarises them down. Runs once per scan on thephases.context-compressmodel — typically a cheap flash/haiku.
Why this approach: relevance-filtering and embedding retrieval both assume you can pick different context per chunk, but supplementary context is shared across all chunks — the API spec is relevant everywhere. Priority packing is deterministic and free; LLM compression handles the "200-page API reference" case without adding an embedding-model dependency.
context-sources:
- name: "Payments API Spec"
type: path
location: ../api-contracts/payments/openapi.yaml
priority: 100
phases: [analysis, audit] # empty/omitted = both phases
- name: "Auth SDK"
type: repo
location: git@github.com:org/auth-sdk.git
priority: 80
include: ["**/*.go"]
compress: true # squeeze via LLM if over budget
- name: "Threat model"
type: url
location: https://wiki.internal/threat-model/payments
priority: 90
phases: [audit] # only the auditor needs this
- name: "Review notes"
type: inline
location: |
The /admin endpoints sit behind mTLS at the gateway. Findings
there must demonstrate gateway bypass, not just handler weakness.
priority: 70
context-budget-pct: 15
phases:
context-compress:
model: claude-haiku-4-5 # compression is a writing task, not analysisOn the CLI (scalar fields only — use the config file for globs and phase lists):
./codecrucible scan ./target \
--context-source 'name=spec,type=path,location=../contracts/api.yaml,priority=100' \
--context-source 'name=notes,type=inline,location=admin is mTLS-gated,priority=50' \
--context-budget-pct 20 \
--cc-model claude-haiku-4-5Guardrails. Load failures (404, clone error, missing file) log a warning and skip that source — the scan continues. If context consumes so much of the window that less than 5000 tokens remain for actual source code, the scan aborts before any LLM call with a clear error.
model-params is merged into the top level of the request body — use it for
provider-specific knobs (adaptive thinking, reasoning effort, custom safety
settings).
- YAML map form in config files; JSON string form on the CLI and in env vars.
- When both are present, the JSON string deep-merges onto the map; JSON wins on conflict.
- Not forwarded when Anthropic falls back to Claude CLI auth.
- Unknown keys are passed through; the provider rejects what it doesn't understand.
| Model | Provider | Context Limit | Max Output | Structured Output |
|---|---|---|---|---|
| claude-sonnet-5 | anthropic | 1M | 128K | output_config.format JSON Schema |
| claude-opus-4-8 | anthropic | 1M | 128K | output_config.format JSON Schema |
| claude-fable-5 | anthropic | 1M | 128K | output_config.format JSON Schema |
| claude-haiku-4-5 | anthropic | 200K | 64K | output_config.format JSON Schema |
| goose-claude-4-6-opus | databricks | 200K | 32K | tool_use |
| goose-claude-4-7-opus | databricks | 1M | 128K | tool_use |
| gpt-5.6 | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.6-sol | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.6-terra | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.6-luna | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.5 | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.5-cyber-preview | openai | 272K | 128K | response_format JSON Schema |
| gpt-5.5-cyber | openai | 272K | 128K | response_format JSON Schema |
| gpt-5.4 | openai | 1.05M | 128K | response_format JSON Schema |
| gpt-5.4-mini | openai | 400K | 128K | response_format JSON Schema |
| gpt-5.4-nano | openai | 400K | 128K | response_format JSON Schema |
| gemini-3.1-pro-preview | 1M | 64K | response_format JSON Schema | |
| gemini-3.5-flash | 1M | 64K | response_format JSON Schema | |
| gemini-3.1-flash-lite | 1M | 64K | response_format JSON Schema |
The registry also carries the documented long-context pricing tiers for the
gpt-5.6 family, gpt-5.5, and gpt-5.4 prompts above 272K input tokens,
and gemini-3.1-pro-preview prompts above 200K input tokens.
gpt-5.6 is OpenAI's stable alias for gpt-5.6-sol; both entries use Sol
pricing. The direct gpt-5.6-terra and gpt-5.6-luna entries expose the
documented lower-cost tiers. All GPT-5.6 entries emit an execution warning
because OpenAI documents real-time cyber safeguards that can block or pause
generation during security work.
gpt-5.5-cyber-preview and gpt-5.5-cyber are private/preview aliases with
no public provider model page yet. Their built-in entries use the currently
observed 272K context window plus GPT-5.5 request semantics and pricing, and
emit a warning that those registry parameters and cost estimates are
provisional. Override the entry under models: when your provider exposes
different limits or billing.
claude-fable-5 also emits an execution warning because security-policy
errors during a security scan can invalidate the resulting findings. Some
Anthropic workspaces also require data retention to be enabled before this
model is accessible; when the provider rejects access, CodeCrucible writes a
failed SARIF invocation and exits non-zero.
The goose-* Databricks rows are workspace serving aliases, not public model
IDs. They stay explicit because a public provider release does not establish
which deployment name a Databricks workspace exposes.
Gemini goes through Google's OpenAI-compat endpoint
(generativelanguage.googleapis.com/v1beta/openai) — Bearer auth, OpenAI
request/response shapes. Gemini-specific features (grounding, code execution)
are not available through this path; set phases.<phase>.base-url to point
at Vertex or a proxy if you need them.
All providers are also reachable via Databricks model serving when
DATABRICKS_HOST/DATABRICKS_TOKEN are set.
Unknown models get conservative defaults (128K context, 8192 max output,
unstructured). Override with --context-limit / --max-output-tokens.
The table above is the built-in registry compiled into the binary. You can
extend or override it from the config file under a models: key — useful when
a new model ships, when you run behind a proxy with a custom endpoint, or when
you want to retune pricing / context limits without recompiling.
models:
# Extend: a model the binary doesn't know about yet.
- name: gpt-acme-frontier-v1
provider: openai-compat
execution_warning: registry parameters are operator supplied
input_price_per_million: 3.0
output_price_per_million: 15.0
context_limit: 1000000
max_output_tokens: 64000
tokenizer_encoding: o200k_base
supports_structured_output: true
# Override: change a built-in's pricing without forking.
- name: gpt-5.5
provider: openai
input_price_per_million: 4.5 # negotiated rate
output_price_per_million: 27.0
long_context_threshold: 272000
long_context_input_price_per_million: 9.0
long_context_output_price_per_million: 40.5
context_limit: 1050000
max_output_tokens: 128000
tokenizer_encoding: o200k_base
supports_structured_output: true
use_max_completion_tokens: true
# Azure / self-hosted: point at a non-standard endpoint.
- name: azure-gpt-5
provider: openai-compat
endpoint: deployments/my-azure-deploy/chat/completions
context_limit: 400000
max_output_tokens: 16384
tokenizer_encoding: o200k_baseEntries are keyed by name: a user entry sharing a name with a built-in
replaces it wholesale (case-insensitive), a new name extends the registry.
Empty endpoint defaults to <name>/invocations to match the built-in
convention (Databricks serving path; other providers ignore it). name is
required; other fields follow the same YAML schema as the built-in registry.
Set execution_warning when a model has provisional limits, estimated
pricing, or operational caveats that should be logged whenever a scan selects
it.
Repository on disk
│
▼
┌──────────────┐
│ Walker │ filepath.WalkDir + .gitignore
├──────────────┤
│ Filter │ Test/vendor/binary/doc exclusion
├──────────────┤
│ Flattener │ Repomix-compatible XML with line numbers
├──────────────┤
│ Chunker │ Token-budget-aware splitting by directory
└──────┬───────┘
│
│ PhaseConfig: each box has its own (provider, model,
│ api-key, base-url, model-params, timeout). Unset
│ fields inherit from analysis. Resolved once at
│ startup by config.ResolvePhases.
│
│ repo > one chunk?
▼
┌─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐ ┌──────────────────────────┐
│ phases.feature-detection │
│ FEATURE DETECTION (optional) │◀───│ --fd-provider │
│ --fd-model │
│ file manifest → features │ │ --fd-api-key │
│ --fd-model-params │
└─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─┘ └──────────────────────────┘
│ enabled features → prunes analysis_sections
▼
┌─────────────────────────────────┐ ┌──────────────────────────┐
│ │ │ phases.analysis │
│ ANALYSIS (main loop) │◀───│ --provider │
│ │ │ --model │
│ chunk 1 ──▶ findings │ │ --api-key │
│ chunk 2 ──▶ findings } merge │ │ --model-params │
│ chunk N ──▶ findings │ └──────────────────────────┘
│ (concurrent, --concurrency) │
│ │
└────────────────┬────────────────┘
│ initial findings + CWE categories
▼
┌─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐ ┌──────────────────────────┐
│ phases.audit │
│ AUDIT (optional, --skip-audit)│◀───│ --audit-provider │
│ --audit-model │
│ findings + code + CWE prompts │ │ --audit-api-key │
│ → confirm / reject / refine │ │ --audit-model-params │
└──────────────────────────┘
└─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─┘
│ audited findings
▼
┌─────────────────────────────────┐
│ SARIF build + merge + dedup │
└────────────────┬────────────────┘
▼
SARIF v2.1.0 output
+ phase artifacts
Each phase builds its own llm.Client from its PhaseConfig — there is no
shared client object. A fresh client per phase means the learned endpoint
constraints (noForcedToolChoice, dropTemperature) reset at phase
boundaries; at most one extra 400→retry per phase when the model rejects
a feature.
After walking and filtering the repository, CodeCrucible builds one immutable index of the admitted source. Feature sampling, dependency-aware chunking, cross-chunk declaration summaries, and both audit contracts reuse that index. The scanner needs source files, not a successful build: it does not install dependencies, invoke a compiler, or fetch missing imports. Unknown languages retain their original source and lexical context. A failed Go parse falls back to lexical extraction without inventing argument bindings.
Dependency grouping follows imports only when they resolve to admitted local
files. The current resolvers cover JavaScript/TypeScript relative imports,
Python repository and relative modules, Go packages (including local go.mod
roots), explicit Kotlin imports, and quoted C/C++ includes. External and
vendored imports are skipped; missing and ambiguous candidates remain
unresolved. Unsupported import forms use the existing directory grouping.
Language-specific readers produce source facts, not security rules or verdicts.
Relative JavaScript/TypeScript imports prefer an exact admitted file, then
try source extensions and index files, including dotted basenames such as
./config.types. Multiple inferred matches remain ambiguous.
Small repositories keep the single-chunk path. Larger scans keep whole files together where the token budget permits, assign dependencies alongside their importers, and use short declaration summaries for dependencies in other chunks. Graph grouping is compared with directory grouping at the same budget. It is selected only when it improves chunk count or unique dependency-edge co-location without worsening the other; ties and tradeoffs keep directory grouping. Both candidates retain cross-chunk summaries and are checked against the rendered XML budget. These are packing measures, not evidence of better vulnerability detection. Each admitted file is analyzed in exactly one chunk, so one defect is not reported again by every chunk that could see its file. Files larger than a chunk budget remain in the coverage report and cause an incomplete-analysis warning; a manifest entry alone does not count as analyzed source.
A chunk gets one recovery round. Exhausted HTTP 408/429/5xx failures retry the original chunk unsplit. One that exceeds the model's context is re-chunked using the provider's reported total request size and context limit when available. The retry reserves output tokens and prompt/manifest overhead, keeps 20% headroom, and never exceeds 60% of the original source budget. Unknown size diagnostics fall back to 60%. Only failed chunks are retried; a limit too small for the unchanged reservations remains incomplete. One whose answer stops at the output-token limit (reasoning counts against it) is split into two groups of its files, which keep the full manifest. A recovered chunk counts as analyzed, and its failed attempt stays in the usage totals and the lineage. A single-file chunk, or a recovery chunk that fails again, remains an execution failure. The audit works the same way: a batch that stops at the output limit is retried one claim per request, and a single claim that stops there is not retried.
Audit can request additional numbered excerpts from the same indexed bytes,
independent of the original analysis chunk. --audit-from builds a fresh index
of the supplied checkout and keeps its existing drift checks and finding IDs.
Supplementary context retains its separate loading, packing, and compression
policy.
The extractor interface allows richer parsers later. A new parser must first
demonstrate useful local-import/declaration accuracy on incomplete source,
lower context duplication or better evidence retrieval, and acceptable runtime
and memory use. It must also preserve CGO_ENABLED=0 builds and the documented
single-binary/container constraints. No additional parser runtime is required.
cmd/codecrucible/ CLI entry point
internal/
cli/ Cobra commands (scan, list-models, init), pipeline orchestration
config/ Viper config, model registry, per-phase resolution (phase.go)
ingest/ File walker, filter, XML flattener
sourceindex/ Shared source facts, local imports, declarations, fingerprints
auditctx/ Bounded audit context selection and rendering
chunk/ Token counting (tiktoken), budget-aware chunking
supctx/ Supplementary-context loaders, priority packing, LLM compression
llm/ HTTP client, prompt templates, JSON schema
sarif/ SARIF types, builder, merger, post-processor, contract tests
logging/ slog-based structured logging
prompts/ Prompt sets (each subdirectory is a complete set of YAML templates)
default/ Default prompt set
carlini/ Carlini-style adversarial prompts
carlini-curated/ Carlini v2 with targeted suppression
exploit-proof/ Language-agnostic concrete-exploit gate
exploit-proof-c-kernel/ Kernel / systems C
exploit-proof-c-userland/ C/C++ userland, setuid, parsers
exploit-proof-rust/ Rust (unsafe, FFI, web frameworks)
exploit-proof-solidity/ Solidity / Vyper smart contracts
exploit-proof-web-go/ Go web services
exploit-proof-web-java/ JVM web applications
exploit-proof-web-js/ JS/TS backends and frontends
exploit-proof-web-python/ Python web applications
nano-analyzer/ Terse attacker-first voice (nano-analyzer port)
testdata/fixtures/ LLM response fixtures for contract tests
| Code | Meaning |
|---|---|
| 0 | Analysis completed, possibly with audit warnings (no findings above threshold) |
| 1 | Error (analysis/pipeline failure, cancellation, or SARIF invocation failure) |
| 2 | Findings exceed --fail-on-severity threshold |
Analysis failures still write partial SARIF when possible and return exit code 1.
Check runs[0].invocations[0].executionSuccessful and
toolExecutionNotifications for failure details.
Audit is best effort. If any audit batch remains unavailable, completed audit
verdicts are preserved and the remaining findings are retained with
properties.auditStatus: "not_audited" and auditReasons: ["missing_verdict"]. The run
contains a warning notification and its audit phase metadata has status
incomplete. This does not fail CI, even when all audit batches are unavailable.
It does not turn an analysis failure or cancellation into a successful scan.
The --fail-on-severity threshold still applies to retained findings.
HTTP requests use three retries by default for network/read failures, request
timeouts, and HTML 403 responses from intermediaries. HTTP 408/429 and all 5xx
responses raise the retry limit to at least eight: 121 seconds of exponential
backoff plus up to 25% jitter. Retry-After takes precedence over those delays;
this is not a wall-clock deadline. JSON/plain-text permission errors and HTTP 401 fail
immediately. Cancellation stops retries. Audit additionally retries malformed,
truncated, or incomplete verdict output once after attempting local JSON repair.
Valid verdicts are retained, and only unassessed claims are retried. Both audit
contracts match by finding_id, so a refined title or location cannot invalidate
another finding's verdict. Older responses without IDs can match only an exact,
unique original title/file/line key. Primary source and retrieved excerpts use
the same original line numbering.
Both generations count toward reported token usage and cost. Transport retry
exhaustion does not start a second audit-level HTTP retry cycle.
Each result is a self-contained finding with its own rule, whose ID is
codecrucible. plus the finding ID. GitHub renders result messages as plain
text and only rule.help as Markdown, so the writeup lives on the rule:
rule.fullDescription is the finding's summary, and rule.help adds its audit
status, remediation, and technical details (escaped, collapsed in Markdown).
result.message.text is a one-line annotation: the summary's first sentence and
the audit status. The rule's security-severity and CWE tag are the finding's
own. Rule IDs exclude model wording, so a reworded title keeps its alert.
Per-finding state lives in result.properties:
| Property | Meaning |
|---|---|
findingId |
Stable ID (CC- + 16 hex). Also in partialFingerprints["codecrucibleFinding/v1"] |
verified |
true only when the audit confirmed, refined, or escalated the finding and did not suppress it |
auditStatus |
confirmed, refined, escalated, unverified, rejected, duplicate (v2), superseded (v3: suppressed because its independently audited children cover all of its material), new (added by a legacy audit that allows additions; see allow_new_findings), or not_audited |
auditConfidence |
Audit confidence, 0–1 |
auditJustification, auditBlockingCode |
The auditor's reasoning and, for rejections, the quoted blocking source |
auditReasons |
Machine-readable qualifiers: missing_verdict, audit_skipped, ungrounded_rejection, below_confidence_threshold; v2 adds refuted:<question>, unknown:<question>, ungrounded_refutation:<question>, unverified_evidence:<question>, and duplicate; v3 adds invalid_claim_assessment, refuted:<question>, unknown:<question>, insufficient_evidence:<question>, incomplete_claim_coverage, and independent_subclaims |
auditAnswers |
v2: each audit question's status (established, refuted, unknown), reason, and the evidence quotes that matched the source |
auditCrux |
v2 and v3: for an unverified finding, the code or fact that would decide it |
duplicateOf |
v2: the finding ID this one duplicates (same root cause and fix) |
deploymentExposure |
v2: default_on, config_enabled, config_dependent, not_deployed, or unknown, with detail and evidence. Informational; never changes the verdict |
severity, cwe |
This finding's own severity (0–10) and CWE, including audit refinements |
summary, remediation, technicalDetails |
Reviewer summary, fix, and full evidence |
reportedPath |
The model's file path, when it named no scanned file and was repaired to the one scanned file it uniquely matches (for example a dropped app/ prefix) |
reportedLocations |
A location the model reported whose region was invalid for the scanned file, kept here as reported. A valid start line keeps its region in locations, with the end clamped to the start (reversed range) or to the file's last line; an invalid start line removes the region |
locationWarnings |
One entry per reportedLocations entry: clamped_source_region when the region was clamped, invalid_source_region when it was removed |
initialEvidence |
v3: the discovery model's finding_evidence references (kind plus file, line range and quote) for this claim |
auditIntegrity |
v3: the policy outcome — status, reasons, per-question assertions, crux, and the policy version |
parentFindingId |
v3: the finding this child claim was split from |
childFindingIds |
v3: the independently audited child claims split from this finding |
claimCoverage |
v3: for a child claim, the parent material it covers (material_id and quote) |
semanticDuplicates |
v3 with --semantic-dedup report: IDs of findings judged same_cause_same_fix with verified cause and fix evidence. Neither finding is hidden |
provenance |
Links to the lineage ledger: runId, the observationIds this result derives from, and its current revisionId |
The finding ID hashes the CWE (or rule ID), file path, and whitespace-normalized flagged source. It excludes model wording and line numbers, so rescans of unchanged code and unrelated edits that shift lines keep the same ID. IDs are assigned before the audit, so an audit-refined CWE does not change them.
Audit rejections and findings below --audit-confidence-threshold are retained
as suppressed results (suppressions[].kind: "external", status: "accepted",
with the audit justification) and auditStatus: "rejected". They do not count
toward --fail-on-severity. Consumers that ignore SARIF suppressions will
display them; filter on suppressions or properties.auditStatus.
A prompt set opts into the v2 audit contract with contract: v2 in
audit.yaml. No bundled prompt set currently selects v2; prompts/core
uses v3. For each finding, the auditor answers three questions with quoted
source evidence. attacker_control asks whether attacker input reaches the
flagged code. privilege_boundary asks whether the finding grants more than the
attacker already holds. unmitigated asks whether the path lacks a guard. The
verdict is computed from the answers. A question refuted by a quote that matches
the source, within two lines of the cited line, rejects the finding. If all
three are established, the finding is confirmed. Anything else leaves it
unverified. A refutation without a matching quote counts as unknown, so missing
evidence never rejects. A v2 audit has no confidence, so
--audit-confidence-threshold does not apply. Findings are matched by
findingId, and claims the response omits are retried once.
The opt-in prompts/core set uses contract: v3. V3 binds each assessment to
an immutable claim revision and digest. It asks separately about attacker
control, the source weakness, the security boundary, the missing control, and
the claimed impact. Established and refuted answers require source evidence.
Attacker-control and boundary evidence must quote the answer's subject, and
refuting either also requires evidence at the claim's own location, code path,
or initial evidence, so an unrelated quote elsewhere cannot reject a claim. An
established upstream source in another file can still confirm one. An answer
downgraded for missing evidence reports insufficient_evidence:<question> (why
it was downgraded) and, when the claim stays unverified, also
unknown:<question> (the question's resulting state).
Consumer and guard expressions must occur in their respective quotes; renamed
values require explicit, quoted flow steps. A missing guard is represented by
guard_state: not_found with source evidence for the actual protection point. These checks establish source
correspondence, not whole-program data flow. Unsupported impact stays unresolved.
Version-dependent framework assumptions require the runtime, version and cited
behavior. Explicit supplementary context can support an assumption, but cannot
become a source location.
V3 retries invalid claims individually and permits one bounded local-context
expansion. Its context artifacts record included ranges and omissions. A claim
left unverified may name the context that would decide it in context_requests:
at most eight entries, each an exact admitted file with either an unqualified
declaration name or an inclusive line range of at most 120 lines. Requests
resolve against the shared source index and are answered in that one retry
round only; requests in the retry are ignored. A declaration that is missing,
defined more than once in its file, or outside the scanned files, and an
out-of-bounds range, are not guessed: each is recorded as an omission
(symbol_not_found, ambiguous_symbol, outside_scope, invalid_range or
invalid_request, plus request_limit past eight) and reported to the model.
Requested source competes for the same token budget as other context, and one
that does not fit is recorded as budget_exhausted. The bundle artifact lists each
request with its status (included or the reason it was not). A declaration
longer than 120 lines is cut there and labelled as truncated. Requests only add
context to cite; they never read outside the scanned files or change a
verdict by themselves. Other contracts do not accept them. Grouped
claims can produce separately audited children with stable IDs and split_from
lineage. An unresolved remainder remains visible unless the child records retain
all original material. A validly rejected parent stays rejected even when it
proposes children; each valid child is still audited on its own evidence. A
rejected child that proposes a further valid subclaim stays visible as
unverified (the further subclaim is not audited itself).
--semantic-dedup report adds attributed duplicate relationships without
hiding findings; off disables those extra requests.
Suppression is deliberately unavailable until held-out duplicate-precision and
claim-preservation checks pass. Legacy and v2 prompt sets retain their contracts.
Use frozen analysis artifacts to compare audit implementations. The offline scorer accepts independently adjudicated labels:
codecrucible evaluate-audit results.sarif --labels labels.jsonThe label file contains cases and pairs arrays. A case identifies a
finding_id and labels weakness as valid, invalid, or unknown; optional
impact is supported, unsupported, or unknown. A child can instead be
selected by parent_id, file, line, and claim_contains. A pair contains
left, right, and a Boolean duplicate. The report counts labeled cases
with no matching result (missing) and the matched results' audit statuses. It
gives each rate with a 95% interval:
recall: valid cases whose result is present and unsuppressed, out of all valid cases. A valid case with no result counts inrecallMisses, not as a suppression.knownPositiveSuppressed: valid cases whose result is suppressed, out of all valid cases.invalidConfirmedandunsupportedImpactConfirmed: invalid cases, and unsupported-impact cases, whose result is still active (unsuppressed) with any audit status, includingunverified, out of all cases with that label. Despite the key names, these count active results, not only confirmed ones.duplicatePrecision: of the labeled pairs the audit reported as duplicates (throughduplicateOforsemanticDuplicates, in either direction), those labeledduplicate: true. Pairs whoseleftfinding has no result are skipped.
Each rate reports count, total, rate, lower95 and upper95. A rate with
total: 0 is undefined, not zero: its rate and bounds are reported as 0,
so check total before reading them.
The report also includes recorded audit-model usage. Keep tuning cases separate from held-out evaluation and record elapsed time alongside each replay.
All audit contracts carry more than the files the findings cite. Up to about 24K tokens of excerpts are retrieved per batch, with real line numbers, so the auditor can check what decides a claim:
- references to the flagged function, with route registrations first;
- local definitions of other names in the same statement as such a reference, such as middleware registered with the handler (up to eight per claim);
- templates the flagged code renders;
- functions or constructors receiving the flagged expression, and one further call using the corresponding parameter;
- definitions of the functions and types it uses.
Excerpts are taken round-robin across the batch's claims and never repeat a file the batch already includes. A legacy audit also shrinks the retrieval budget so the prompt fits the model's context limit after reserving output tokens. If the rendered excerpts still overshoot, retrieval is retried once with the overshoot removed; only if that also fails is the batch sent with an omission note in place of the retrieved excerpts. The claims' own files and the source ranges they cite are always sent.
When retrieval leaves out context that may decide a claim, the batch says so in plain text, so a guard that was not retrieved is not mistaken for a guard that does not exist:
Audit context omitted: ambiguous caller reference <name> in <file>: more than one local definition matches, and no import says which.Audit context omitted: unresolved or external caller reference <name> in <file>: no scanned file defines the name, or it is imported from a module that does not resolve to a scanned file, such as a package dependency. A qualified reference (authz.RequireAdmin) that does not resolve is noted only when the flagged function may be passed to it directly; for languages read lexically, which do not record call arguments, it is always noted.Audit context omitted: caller definition limit reached: more definitions were found than the per-claim limit.Audit context omitted: token budget exhausted: some excerpts did not fit the retrieval budget.Audit context omitted: retrieval budget exhausted: a legacy batch's rendered context could not be made to fit, and no excerpts were sent.
A v3 audit lists the caller notes among the Context omissions of its context
bundle, so they are recorded in the bundle artifact and its fingerprint. It
records budget shortfalls as budget_exhausted omissions instead of the two
budget notes.
When a legacy audit retries claims whose verdicts were missing or invalid, the
retry prompt ends with the reason (for example, which of original_issue,
file_path or start_line differed from the claim) and restates the pending
claims' identity fields. That text is passed as JSON data, capped in length, and
counted against the context budget.
Retrieval is deterministic. Language adapters supply syntax and name lookup; the shared engine controls traversal limits, ranking, excerpt coverage and the token budget. Go uses its standard parser. Kotlin has a dedicated syntax reader for ordinary functions, primary constructors, objects, named arguments and import aliases. Other languages retain lexical retrieval without parameter binding. Go parse failures also fall back to lexical retrieval.
Caller-definition retrieval has no language rules of its own. The source index
supplies statement boundaries, names, comment masking and import bindings:
each language's import syntax (ES modules and require, Python import and
from … import, Go and Kotlin imports) stays in its import parser, and a name
imported from a module that resolves outside the scanned files never matches a
local namesake. Non-relative JavaScript specifiers, including @/ and ~/
aliases and directory index files, match scanned files at complete path
segments only. Adding a language means teaching the source index, not the
audit.
Retrieval supplies context candidates, not vulnerability verdicts or proof of data flow. Ambiguous definitions and unsupported Kotlin dispatch remain unresolved; overload selection, extension dispatch, wildcard imports and implicit receivers are not inferred. Comments and string contents cannot establish a parameter binding. Supplying an excerpt does not mark the rest of its file as supplied, so a helper elsewhere in that file can still be retrieved.
Each v2 batch also lists the scan's other findings, so the auditor
doesn't repeat them as leads. Notes the auditor
makes about possible issues outside the findings are recorded as
execution.auditLeads in the run metadata, not as findings.
Older/custom prompts without a reviewer summary use the first narrative paragraph of the technical details, limited to 1000 characters.
Analysis and audit schemas request an ordered code_path of exact files,
line ranges, and step explanations. Valid paths become
codeFlows[].threadFlows[].locations[], which GitHub uses for expandable source
walkthroughs. Every step must refer to source present in the scan with a valid
range; an invalid step omits the whole path rather than inventing a connection.
Audit receives the path's source files and replaces the analysis path with its
reviewed path. Unverified findings have no final code flow. These fields describe
model-reported evidence, not a proven execution trace.
Every SARIF run includes properties.codecrucible with schemaVersion: 1:
| Field | Contents |
|---|---|
recipe |
Scanner version/commit, resolved phase configurations, scan controls, prompt identity, custom-requirement and supplementary-source fingerprints |
recipe.phases |
Analysis, feature detection, audit, and context compression: provider/model, sanitized base URL/endpoint, transport, model parameters, context/output limits, temperature settings, output mode, timeout, tokenizer, and pricing assumptions |
recipe.controls |
Scope filters, test/document inclusion, file-size limit, compression, concurrency, cost limit, severity gate, phase toggles, audit confidence/batch size, and context budget |
recipeFingerprint |
SHA-256 of the canonical JSON recipe (sorted object keys, preserved array order); excludes output paths, credentials, timestamps, and execution outcomes |
execution |
Artifact stage, phase statuses and actual phase configurations, fallbacks, per-phase model calls, the models used, detected features, token correction, chunk/recovery counts, source loading/compression outcomes, packed-context fingerprints/truncation, auditAdditionsDropped (audit additions excluded under allow_new_findings: false), and lineageIncomplete (set when any lineage event was not recorded) |
execution.sourceIndex |
Extractor version, fingerprints of admitted source bytes and the index, file/line counts, extraction modes, and import-resolution counts |
execution.sourceBundles |
Fingerprints of the source context assembled for feature detection, analysis chunks/recovery, and audit batches |
execution.sourceCoverage |
Admitted, planned, and successfully analyzed file counts; repeated files (including retries), and repo-relative lists of unplanned or unanalyzed files |
Phase configuration reflects inheritance and overrides after configuration
resolution. Model parameters are recorded separately from model-registry
defaults; they can override request-body fields. execution.phases.*.actual
identifies the configuration used when a phase ran, including fallback to the
analysis client. requestPolicy explains exceptions such as Claude CLI-managed
sampling and context compression's per-source output limits.
execution.phases.*.models tallies each phase's requests by the model ID sent,
which is the model-params.model override when one is set. For each ID it
records the IDs the provider reported serving the requests, call and failure
counts, token usage, and the cost estimated at the configured prices. It also
counts successful requests that were sent without a temperature or with
max_completion_tokens, including after the client drops a field the endpoint
rejected. execution.models lists the distinct models that served the scan:
the provider-reported IDs, or the sent ID when a provider reports none. Calls
count client requests, not the client's internal retries. Provider-side
defaults are not recorded.
Analysis, audit, and final files have independent execution snapshots and the
same recipe fingerprint. pending means a phase had not run at that snapshot;
skipped, completed, incomplete, and failed describe its outcome. Empty scans include
metadata too, but do not fetch supplementary sources; prompt fingerprints are
included when local templates are available. Failed or empty context sources
have no content fingerprint, and a skipped audit has no audit artifact.
API keys, tokens, header values, raw arguments, and environment variables are
excluded from metadata. URLs omit credentials, queries, and fragments. Known
numeric/boolean tuning parameters and supported enumerations are readable;
other parameter values use { "omitted": true, "fingerprint": "sha256:…" }.
Credential-named parameter fields are excluded entirely. Prompt templates,
custom requirements, and loaded context are fingerprinted, not embedded;
context locations and absolute prompt-directory paths are omitted. Treat the
SARIF file itself as source-derived data: finding messages and snippets still
contain evidence from the scanned repository.
Compare the saved SARIF artifacts directly; GitHub does not expose arbitrary custom SARIF properties in its alert interface:
# Inspect configuration and execution outcomes.
jq '.runs[0].properties.codecrucible' results.sarif
# Show the models each phase used.
jq '.runs[0].properties.codecrucible.execution | {models, phases: (.phases | map_values(.models))}' results.sarif
# Compare recipes, excluding differences caused only by run outcomes.
jq -S '.runs[0].properties.codecrucible.recipe' before.sarif > before.recipe.json
jq -S '.runs[0].properties.codecrucible.recipe' after.sarif > after.recipe.json
diff -u before.recipe.json after.recipe.jsonMatching recipe fingerprints identify matching recorded settings and reference
inputs, not identical source revisions or guaranteed identical model responses.
Compare execution.sourceIndex.sourceFingerprint for matching admitted source,
the index version/fingerprint for matching extraction, and source-bundle
fingerprints for matching assembled context. These hashes do not archive the
source or guarantee identical model responses. Compare execution outcomes too,
particularly coverage gaps, partial failures, and fallbacks.
# GitHub Actions example
- name: Security scan
run: |
./codecrucible scan . \
--output results.sarif \
--fail-on-severity 7.0
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif# List available models for a provider (alias: list-endpoints).
# Provider auto-detected from env; override with --provider.
./codecrucible list-models
./codecrucible list-models --provider anthropic
./codecrucible list-models --provider openai-compat --base-url http://localhost:8000
# Write a commented .codecrucible.yaml to the current directory (or given path).
# A worked example, not a schema dump — shows the per-phase override shape.
./codecrucible init
./codecrucible init --force path/to/config.yamlmake build # Build binary
make test # Run tests with race detector
make lint # golangci-lint (or go vet fallback)
make coverage # Coverage report
make fmt # Format all Go files
make vet # go vetSee LICENSE for the full license text.