# Code language detector

Detect the likely programming language of a pasted code snippet with ranked alternatives, confidence and explainable signals.

## Run it

- **CLI:** `gizza tool code-language-detect 'Paste code here, for example:
fn main() {
    let mut count = 0;
    println!("{count}");
}'`
- **Web:** https://gizza.ai/tools/code-language-detect/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/code-language-detect/tool.json

## Inputs

- `code` — Code snippet _(field)_
- `filename` — Filename hint _(field)_
- `candidates` — Candidate allowlist _(field)_
- `top_k` — Ranked candidates _(field)_
- `common_only` — Common languages only _(field)_
- `explain` — Show evidence _(field)_
- `output` — Output format _(field)_

## Output

- Result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `code` — Code snippet
- `filename` — Filename hint
- `candidates` — Candidate allowlist
- `top_k` — Ranked candidates
- `common_only` — Common languages only
- `explain` — Show evidence
- `output` — Output format

Example: `https://gizza.ai/tools/code-language-detect/?code=Paste%20code%20here%2C%20for%20example%3A%0Afn%20main%28%29%20%7B%0A%20%20%20%20let%20mut%20count%20%3D%200%3B%0A%20%20%20%20println%21%28%22%7Bcount%7D%22%29%3B%0A%7D&filename=main.rs&candidates=rust%2Cpython%2Cjavascript&top_k=3&common_only=true&explain=true&output=report`

---

## About this tool

Paste a code snippet to identify its likely programming language without uploading the text or
calling a model. The detector uses a deterministic, GitHub-Linguist-style score table: syntax
signals, imports, keywords, shebangs, structural checks, and optional filename hints add weighted
evidence for each language. The result includes a confidence level, ranked alternatives, and the
matched signals so you can see why a language won.

Worked example: paste this Rust snippet and set the filename hint to `main.rs`:

```rust
use std::collections::HashMap;

pub fn tally(words: &[&str]) -> HashMap<String, usize> {
    let mut counts = HashMap::new();
    for w in words {
        *counts.entry(w.to_string()).or_insert(0) += 1;
    }
    counts
}
```

The report should identify `rust`, show the filename and Rust-specific signals in the evidence,
and list the nearest alternatives. For a short one-liner such as `print("hello")`, use the candidate
allowlist (`python,javascript,ruby`) or a filename hint to make the ambiguity explicit.

Limits and edge cases: snippets are capped at 1 MiB, the detector is heuristic rather than a trained
model, and very short or deliberately polyglot snippets can be close calls. Syntax highlighting and
file upload are intentionally separate from this tool; this page focuses on local paste-in language
detection with explainable output.

## FAQ

<details>
<summary>How accurate is the detector?</summary>

It is strongest on snippets with several lines, imports, type declarations, markup structure, or a
filename hint. It is not an ML classifier, so it does not claim corpus-level accuracy; instead it
shows the signals that matched and warns when the top candidates are close.

</details>

<details>
<summary>Why does a one-line snippet get a low-confidence warning?</summary>

Many languages share tiny snippets. `print("hello")` could be Python, Ruby-like pseudocode, or a
function call in another language. Add more context, set `filename`, enable `common_only`, or provide
a `candidates` allowlist to make a short snippet less ambiguous.

</details>

<details>
<summary>What does the candidate allowlist accept?</summary>

Use comma-separated language ids such as `rust,python,javascript` or `json,yaml,toml`. Unknown ids
produce an error that lists the supported values, and the report notes when the language pool was
restricted.

</details>

<details>
<summary>Does this upload my code or use a network service?</summary>

No. The scoring runs in local WebAssembly in the browser and the CLI/chat block uses the same pure
Rust core. The pasted snippet is not sent to a remote detector.

</details>

## Related tools

- [Apply a Unified Diff to a File](https://gizza.ai/tools/apply-patch/): Paste a file and a unified diff to get the patched text in your browser, with reverse apply, fuzz matching, and per-hunk conflict reports.
- [Autocomplete Trie](https://gizza.ai/tools/autocomplete-trie/): Build a prefix trie from a pasted wordlist and get ranked autocomplete suggestions for any typed prefix. Weights, typo tolerance, trie stats, JSON. Runs locally.
- [Code Chunker](https://gizza.ai/tools/code-chunker/): Split Python, Rust, JavaScript, TypeScript, Go, Java, C/C++, C#, PHP, or Swift into line-ranged chunks that keep functions and classes intact.
- [Code Formatter](https://gizza.ai/tools/code-formatter/): Beautify and re-indent minified or messy HTML, CSS, JavaScript, or JSON. Auto-detect the language, choose spaces or tabs, and format locally in your browser.
- [Code metrics analyzer](https://gizza.ai/tools/code-metrics-analyzer/): Paste source code and get line counts, function counts, approximate cyclomatic complexity, maintainability, and risk bands. Runs locally in your browser.
