gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Bug: @-command fails to read directory contents or glob patterns due to incorrect tool usage

Open zhucj1981 opened this issue 7 months ago • 2 comments

What happened?

The @ command, which is intended to inject file or directory content into the prompt, fails silently when given a directory path (e.g., @mydir) or a glob pattern (e.g., '@mydir/*.ts'). The command appears to execute in the logs, but no file content is actually passed to the LLM. The only currently working method is to explicitly list every single file with its own @ prefix (e.g., @file1.txt @file2.txt).

What did you expect to happen?

预期行为 (Expected Behavior):

When a user provides a directory path like @test_dir or a glob pattern like '@test_dir/*.txt', the CLI should:

  1. Identify all files matching that path/pattern.
  2. Read the content of all identified files.
  3. Inject the content into the prompt sent to the LLM.

实际行为 (Actual Behavior):

The command fails silently. The file content is not injected into the prompt. The LLM only receives the text part of the user's query, leading to confused or irrelevant responses. This happens because of a logic error in how the path is processed and which tool is subsequently called.

Client information

│ About Gemini CLI │ │ │ │ CLI Version 0.1.12 │ │ Git Commit b29c02dd (local modifications) │ │ Model gemini-2.5-pro │ │ Sandbox no sandbox │ │ OS darwin │ │ Auth Method OAuth │

Login information

No response

Anything else we need to know?

根本原因分析 (Root Cause Analysis):

The bug is located in packages/cli/src/ui/hooks/atCommandProcessor.ts.

The current implementation correctly identifies when a path is a directory and correctly converts it into a glob pattern (e.g., test_dir becomes test_dir/**).

However, it then makes a critical mistake: it passes this glob pattern string directly to the read_many_files tool. The read_many_files tool is not designed to expand glob patterns; it expects a concrete list of file paths.

The correct implementation should be:

  1. Convert the directory path to a glob pattern.
  2. Call the glob tool with this pattern to get a list of concrete file paths.
  3. Pass the resulting list of concrete file paths to the read_many_files tool.

zhucj1981 avatar Jul 13 '25 09:07 zhucj1981

Hello! As part of our effort to keep our backlog manageable and focus on the most active issues, we are tidying up older reports.

It looks like this issue hasn't been active for a while, so we are closing it for now. However, if you are still experiencing this bug on the latest stable build, please feel free to comment on this issue or create a new one with updated details.

Thank you for your contribution!

gemini-cli[bot] avatar Dec 03 '25 21:12 gemini-cli[bot]

Found possible duplicate issues:

  • #3779

If you believe this is not a duplicate, please remove the status/possible-duplicate label.

gemini-cli[bot] avatar Dec 04 '25 19:12 gemini-cli[bot]