Mastering Context in Trae

Amber Shen·

We've put together this guide that shows you how to make smart use of context in Trae to collaborate seamlessly with your AI partner.

Still frustrated that AI doesn't quite understand your intent? We've put together this guide that shows you how to make smart use of context in Trae to collaborate seamlessly with your AI partner.


What Is “Context” in Trae?

“Context” refers to the background information you provide to help the AI understand your intent.

Just like humans rely on conversation history and shared background to communicate, AI performs better when it has access to relevant supporting information.

Trae supports two main types of context:

  • Internal Context: Codebase, file content, terminal logs, etc.

  • External Context: Searchable web pages, documentation sets, and more.

Adding context reduces misunderstandings and improves the accuracy of AI responses.

How to Use Context in Trae

Everything starts with a "#" in the chat box

Internal Context

  • #Code: Search and preview functions or classes in the current file.

  • #File: Select specific files (recent files shown by default, with folder previews).

  • #Folder: Include an entire folder (via code indexing and directory search).

  • #Workspace: Ask project-wide questions (Trae will automatically find the most relevant files).

Ignore Files Context

To control what gets indexed from your project, you can add files or folders to the Ignore Files list. These will be excluded from AI context and codebase indexing.

Why does it matter?

  • Security: Prevent AI from indexing sensitive information such as credentials, API keys, and config files containing secrets.

  • Performance: In large codebases, exclude irrelevant modules, legacy code, or third-party packages to improve indexing speed and AI response time.

How to add ignore files:

  1. Go to Settings > Context > Ignore Files.

  2. Add specific file paths, folders, or use glob patterns (e.g., **/secrets/*.json, node_modules/) to exclude them from indexing.

This gives you precise control over what Trae can access—keeping your workspace both secure and optimized.

External Context: Docs and Web

#Doc: Document Sets

To preload external references like technical docs, API guides, or design specs:

  1. Click the Settings icon > Context > Docs, or use #Doc in the chat box.
  1. Click + Add Document Set.

  2. Choose one of the following: - **Via URL:**Enter a name and the doc-site URL. Trae will auto-fetch pages under the same path and up to three levels deep. - **From Local Files:**Upload .md or .txt files (max 10MB per file, up to 50MB total, max 1000 files).

  1. Once indexed, you can reference the document set directly in your prompts.

#Web: Online Sources

Two ways to use it:

  • Type #Web [your question] → Trae will run a live web search.

  • Type a URL + your question → Trae pulls content from that specific page to generate an answer.

Useful for referencing the latest updates from official docs or comparing across multiple sources.


Use Cases

1. From Product Requirements to Code Generation

Upload product specs or API docs via #Doc to give Trae full context of your business logic.

Examples:

#Doc E-commerce Payment Spec
Based on the timeout rule in the doc, generate the backend logic to update order status.
 
#Doc API Guide
What's the return structure of this API?

How it works: Trae links business rules or field definitions from your docs directly to your prompt, reducing back-and-forth.

2. Technical Docs as AI References

No more juggling 10 open tabs.

  • **Local Docs:**Add local files (Markdown, API docs, etc.) via #Doc, then ask questions directly.

  • Online Docs: Use

#Web https://vuejs.org/guide/components/registration.html
→ What are the component registration options in Vue?

This avoids context switching and allows Trae to reference methods, parameters, and even compare version changes in real-time.

3. Onboarding New Teammates

Upload onboarding materials, team workflows, and engineering best practices using #Doc or #Workspace. New team members can ask questions in plain language to ramp up faster.

Example:

#Doc Code Submission Guide
What checks are required before committing code?

4. @Agents + Context = A Team of Smart Specialists

Add a document set to a Trae Agent to give it deep domain knowledge.

Example:

@FrontendEngineer
Give it #Doc Project Guidelines — now it's an expert familiar with your team's handbook.

Build a team of domain-specific AI agents—each with focused skills and scoped knowledge.


Pro Tips

  • Keep Docs Up-to-Date: Re-upload or refresh URLs to make sure your context reflects the latest changes.

  • Allow Time for Indexing: After uploading, indexing takes a few seconds to minutes. If it fails, check file size or format and try again.

With #Context, Trae evolves from a generic AI executor to a collaborative coding partner that actually gets you. By binding your code, docs, files, and external content, you're teaching Trae how you work. We aim to build a smarter, more personalized development experience.

← Blog