> ## Documentation Index
> Fetch the complete documentation index at: https://www.greptile.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Context

> Access your team's coding patterns from your IDE using MCP

Greptile learns your team's coding standards by analyzing PR feedback. Use MCP tools to access these patterns during development.

## What is Custom Context?

Custom context entries are coding patterns Greptile has learned from your team's code reviews. They include:

* **CUSTOM\_INSTRUCTION**: Explicit coding rules (e.g., "Use async/await instead of Promise.then()")
* **PATTERN**: Observed patterns from your codebase (e.g., "API errors should return standardized error objects")

Each entry has:

* **Body**: The actual instruction or pattern
* **Scopes**: Where it applies (specific files, directories, or universal)
* **Status**: `ACTIVE`, `INACTIVE`, or `SUGGESTED`
* **Evidence**: Linked comments that support the pattern

## Common Workflows

### List Your Team's Patterns

Ask your AI assistant:

```text theme={}
What custom context does my organization have?
```

Or be more specific:

```text theme={}
Show me all active coding patterns for JavaScript files
```

The assistant uses `list_custom_context` to retrieve your patterns.

### Onboard a New Developer

```text theme={}
Show a new team member all our coding patterns and explain why we use them
```

**Example response:**

```markdown theme={}
Here are your organization's key coding patterns:

1. **Security Pattern**: "Validate all API inputs using Joi schemas"
   - Why: Prevents injection attacks and ensures data integrity
   - Applied to: All API route files

2. **Style Pattern**: "Use async/await instead of Promise.then()"
   - Why: Better readability and error handling
   - Applied to: All JavaScript/TypeScript files

3. **Architecture Pattern**: "Prefer composition over inheritance"
   - Why: More flexible and testable code
   - Applied to: Class-based components
```

### Apply Patterns During Development

When writing code, ask:

```text theme={}
Check if my current code follows our team's patterns
```

Or when reviewing a specific file:

```text theme={}
What coding patterns apply to this authentication service?
```

### Create New Patterns

From recent review feedback:

```text theme={}
Create a new coding pattern based on this review feedback: "Always use TypeScript strict mode for new services"
```

The assistant will use `create_custom_context`:

```markdown theme={}
Pattern Type: CUSTOM_INSTRUCTION
Body: "Always use TypeScript strict mode for new services"
Scope: Apply to **/services/**/*.ts files
Status: ACTIVE

Should I create this pattern?
```

### Search for Specific Patterns

```text theme={}
Search our custom context for anything related to error handling
```

Uses `search_custom_context` to find relevant patterns.

## Understanding Scopes

Scopes define where patterns apply:

| Scope Type   | Example                                                                          | Meaning                     |
| ------------ | -------------------------------------------------------------------------------- | --------------------------- |
| Universal    | `{"AND": []}`                                                                    | Applies everywhere          |
| File pattern | `{"AND": [{"operator": "MATCHES", "field": "filepath", "value": "**/*.ts"}]}`    | Applies to TypeScript files |
| Directory    | `{"AND": [{"operator": "MATCHES", "field": "filepath", "value": "src/api/**"}]}` | Applies to API directory    |

**Scope format:**

```json theme={}
{
  "scopes": {
    "AND": [
      {
        "operator": "MATCHES",
        "field": "filepath",
        "value": "**/*.js"
      }
    ]
  }
}
```

## Example Prompts

<AccordionGroup>
  <Accordion title="Review code against patterns">
    ```text theme={}
    Check this function against our team's coding patterns. 
    What improvements should I make?
    ```
  </Accordion>

  <Accordion title="Find patterns for specific area">
    ```text theme={}
    What patterns should I follow when writing database queries?
    ```
  </Accordion>

  <Accordion title="Understand why a pattern exists">
    ```text theme={}
    Get the details and linked comments for pattern ctx_123. 
    Why was this pattern created?
    ```
  </Accordion>

  <Accordion title="Suggest new patterns from PR feedback">
    ```text theme={}
    Based on recent Greptile comments, what new patterns 
    should we add to our custom context?
    ```
  </Accordion>
</AccordionGroup>

## Tools Used

| Tool                    | Purpose                                      |
| ----------------------- | -------------------------------------------- |
| `list_custom_context`   | List all patterns, optionally filter by type |
| `get_custom_context`    | Get details for a specific pattern           |
| `search_custom_context` | Search patterns by content                   |
| `create_custom_context` | Create new patterns                          |

See [Tools Reference](/mcp/tools) for complete parameters.

## Next Steps

<CardGroup cols={2}>
  <Card title="Auto-Fix Workflow" icon="wand-magic-sparkles" href="/mcp/auto-fix">
    Apply fixes based on your team's patterns
  </Card>

  <Card title="Reports & Analytics" icon="chart-line" href="/mcp/reports">
    Generate code review reports and analytics
  </Card>
</CardGroup>
