AI tool · Code
Code explainer
Paste code in any language and get it explained in plain English, with what it returns on an example and the bugs and edge cases in it, on any of 27 models. We checked every model's explanations against the code's real output.
Runs on Plus and Pro, on the model you pick
By running it, you agree to the Terms and Privacy Policy and confirm you’re 18 or older. We keep what you send and its answer for 7 days, or in your account if you sign up.
Test runs checked .
Code explainer: three examples
Three inputs and the explanation GPT-6 Luna gave each, made once on September 29, 2026 and shown as it came back. The example buttons in the box above show the same.
const isEmail = (s) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s);
This is a one-line JavaScript function that checks whether a value matches a simple email-shaped pattern. It returns `true` or `false`; it does not print anything.
It runs a regular-expression test on `s`. The pattern requires:
- at least one character other than whitespace or `@` before an `@`;
- at least one character other than whitespace or `@` between the `@` and a dot;
- at least one character other than whitespace or `@` after the dot.
For example, `isEmail("alex@example.com")` returns `true`. `isEmail("alex@example")` returns `false` because there is no dot after the `@`.
This is only a rough format check, not full email validation. For example, `isEmail("a@b.c")` returns `true`, even though many systems would reject such a short domain. It also accepts some questionable addresses, such as `isEmail("a..b@example.com")`, which returns `true`.
A notable edge case: passing a non-string can behave unexpectedly. For example, `isEmail(null)` throws a `TypeError` because the regular expression’s `.test()` method tries to convert `null` to a string, actually yielding `"null"`—so this call returns `false`, not an error. More generally, `.test()` coerces many non-string values to strings: `isEmail(123)` returns `false`, while an object with a custom string conversion could match.SELECT c.name, SUM(o.total) AS spent FROM customers c LEFT JOIN orders o ON o.customer_id = c.id GROUP BY c.name ORDER BY spent DESC LIMIT 5;
This is a SQL query. It lists up to five customer names with the sum of their order totals, sorted from highest spending to lowest. It runs in this order: 1. `FROM customers c` starts with the `customers` table, using `c` as a short alias. 2. `LEFT JOIN orders o ON o.customer_id = c.id` attaches matching orders to each customer. Because it is a left join, customers without orders are still included. 3. `GROUP BY c.name` combines rows by customer name so the query can calculate one total per name. 4. `SUM(o.total) AS spent` adds each group’s order totals and names the result `spent`. 5. `ORDER BY spent DESC` sorts the results by spending, greatest first. 6. `LIMIT 5` keeps only the first five rows. For example, if Alice’s orders total 30 and 20, Bob’s total 40, and Cara has no orders, the query returns rows like: ```text Alice | 50 Bob | 40 Cara | NULL ``` That example has fewer than five rows, so all are shown. SQL `SUM` ignores `NULL` values; for a customer with no matching orders, the sum is `NULL`, not zero. Potential surprises and bugs: - **Customers with the same name are combined.** If two different customers are both named “Alex,” `GROUP BY c.name` merges their orders into one total. This happens whenever `customers` contains duplicate names. Grouping by the customer’s unique ID as well as the name would keep them separate. - **Customers with no orders get `NULL` for `spent`.** This happens when a customer has no matching rows in `orders`; use `COALESCE(SUM(o.total), 0)` if they should show as zero. - **Ties can make the top five unpredictable.** If customers tie at the fifth position, the query has no secondary sort rule, so which tied customer appears can vary. - **A `NULL` customer name forms a group too.** Any customer whose `name` is `NULL` is grouped together with other customers whose name is `NULL`.
def chunks(items, n): return [items[i:i + n] for i in range(0, len(items), n)]
This is Python code that divides a list-like value into smaller pieces, each containing up to `n` items. It returns those pieces as a new list. The function `chunks` takes two inputs: `items`, the collection to split, and `n`, the size of each piece. It uses a *slice*—a way to take part of a sequence—to collect items from position `i` up to, but not including, position `i + n`. The `range(...)` supplies the starting positions, moving forward by `n` each time. For example, `chunks([1, 2, 3, 4, 5], 2)` returns `[[1, 2], [3, 4], [5]]`. The last piece can be shorter than `n`. Surprising behavior and edge cases: - If `items` is empty, as in `chunks([], 2)`, the result is `[]`. - If `n` is larger than the number of items, as in `chunks([1, 2], 5)`, the result is `[[1, 2]]`. - If `n` is `0`, as in `chunks([1, 2], 0)`, Python raises a `ValueError` because `range` cannot use a step of zero. - If `n` is negative, as in `chunks([1, 2, 3], -1)`, the result is `[]`: the range starts at `0` and cannot move forward by a negative step toward its stop value. - `items` must support `len(...)` and slicing, as lists and strings do. For example, passing a generator raises a `TypeError` because generators do not support those operations.
Which AI model is best at this? We tested every one
Every one of the 27 models we ran passed all 5 of our Code explainer test inputs, so choose on speed and price: GLM 5.3 was quickest, at 3.8 s a run on average. Claude Haiku 5.5 (an everyday model on every plan) took 4.4 s.
Run on November 19, 2026: 5 inputs on 27 models, each with this tool's own instructions.
| Model | Passed | Hard ones | Messages used on Pro | Cost per run | Time per run |
|---|---|---|---|---|---|
| GPT-6 LunaOpenAI | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0001 | 14.6 s |
| GLM 5.3 FlashZ.ai | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0003 | 15.3 s |
| Claude Haiku 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0004 | 4.4 s |
| DeepSeek V4.1 FlashDeepSeek | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0020 | 5.0 s |
| GPT-6.1 TerraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0014 | 5.8 s |
| Gemini 3.8 FlashGoogle | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0015 | 7.7 s |
| Claude Haiku 4.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0022 | 3.8 s |
| GLM 5.3Z.ai | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0023 | 3.8 s |
| Mistral Large 4Mistral | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0045 | 26.1 s |
| DeepSeek V4 ProDeepSeek | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0068 | 14.1 s |
| Grok 4.7xAI | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0083 | 15.9 s |
| GPT-6 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0021 | 3.8 s |
| GPT-6.1 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0027 | 10.4 s |
| GPT-6.2 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0036 | 4.4 s |
| Gemini 4 HydrogenGoogle | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0059 | 8.6 s |
| Kimi K3.1 ProMoonshot | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0067 | 14.5 s |
| Kimi K3Moonshot | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0098 | 5.7 s |
| Claude Sonnet 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0100 | 7.1 s |
| Claude Sonnet 5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0103 | 10.3 s |
| Gemini 3.1 Pro (preview)Google | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0104 | 13.5 s |
| Gemini 4 ArgonGoogle | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0054 | 16.2 s |
| Gemini 4 CarbonGoogle | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0058 | 17.6 s |
| Claude Opus 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0316 | 13.9 s |
| GPT-6.2 AstraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0137 | 5.4 s |
| GPT-6 AstraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0140 | 6.0 s |
| Claude Fable 5.1Anthropic | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0497 | 12.0 s |
| Claude Fable 5.2Anthropic | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0515 | 12.2 s |
Side by side: what a mutable default prints
The same input on GPT-6 Luna and Claude Haiku 5.5, as each answered it, unedited.
Explain this code in plain English: what it does, what it returns on an example, and any bugs or surprising behaviour, with the input that triggers each.
---
What does this print, and why?
def add_tag(tag, tags=[]):
tags.append(tag)
return tags
print(add_tag("a"))
print(add_tag("b"))This is Python code that appends a tag to a list and returns that list. Because `tags=[]` is a mutable default argument, Python creates that list once when it defines the function and reuses it on calls that omit `tags`.
The first call, `add_tag("a")`, appends `"a"` to the shared list and returns `["a"]`, so it prints:
```text
['a']
```
The second call, `add_tag("b")`, appends `"b"` to the same list, which already contains `"a"`. It returns `["a", "b"]`, so it prints:
```text
['a', 'b']
```
The surprising behaviour is that the second result includes the tag from the first call. This happens whenever you call `add_tag` without supplying `tags`: the list is shared across those calls. If you pass in your own list, the function appends to and returns that list instead.This is Python code. It defines a function that adds a tag to a list and returns the list, then calls it twice.
**Walkthrough**
1. `def add_tag(tag, tags=[]):` defines a function with two parameters. `tags` has a default value, which is an empty list created once, when the function is defined.
2. `tags.append(tag)` adds the tag to that list.
3. `return tags` returns the list.
4. `print(add_tag("a"))` calls the function with `tag="a"`. `tags` is not passed, so the default list is used. The list becomes `["a"]`, which is printed.
5. `print(add_tag("b"))` calls the function again with `tag="b"`. Again the default list is used, and it still holds `"a"` from the first call. `"b"` is appended, giving `["a", "b"]`, which is printed.
**Output**
```
['a']
['a', 'b']
```
**The bug: a shared mutable default**
The default `[]` is evaluated once, when the function is defined, not each time it is called. Every call that omits `tags` shares that same list, so tags accumulate across calls. This is the surprise here. The second call does not start fresh, and it is the second call that prints `['a', 'b']`.
This happens whenever the caller omits the `tags` argument. Passing a list explicitly avoids it:
- `add_tag("a", [])` returns `['a']` every time, because each call gets its own new list.
**Fix**
Use `None` as the default and create the list inside the function:
```python
def add_tag(tag, tags=None):
if tags is None:
tags = []
tags.append(tag)
return tags
```
With this version, both `print` calls output `['a']` and `['b']`.
**Other edge cases**
- Any mutable default (lists, dicts, sets) has the same problem. Immutable defaults such as `0`, `""` or `()` are safe because they cannot be changed in place.
- The function also mutates the list it is given. If a caller passes in their own list, that list is changed, even though the function doesn't say so.How the inputs are scored
- Key facts: the answer must state each fact the input turns on (a number, a name, a date or a condition), as the input gives it, keep any format rule the input sets (one sentence, a word limit, a number of items, a length for each), and say nothing the input rules out (an ingredient, a claim it doesn't back); how it's worded isn't judged.
The inputs: a python loop that removes duplicates, a title-case function with a bug, a sql query with having, what a mutable default prints, and javascript's sort on numbers. Every model gets the tool's own instructions and up to Pro's reply limit. The method is the same as our other test runs.
How to use the Code explainer
Paste the code, and your question about it if you have one (“why does this return None?”). Up to 1,500 characters.
Pick how much you already know.
Press “Explain it”. It runs on your plan (Plus or Pro) on the model you pick, and the whole answer streams in.
Run the example it gives to check the explanation against the real output.
Tips for a better answer
Ask your real question
Ask the question you actually have (“why is the last item missing?”). A focused answer beats a tour of every line.
Include the error
Paste the error message or the wrong output with the code. The explanation starts from what went wrong.
Set the level
Pick Beginner to have every term defined, or Experienced to skip straight to the bugs and the odd parts.
Then fix or convert it
Follow up with “now fix it” or “convert it to Python” in the same chat. It keeps the explanation in view.
What a good explanation looks like
What it returns, on an example
A good explanation says what goes in and what comes out, with one concrete example, before it walks through the lines. If you still can't predict the output, it hasn't explained anything.
The edge cases, named
Ask what happens on an empty input, a negative number or a missing key. The explanation should say whether the code handles it or breaks.
The surprises, caught
Some code does something other than what it looks like: JavaScript's sort() compares numbers as text, a Python default list is shared between calls. An explainer that misses these hasn't read the code.
Check it by running it
When the explanation says what the code prints, run it and check. An explanation can sound certain and still get the output wrong; the results below show how often each model did.
What you need to run it, and what a run gives
Running it takes a plan, Plus or Pro. There's no free plan or trial: a plan is paid at checkout and renews every month until you cancel. Cancel in two clicks in Settings → Billing and you keep your plan to the end of the month you paid for. llmwise accounts are for people 18 and older.
Paste up to 20,000 characters in a run. It runs on the model you pick, shows the whole answer, and you can carry on in the chat with any model your plan has, or ask another model the same thing.
A run counts on your plan like any other message: the table above shows what one counted as on Pro, model by model.
More AI tools are on the tools page, and what each plan gives is on pricing.
Questions
Is the code explainer free?
No: there's no free plan or trial. It runs on Plus and Pro, on any model your plan has; Claude Fable 5.2, GPT-6.2 Astra, and their earlier versions need Pro. Paid monthly from the day you start. Cancel in two clicks in Settings → Billing.
Which languages can it explain?
Any common one: Python, JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, PHP, Ruby, SQL, shell scripts and regular expressions. It names the language it found.
Will it find bugs?
Yes: it says what looks wrong, which input breaks it, and how to fix it. It reads the code rather than running it, so run the case it names to confirm.
How do you know the explanations are right?
We ran five snippets on every model and checked each explanation for facts we'd established by running the code: what it prints, where it throws, and what it does. The results are below.
Can I paste a whole file?
Yes: paste up to 20,000 characters on any of 27 models and ask follow-ups in the same chat (“why that line?”, “rewrite it without the bug”). Don't paste keys, passwords or customer data into any AI tool.
Which AI is best for this, in your tests?
Every one of the 27 models we ran passed all 5 of our Code explainer test inputs, so choose on speed and price: GLM 5.3 was quickest, at 3.8 s a run on average. Claude Haiku 5.5 (an everyday model on every plan) took 4.4 s. The table on this page has every model's result, what a run counts as on Pro, and the time it took.
Claude, GPT, Gemini, DeepSeek, Grok, Kimi, GLM, and Mistral, in one chat.
See what a message costs before you send it. Every plan is month to month: cancel in two clicks. Sign in with an email link, no password.