> For the complete documentation index, see [llms.txt](https://modelmesh.gitbook.io/cline-zhong-wen-ban-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://modelmesh.gitbook.io/cline-zhong-wen-ban-docs/getting-started/context-management.md).

# Context Management

Context is key to getting the most out of Cline

> 💡 **Quick Reference**
>
> * Context = The information Cline knows about your project
> * Context Window = How much information Cline can hold at once
> * Use context files to maintain project knowledge
> * Reset when the context window gets full

### Understanding Context & Context Windows <a href="#understanding-context-and-context-windows" id="understanding-context-and-context-windows"></a>

![](https://docs.cline.bot/~gitbook/image?url=https%3A%2F%2F3321249260-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Ff8Oh1Lcy6yWYq1caYESV%252Fuploads%252FhhLjQthMNikjDLFjCilq%252Fimage.png%3Falt%3Dmedia%26token%3D9df6e559-3d99-42f4-8905-57df2fd8220c\&width=768\&dpr=4\&quality=100\&sign=eabe9e25\&sv=2)In a world of infinite context, the context window is what Cline currently has available

Think of working with Cline like collaborating with a thorough, proactive teammate:

#### How Context is Built <a href="#how-context-is-built" id="how-context-is-built"></a>

Cline actively builds context in two ways:

1. **Automatic Context Gathering (i.e. Cline-driven)**
   * Proactively reads related files
   * Explores project structure
   * Analyzes patterns and relationships
   * Maps dependencies and imports
   * Asks clarifying questions
2. **User-Guided Context**
   * Share specific files
   * Provide documentation
   * Answer Cline's questions
   * Guide focus areas
   * Share design thoughts and requirements

💡 **Key Point**: Cline isn't passive - it actively seeks to understand your project. You can either let it explore or guide its focus, especially in [Plan](https://docs.cline.bot/exploring-clines-tools/plan-and-act-modes-a-guide-to-effective-ai-development) mode.

#### Context & Context Windows <a href="#context-and-context-windows" id="context-and-context-windows"></a>

Think of context like a whiteboard you and Cline share:

* **Context** is all the information available:
  * What Cline 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 3.5 Sonnet: 200,000 tokens
    * DeepSeek: 64,000 tokens
  * When the whiteboard is full, you need to erase (clear context) to write more
    * [How Cline manages context under the hood](https://cline.bot/blog/understanding-the-new-context-window-progress-bar-in-cline)

⚠️ **Important**: Having a large context window (like Claude's 200k tokens) doesn't mean you should fill it completely. Just like a cluttered whiteboard, too much information can make it harder to focus on what's important.

### Understanding the Context Window Progress Bar <a href="#understanding-the-context-window-progress-bar" id="understanding-the-context-window-progress-bar"></a>

Cline provides a visual way to monitor your context window usage through a progress bar:

![](https://docs.cline.bot/~gitbook/image?url=https%3A%2F%2F3321249260-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Ff8Oh1Lcy6yWYq1caYESV%252Fuploads%252F2SldHaOWE4n4Og5W08G3%252Fimage.png%3Falt%3Dmedia%26token%3D630b27ae-8b9b-45a7-b00b-af292a3094ca\&width=768\&dpr=4\&quality=100\&sign=c10264b\&sv=2)

#### Reading the Bar <a href="#reading-the-bar" id="reading-the-bar"></a>

* ↑ 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., 200k for Claude 3.5-Sonnet)

#### When to Watch the Bar <a href="#when-to-watch-the-bar" id="when-to-watch-the-bar"></a>

* During long coding sessions
* When working with multiple files
* Before starting complex tasks
* When Cline seems to lose context

💡 **Tip**: Consider starting a fresh session when usage reaches 70-80% to maintain optimal performance.

### Working with Context Files <a href="#working-with-context-files" id="working-with-context-files"></a>

Context files help maintain understanding across sessions. They serve as documentation specifically designed to help AI assistants understand your project.

**Approaches to Context Files**

1. **Evergreen Project Context (i.e.** [**Memory Bank**](https://docs.cline.bot/improving-your-prompting-skills/custom-instructions-library/cline-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` and `systemPatterns.md`
   * Useful for long-running projects and teams
2. **Task-Specific Context (i.e.** [**Structured Approach**](https://cline.bot/blog/building-advanced-software-with-cline-a-structured-approach)**)**
   * Created for specific implementation tasks
   * Document requirements, constraints, and decisions
   * Example:

     Copy

     ```
     # 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
     ```
3. **Knowledge Transfer Docs**
   * Switch to plan mode and ask Cline 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**

1. **Structure and Format**
   * Use clear, consistent organization
   * Include relevant examples
   * Link related concepts
   * Keep information focused
2. **Maintenance**
   * Update after significant changes
   * Version control your context files
   * Remove outdated information
   * Document key decisions

### Practical Tips <a href="#practical-tips" id="practical-tips"></a>

1. **Starting New Projects**
   * Let Cline explore the codebase
   * Answer its questions about structure and patterns
   * Consider setting up basic context files
   * Document key design decisions
2. **Ongoing Development**
   * Update context files with significant changes
   * Share relevant documentation
   * Use Plan mode for complex discussions
   * Start fresh sessions when needed
3. **Team Projects**
   * Share common context files (consider using [.clinerules](https://docs.cline.bot/improving-your-prompting-skills/prompting) files in project roots)
   * Document architectural decisions
   * Maintain consistent patterns
   * Keep documentation current

Remember: The goal is to help Cline maintain consistent understanding of your project across sessions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://modelmesh.gitbook.io/cline-zhong-wen-ban-docs/getting-started/context-management.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
