# How Lyna finds the right code

How Lyna AI knows your project. A map of your pages and files in every message, a search by name and by meaning, an index that keeps itself up to date, and memory.

Lyna AI does not guess where your code is. Every message it gets comes with a map of your project, the pieces of code that match your question, and what it remembers about your project. This page explains each part, so you know what Lyna sees and how to help it.

Under a reply, the code card open on the snippets Lyna used, each with its file, folder and lines.

## What you can do

- Ask about a page, a component or a behavior in your own words, in any language, and let Lyna find the code.
- See which pieces of code Lyna used for a reply, and open each one in the code panel.
- Know when Lyna may have missed your latest edit, and what to do about it.
- Count on Lyna to keep your secrets out of what it reads.

## Three sources for every answer

Each message you send reaches Lyna with three kinds of context. They are gathered at the same time, before Lyna starts to answer.

```mermaid
flowchart LR
    Q["Your message"] --> M["Project map: pages, files and what they define"]
    Q --> S["Code search: by name and by meaning"]
    Q --> R["Memory: decisions and preferences"]
    M --> A["One answer"]
    S --> A
    R --> A
```

If one source is not available, Lyna answers with the others. A missing source never stops a reply.

## A map of your project in every message

Every message carries a short map of your project:

1. Your pages first, each with its address and the file that draws it.
2. Then your other files, grouped by folder.
3. For each file, the components, functions and types it defines, with the line where each starts.

The map holds names and places, never the content of your files. With it, Lyna can name the right file at once, without searching first.

In a large project, the map keeps all your pages first, then your components, hooks and helpers, then the rest. When some files do not fit, the map says how many are left out, so Lyna knows to search for them.

> [!TIP]
>
> **Lyna reads before it edits**
>
> The map can trail your very last change by a moment. That is why Lyna always opens a file and reads it before it changes it.

## Search by name and by meaning

For each message, Lyna searches your code in two ways at once:

- **By name.** The exact words of your question: a component name, a page address, a function, a phrase in your copy. Names written together are understood in parts, so `useOrders` also matches "use orders".
- **By meaning.** Your question in your own words, such as "where do we check the cart before payment". This search works in any language, even when your code never uses those words.

The two results are merged. A piece of code that matches your exact name comes first, so the line that defines it is the first thing Lyna sees. Each piece also carries its file path and name, so a question about a page or a component finds its code even when the code itself never spells it.

The best few pieces are added to your message. Under the reply, the code card lists them: the file, its folder and the lines. Select a row to open that file in the code panel. While it works, Lyna can also search your code again on its own.

Some files are never searched, because they are noise for a question: lockfiles, generated files (such as the route list your project builds by itself), minified files, source maps and very large data files.

## The index refreshes on its own

To search by meaning, Lyna keeps an index of your code. You never have to rebuild it:

- When you save a file, the files that changed are read again in the background. Files that did not change are skipped.
- When Lyna writes files during a reply, those files are indexed too, without waiting for a save.
- When Lyna improves the way it reads code, your project is read again on its own, the next time you save or send a message.

Your message never waits for the index. It is sent at once, with the code the index already has.

## What a stale index means

If you send a message right after a large edit, the index may still be catching up. The code card then shows **Index behind**. Its tooltip says that Lyna may have missed a recent change.

The code card under a reply with the Index behind badge and its tooltip.

You do not need to do anything: the index catches up in the background, and Lyna reads a file before it edits it. If your question is about a file you just changed, add it with `@` so Lyna reads it first. See [Mentions and context](/features/ai/mentions-and-context).

## Earlier conversation and memory

In a long conversation, Lyna also searches the earlier messages of that conversation for the parts that match your question. When a conversation gets too long, its older part is replaced by a summary. See [Chat history and context](/features/ai/chat-history-and-context).

Lyna also remembers the decisions and preferences you state, per project. The memories that match your message are added to it, and the memory card under the reply names them. See [Knowledge and memory](/features/ai/knowledge-and-memory).

## What Lyna never reads

Your secrets stay out of what Lyna reads and shows:

- **Environment files** (`.env` and the like) are left out of the map and the search. Lyna cannot open them from the terminal. It changes them only through your project's environment variables, which hide secret values. Example files, such as `.env.example`, stay open.
- **A key or token you paste in a message** is hidden before Lyna AI reads it. The chat tells you, and the saved conversation keeps only the hidden version.
- **A secret written in code** during a reply is flagged: the chat names the problem and asks you to move it out of the code before you publish.

To give your app a secret, add it as an environment variable. See [Environment variables](/features/code/environment-variables).

> [!NOTE]
>
> **Teammates and memory**
>
> In a shared project, what Lyna remembers about you stays yours. Teammates never see your memories.

## Related

- [Mentions and context](/features/ai/mentions-and-context): Point Lyna at the right files.
- [Knowledge and memory](/features/ai/knowledge-and-memory): What Lyna remembers, and how to change it.
- [Chat history and context](/features/ai/chat-history-and-context): Past conversations, the context meter and compaction.
- [Environment variables](/features/code/environment-variables): Keep secrets out of your code.
