What is Context in Trae?
Context in Trae allows you to specify content like code, files, folders, and workspace information for the AI assistant to understand and reference. By providing relevant context, you can get more accurate and helpful responses. Here’s how to use context in Trae:
Method 1: Reference Editor Content
When you have a file open in the editor, the AI assistant automatically sees its content. To reference specific sections:
- Select the code you want to reference
- Click “Add to Chat” in the floating menu to add it as context
- The context will appear in the side chat input box, showing the file name and line numbers
- Optionally add more context from the same or other files
- Type your question and send it to the AI assistant
Method 2: Reference Terminal Output
To ask questions about terminal output (like error messages):
- Click the output section in the terminal
- Click “Add to Chat” in the top right of the selection
- The selected output appears as context in the side chat
- Optionally add more context from other sources
- Type your question and send it
Method 3: Add Context with # Symbol
Use the # symbol in the side chat to add different types of context:
#Code
- Add specific functions or classes as context
- Requires appropriate Language Server Protocol (LSP) installation
- Preview code before selecting
- Search by keywords if needed
#File
- Reference entire file contents
- Shows recently opened files by default
- Preview file paths
- Search by file name or keywords
#Folder
- Reference all content in a folder
- Shows folders related to current file
- Preview folder paths
- Requires complete code index
#Workspace
- Reference the entire workspace
- Available only in Chat mode
- Automatically finds relevant content
- Requires complete code index
- Helpful for understanding new projects
Note: For #Folder and #Workspace features, ensure your project’s code index is fully built for optimal results. You can manage the code index in Settings under “AI settings”.