Context
When chatting with the AI assistant, you can specify content within Trae—such as code, files, folders, and the workspace—as context for the AI assistant to read and understand. This ensures that the AI assistant's responses align more closely with your needs. Here are three ways to specify context.
Reference the content in the editor as context
When there is a file opened in the editor, the AI assistant can automatically see the content of that file, and you can directly ask questions related to it. If you want to ask about a specific section of code within that file, follow these steps:
- Select some code.
- Click the Add to Chat button in the floating menu to add the selected code as context in the side chat box.
- The specified context will appear at the bottom of the side chat's input box. The input box displays the name of the file from which the selected code originates, along with the line numbers.
- (Optional) Continue to add other code from the same file in the editor or simultaneously add context from other sources.
Reference the content in the terminal as context
If you want to ask questions about the output in the terminal (for example, to help fix an error), follow these steps:
- In the terminal, click on an output segment.
- In the top right of the selected content area, click the Add to Chat button.
- This adds the selected output as context to the side chat box. The specified context will appear at the bottom of the side chat's input box, showing the source of the context along with line numbers.
- (Optional) Continue to add other content from the terminal or simultaneously add context from other sources.
Add context using the # symbol
In the input box of side chat, you can add various types of context, including code, files, folders, workspace, docs, and webs, by using the # symbol. Typically, the list will display recommended contexts related to the file currently opened in the editor, but you can still search for the needed context and add it to the input box. Based on your question, you can combine various sources of relevant context (for example, adding both code and a file at the same time).
Manage codebase indexing
Trae AI can build code index for the project. Once the index is built, when users chat with the AI assistant using #Workspace or #Folder, the AI assistant can understand the currently opened project and use the entire project as context to provide more accurate responses.
Ignore files
Trae IDE ignores files listed in the .gitignore file by default. You can also set up an additional list of files to ignore when indexing the repository, which serves as a supplement to the rules defined in the .gitignore file.