Aider-AI/aider · error · ValueError

No filename provided before {self.fence[0]} in file listing

Error message

No filename provided before {self.fence[0]} in file listing

What it means

WholefileCoder error while splitting a model reply into files: a fenced code block was encountered but no filename could be determined for it. The coder tries the last seen filename, then a single-file fallback (chat_files having exactly one entry); with neither available it raises.

Source

Thrown at aider/coders/wholefile_coder.py:82

                    # Issue #1232
                    if len(fname) > 250:
                        fname = ""

                    # Did gpt prepend a bogus dir? It especially likes to
                    # include the path/to prefix from the one-shot example in
                    # the prompt.
                    if fname and fname not in chat_files and Path(fname).name in chat_files:
                        fname = Path(fname).name
                if not fname:  # blank line? or ``` was on first line i==0
                    if saw_fname:
                        fname = saw_fname
                        fname_source = "saw"
                    elif len(chat_files) == 1:
                        fname = chat_files[0]
                        fname_source = "chat"
                    else:
                        # TODO: sense which file it is by diff size
                        raise ValueError(
                            f"No filename provided before {self.fence[0]} in file listing"
                        )

            elif fname is not None:
                new_lines.append(line)
            else:
                for word in line.strip().split():
                    word = word.rstrip(".:,;!")
                    for chat_file in chat_files:
                        quoted_chat_file = f"`{chat_file}`"
                        if word == quoted_chat_file:
                            saw_fname = chat_file

                output.append(line)

        if mode == "diff":
            if fname is not None:
                # ending an existing block

View on GitHub (pinned to 5dc9490bb3)

Solutions

  1. Add exactly one file to chat so the single-file fallback applies, or mention the target filename in backticks (e.g. `foo.py`) before the fence
  2. Switch the edit format (e.g. diff/udiff or patch format) where filenames are explicit per hunk
  3. Prompt the model to label every code block with its filename

Example fix

# before (model reply)
Here is the code:
```python
def f(): ...
```

# after
Here is `foo.py`:
```python
def f(): ...
```
Defensive patterns

Strategy: validation

Validate before calling

def fence_has_filename(reply: str, chat_files: list[str]) -> bool:
    fence = reply.split("```")
    # odd indices are inside fences; check text before each opening fence
    for i in range(1, len(fence), 2):
        preceding = fence[i - 1]
        mentioned = any(f in preceding for f in chat_files)
        if not mentioned and len(chat_files) != 1:
            return False
    return True

Try / catch

try:
    edited = coder.get_edits(reply)
except ValueError as e:
    if "No filename provided before" in str(e):
        reply = f"`{chat_files[0]}`\n" + reply if len(chat_files) == 1 else reply
        edited = coder.get_edits(reply)
    else:
        raise

Prevention

When it happens

Trigger: Model returns a bare ``` fence with no preceding filename mention while zero or 2+ files are in chat; the filename word appears after the fence instead of before; filename formatting differs from the backtick-quoted chat-file matching.

Common situations: Using wholefile coder with an empty chat and asking for new-file output; model says 'I'll write the code:' followed by an anonymous fence; filename mentioned in prose without backticks so saw_fname never gets set.

Related errors


AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15). Data as JSON: /api/errors/182382ffad92f38c. Report an issue: GitHub.