上下文管理
快速参考
- 上下文 = Caret 对您项目了解的信息
- 上下文窗口 = Caret 一次可以保存的信息量
- 使用上下文文件来维护项目知识
- 当上下文窗口填满时重置
理解上下文和上下文窗口
.png)
把与 Caret 合作想象成与一个彻底、主动的团队成员协作:
How Context is Built
Caret actively builds context in two ways:
- Automatic Context Gathering (i.e. Caret-driven)
- Proactively reads related files
- Explores project structure
- Analyzes patterns and relationships
- Maps dependencies and imports
- Asks clarifying questions
- User-Guided Context
- Share specific files
- Provide documentation
- Answer Caret's questions
- Guide focus areas
- Share design thoughts and requirements
Key Point: Caret isn't passive - it actively seeks to understand your project. You can either let it explore or guide its focus, especially in Plan Mode.
Context & Context Windows
Think of context like a whiteboard you and Caret share:
- Context is all the information available:
- What Caret has discovered
- What you've shared
- Your conversation history
- Project requirements
- Previous decisions
- Context Window is the size of the whiteboard itself:
- Measured in tokens (1 token ≈ 3/4 of an English word)
- Each model has a fixed size:
- Claude Sonnet 4: 1,000,000 tokens
- Qwen3 Coder: 256,000 tokens
- Gemini 2.5 Pro: 1,000,000+ tokens
- GPT-5: 400,000 tokens
- When the whiteboard is full, Caret automatically summarizes the conversation to free up space
Important: Having a large context window doesn't mean you should fill it completely. Models start degrading around 400-500K tokens even if they claim higher limits. Just like a cluttered whiteboard, too much information can make it harder to focus on what's important.
Understanding the Context Window Progress Bar
Caret provides a visual way to monitor your context window usage through a progress bar:
%20(1).png)
Reading the Bar
- ↑ shows input tokens (what you've sent to the LLM)
- ↓ shows output tokens (what the LLM has generated)
- The progress bar visualizes how much of your context window you've used
- The total shows your model's maximum capacity (e.g., 1M for Claude Sonnet 4)
When to Watch the Bar
- During long coding sessions
- When working with multiple files
- Before starting complex tasks
- When Caret seems to lose context
Tip: With Auto Compact, Caret can now handle long conversations automatically. When combined with Focus Chain, you can work on complex projects that span multiple context windows without losing progress.
Automatic Context Management
Caret includes intelligent features to manage context automatically:
Default Settings You Should Keep On
Focus Chain - Enabled by default in v3.25. Caret generates a todo list at task start and keeps it in context so the thread doesn't drift. You can edit the markdown to add or reorder steps and Caret will adapt. Learn more about Focus Chain.
Auto Compact - Always on. As the context window reaches its limit, Caret creates a comprehensive summary, replaces the bloated history, and continues where it left off. Decisions, code changes, and state are preserved. Learn more about Auto Compact.
Advanced Context Tools
When you need more control over context management:
Deep Planning (/deep-planning
)
For substantial features, refactors, or integrations. Caret investigates your codebase, asks targeted questions, then writes implementation_plan.md
. It creates a fresh task with distilled, high-value context. Learn more about Deep Planning.
New Task (/newtask
)
At natural transition points, packages only what matters into a fresh task. Clean slate for implementation after research, or crisp handoff between teammates. Learn more about New Task.
Smol (/smol
)
Compress the conversation in place to keep momentum. Ideal during debugging or exploratory work when you don't want to break flow. Learn more about Smol.
Memory Bank + .clinerules
For non-trivial projects. The Memory Bank captures project knowledge as Markdown in your repo. .clinerules
are version-controlled instructions that align Caret's behavior with your team. Learn more about Memory Bank and Caret Rules.
Working with Context Files
Context files help maintain understanding across sessions. They serve as documentation specifically designed to help AI assistants understand your project.
Approaches to Context Files
-
Evergreen Project Context (Memory Bank)
- Living documentation that evolves with your project
- Updated as architecture and patterns emerge
- Example: The Memory Bank pattern maintains files like
techContext.md
andsystemPatterns.md
- Useful for long-running projects and teams
-
Task-Specific Context
-
Created for specific implementation tasks
-
Document requirements, constraints, and decisions
-
Example:
# auth-system-implementation.md
## Requirements
- OAuth2 implementation
- Support for Google and GitHub
- Rate limiting on auth endpoints
## Technical Decisions
- Using Passport.js for provider integration
- JWT for session management
- Redis for rate limiting
-
-
Knowledge Transfer Docs
- Switch to plan mode and ask Caret to document everything you've accomplished so far, along with the remaining steps, in a markdown file.
- Copy the contents of the markdown file.
- Start a new task using that content as context.
Using Context Files Effectively
- Structure and Format
- Use clear, consistent organization
- Include relevant examples
- Link related concepts
- Keep information focused
- Maintenance
- Update after significant changes
- Version control your context files
- Remove outdated information
- Document key decisions
Practical Tips
- Starting New Projects
- Let Caret explore the codebase
- Answer its questions about structure and patterns
- Consider setting up basic context files
- Document key design decisions
- Ongoing Development
- Update context files with significant changes
- Share relevant documentation
- Use Plan mode for complex discussions
- Start fresh sessions when needed
- Team Projects
- Share common context files (consider using .clinerules files in project roots)
- Document architectural decisions
- Maintain consistent patterns
- Keep documentation current
Bonus Context Tips
- You can @ links and have the webpage's context added to Caret (docs, blogs, etc.)
- Utilize MCP servers to pull in context from your external knowledge bases
- Screenshots can be used as context for models that support image inputs
The Bottom Line
Caret already does a lot of context work for you - Focus Chain, Auto Compact, and the planning flow are designed to keep the thread intact across long horizons. The goal is to help Caret maintain consistent understanding of your project across sessions.
Remember: The goal is to keep only what matters in view, at every step.