To debug an error with an AI coding agent, give it three things: the exact error, where it happens, and the command that proves it is fixed. In Mel – the agentic terminal (openmel.dev), the fastest way is to run the failing command in the terminal, press Ctrl+↑ (⌃↑ on a Mac) to attach that command and its output, and say what "fixed" means, for example "make npm test pass". Mel's agent reads the code, reproduces the error, changes what it needs, and runs the check again before it reports back. Every edit and command that changes something waits for your approval unless your settings allow it.
This guide covers why agents get debugging wrong, a five-step method that works, how to do each step in Mel, and the mistakes that send an agent in circles.
Why do AI agents get debugging wrong?
An agent that guesses is worse than no agent. The three usual causes:
- No real error. "The login is broken" gives the agent nothing to reproduce. It guesses a cause and "fixes" code that was never wrong.
- No finish line. Without a command that proves the fix, the agent stops at the first change that looks plausible and says "done".
- Too much context. A 2,000-line log hides the three lines that matter, and the agent chases the wrong warning.
Each of these is fixed by what you put in the message, not by a better model.
There is a fourth cause that is easy to miss: the agent fixes the symptom. If a test fails because a function returns null, the quickest change that makes the test pass is to add a null check at the call site. The real bug may be three files away, in the code that should never have returned null. An agent is not lazy, but it is trying to reach the finish line you gave it. That is why step 4 below, "say what must not change", and step 5, "read the diff", matter as much as the first three.
A five-step method for debugging with an agent
| Step | What you do | Why it matters |
|---|---|---|
| 1. Reproduce | Run the failing command yourself | The agent sees the real error, not your summary of it |
| 2. Attach | Give the agent that one command and its output | Exact text, nothing extra |
| 3. Set the finish line | Name the command that must pass | The agent knows when to stop |
| 4. Set limits | Say what must not change | It fixes the bug, not the design |
| 5. Review | Read the diff, then run the check yourself | "Done" is a claim until you see it |
What to attach for each kind of error
Not every error looks like a failing test. What helps the agent most depends on the kind of problem.
| Kind of error | What to give the agent | Finish line to name |
|---|---|---|
| Build or compile error | The failing build command and its first error | The build command exits with 0 |
| Failing test | The test command, narrowed to the one test if you can | That test passes, nothing skipped |
| Crash with a stack trace | The trace, and the input or request that caused it | The same input no longer crashes, with a test that proves it |
| "It worked yesterday" | The last commit or version that worked | The check passes on the current code |
| Flaky test | How often it fails, and the command you ran in a loop | It passes many runs in a row |
| Works on one machine only | The versions on both machines (node -v, python --version) |
The check passes in a clean environment |
The common thread is the same: a real error you can reproduce, and a command that can say yes or no.
Read the stack trace top to bottom, once
Before you hand over a stack trace, read it yourself for ten seconds. The top line says what went wrong; the first frame in your own code says where. If you can tell the agent "it fails in parseConfig in src/config.ts", it starts in the right file instead of searching the project. You do not need to understand the bug to do this. You only need to point.
For "it worked yesterday", use git bisect
When you know a version that worked and one that does not, git bisect finds the commit that broke it by testing the halfway point again and again. With a test command that exits non-zero on failure, git bisect run <command> does the whole search by itself. You can ask the agent to run it: "use git bisect between v1.4 and HEAD with npm test -- login to find the commit that broke login, then explain what that commit changed". Knowing the guilty commit often turns a day of guessing into a ten-line fix.
How to do each step in Mel
1. Reproduce the error in the terminal
Run the command that fails, such as npm test, pytest -x or cargo build. A failed command gets a red ✗ badge and its whole block turns red, so you can find it again in a long session. See blocks.
2. Attach the failing block
Right after a failed command, the hint row under the prompt offers to attach it. You have three ways:
- Press Ctrl+↑ (⌃↑ on a Mac) at the prompt to attach the last command and its output.
- Right-click the block and choose Attach as agent context.
- Click the paper-clip icon in the block's header.
Attach the one block that fails, not a whole log. Everything you attach counts toward the model's context.
3. Say what "fixed" means
Press Ctrl+Enter (⌘↵ on a Mac) to hand the message to the agent, and write the task like a ticket:
The test above fails since this morning's merge.
Find the cause and fix it.
Done means `npm test` passes, with no test skipped or deleted.
Don't change the public API of src/auth.
If your project has an AGENTS.md that names its test command, Mel's agent reads it and uses that command to check its work. Starting a dev server or reading a file back does not count as a check. See how to write a good task.
4. Approve what it does
Mel's agent reads files and searches freely, because reading changes nothing. An edit shows an approval card with the exact diff it will write, and a command that changes something shows the exact command. You allow it once, allow that kind of step for the rest of the conversation, or deny it, and the agent changes course. See tools and approvals.
Some steps always wait for you, whatever your settings: a command Mel recognises as impossible to undo (such as git push --force, git reset --hard or sudo), reading a file that holds credentials, writing outside the project, and any connector call.
5. Review the fix
Every edit leaves a diff card in the conversation. Press Ctrl+Shift+= (⌘⇧= on a Mac) to open the code review panel and read the whole change. Hover a line and click 💬 to leave a comment, then send your comments back to the agent to fix. When it is right, Approve and Commit.
When the error only shows up while something is running
Some bugs only appear while a server is up: a request that returns 500, a page that throws in the browser console. Mel's agent can start a command in the background and keep working while it runs, so it can start the dev server, send the failing request, and read the server's output, all in one turn. Each background job is listed above the input with its own Stop button, and stopping the turn does not kill the server unless you stop the job.
An example session
Here is what a short, well-set-up debugging session looks like, from start to finish.
- You run
pytest -xand it stops ontest_invoice_totalwithAssertionError: 107.0 != 107.1. - You press Ctrl+↑ to attach that block, and write: "This started after the currency change. Find the cause. Done means
pytestpasses with no test changed." - The agent reads the test and the invoice code, and sees that totals are summed as floating-point numbers and rounded in the wrong place.
- It proposes an edit to round once at the end using the decimal type. The approval card shows the diff, and you allow it.
- It runs
pytest, sees one more failure in a related test, fixes that too, and runs the whole suite again. Both runs are in the conversation. - You open the code review panel, read the two-file change, run
pytestyourself once, and commit.
The agent did the searching and the typing. You gave it a real error and a clear finish line, and you read the result.
What if the agent goes in circles?
Mel stops some loops by itself. Running the same command a third time with nothing changed in between is stopped, and a task that stops making progress ends with a report of what was done and what is left. When that happens:
-
Narrow the task. "Find which commit broke
test_login" before "fix it". - Add one fact. The last version that worked, or the input that fails.
- Try another model. Mel works with Claude, GPT, Gemini, DeepSeek, Qwen and more, so a second opinion is one click in the model menu. See which AI models you can use in Mel.
- Stop it. The stop button ends the turn at once. Background jobs keep running, each with its own Stop.
Debugging by hand versus with an agent
| By hand | With an agent | |
|---|---|---|
| Reproducing | You run the command | You run it once, then attach it |
| Searching the code | You grep and open files | The agent reads and searches freely |
| Trying a fix | You edit, run, repeat | It edits and reruns, under your approvals |
| Knowing when to stop | You decide | The finish line you named decides |
| Judging the fix | You | Still you, in the diff |
The last row does not change. An agent saves you the searching and the retries. It does not take over the judgment of whether the fix is right.
Mistakes that waste a debugging session
- Describing the error instead of attaching it. The exact text matters.
- "Fix the tests" as the whole task. An agent may make tests pass by deleting them. Say "no test skipped or deleted".
- Pasting a huge log. Attach the one failing block.
- Approving without reading. The card shows the exact diff. Read it.
- Trusting "done". Run the check yourself once at the end.
Frequently asked questions
How do I give an AI agent the error from my terminal? In Mel, press Ctrl+↑ (⌃↑ on a Mac) at the prompt to attach the last command and its output, or right-click the block and choose Attach as agent context.
Can the agent run the tests itself? Yes. Mel's agent runs commands in your project, reads the output, and runs the check again after it changes something. A command that changes something waits for your approval unless your settings allow it.
Will the agent delete my files while debugging? Not without asking. Edits and commands that change something stop at an approval card unless you allow them, and steps Mel recognises as impossible to undo always wait for you.
What if the fix is wrong? Undo it in the code review panel: Undo takes back one change, and ↩ Discard reverts one file. See how to undo what an AI coding agent changed.
Does this work with Claude Code or Codex? Yes. You can run claude or codex in a Mel tab and give them the same kind of task. They run on your own Anthropic or OpenAI account. See running Claude Code and Codex together.
Can the agent find which commit introduced a bug? Yes, if you give it a good and a bad version and a test command. Ask it to use git bisect run, and it will narrow the search to one commit.
Can the agent debug a running server? Yes. It can start the server as a background job, send the failing request and read the output, while the job stays listed above the input with its own Stop.
Is Mel free for debugging? The terminal is free, and Mel's agent is free with your own API key. Paid plans start at $20 a month. See pricing.
Try it
Download Mel, run the command that has been failing all week, press Ctrl+↑ and write one line: what done looks like. For more on writing tasks, read how to write a task an agent can finish.
Originally published at openmel.dev.
Top comments (0)