Back to Kilocode

Context & Mentions

packages/kilo-docs/pages/code-with-ai/agents/context-mentions.md

7.4.166.5 KB
Original Source

Context Mentions

Providing the right context helps Kilo Code understand your project and perform tasks accurately. All platforms support @-mentions for referencing files, and the agent can also discover context on its own using built-in tools like read, grep, and glob.

{% tabs %} {% tab label="VSCode" %}

The extension supports @-mention autocomplete for file paths and also uses a tool-based context model where the agent can automatically discover and read files using built-in tools.

How Context Works

When you describe a task, the agent uses its tools — read, grep, glob, and others — to find and read relevant files on its own. You don't need to explicitly point it at files in most cases; just describe what you want done and the agent will locate the right code.

@-Mention Autocomplete

Type @ in the chat input to get autocomplete suggestions. You can mention:

MentionDescriptionExample
FileAttach a file's contents to your message@src/utils.ts
TerminalInclude your active VS Code terminal output@terminal
Git ChangesAttach uncommitted working-tree diffs and new files@git-changes

Selecting a suggestion inserts the mention and highlights it in the input. File contents, terminal output, and git changes are attached as context when you send the message.

Drag and Drop

You can also add file mentions by dragging and dropping:

SourceHowResult
Explorer / Editor tabsDrag a file or folder from VS Code's Explorer or an editor tab into the chat inputInserts an @/relative/path mention
Multiple filesDrag several files at onceInserts space-separated @ mentions
Agent Manager diff headersDrag a file header from the Agent Manager's diff panel into chatInserts an @file mention
ImagesHold Shift while dragging an image file from your OS file manager into the chat inputAttaches the image

{% callout type="info" %} VS Code requires holding Shift when dragging files from outside the editor (e.g. Finder or Windows Explorer) into a webview. This applies to image drops — file drops from within VS Code (Explorer, editor tabs) work without Shift. {% /callout %}

Automatic Editor Context

The extension automatically includes context from your editor with each message — your currently focused file and all open editor tabs. You don't need to mention these explicitly.

Selected code and editor diagnostics (errors/warnings) are not included automatically. However, you can send these to Kilo Code through VS Code's Code Actions: select code or hover over an error, then use the lightbulb menu to find context-dependent actions like "Explain with Kilo Code" or "Fix with Kilo Code."

Tool-Based File Access

Rather than attaching file contents up front, the agent reads files on demand during its work:

ToolPurposeExample
readRead the contents of a specific fileAgent reads src/utils.ts to understand it
globFind files matching a patternAgent searches for **/*.test.ts
grepSearch file contents for a patternAgent searches for function handleError
bashRun shell commands including git operationsAgent runs git diff or git log

This means the agent can explore your entire project as needed, rather than being limited to files you explicitly mention.

Best Practices

PracticeDescription
Describe the task clearlyThe agent finds context on its own — focus on what you want done rather than where the code is
Mention files when helpfulIf you know the exact file, mention its path to save the agent a search step
Keep editor tabs relevantOpen tabs are passed as context, so keep relevant files open
Trust the agent's toolsThe agent can search, read, and explore your codebase — let it do the discovery work

{% /tab %} {% tab label="CLI" %}

The CLI uses a tool-based context model. The agent automatically discovers and reads the context it needs using built-in tools. In the TUI, you can type @ to get file autocomplete suggestions for quick file references.

How Context Works

When you describe a task, the agent uses its tools — read, grep, glob, and others — to find and read relevant files on its own. You don't need to explicitly point it at files in most cases; just describe what you want done and the agent will locate the right code.

Providing File Context

In the terminal-based TUI, you can provide context in several ways:

  • Type @ for file autocomplete — In the TUI, type @ followed by a filename to get autocomplete suggestions. Selecting a file attaches its contents to your message. You can limit how much is included by appending a line range, e.g. @src/utils.ts#10-50.
  • Mention file paths in your message — Simply refer to files by path in your conversation text (e.g., "look at src/utils.ts") and the agent will read them.
  • Use kilo run -f — When using the non-interactive kilo run command, pass -f path/to/file.ts to explicitly include a file's contents in the context.
  • Let the agent find files itself — The agent has access to glob (find files by pattern), grep (search file contents), and read (read file contents) tools. Describe what you're looking for and it will locate the relevant code.

Tool-Based File Access

Rather than attaching file contents up front, the agent reads files on demand during its work:

ToolPurposeExample
readRead the contents of a specific fileAgent reads src/utils.ts to understand it
globFind files matching a patternAgent searches for **/*.test.ts
grepSearch file contents for a patternAgent searches for function handleError
bashRun shell commands including git operationsAgent runs git diff or git log

This means the agent can explore your entire project as needed, rather than being limited to files you explicitly mention.

Best Practices

PracticeDescription
Describe the task clearlyThe agent finds context on its own — focus on what you want done rather than where the code is
Mention files when helpfulIf you know the exact file, mention its path to save the agent a search step
Use kilo run -fPass key files with -f when using kilo run for immediate context
Trust the agent's toolsThe agent can search, read, and explore your codebase — let it do the discovery work

{% /tab %} {% /tabs %}