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

# Fast Context

> Search codebase for relevant context to enhance agent responses

The `--fast-context` flag searches your codebase for relevant code and adds it as context to the agent's prompt.

## Quick Start

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Find authentication code" --fast-context ./src
```

<img src="https://mintcdn.com/praisonai/fT4nF3hY6KPMOPvS/docs/cli/fast-context-fast-context.gif?s=bec696c066d2328d42099ce4d5185f0e" alt="Fast Context Demo" width="1497" height="1104" data-path="docs/cli/fast-context-fast-context.gif" />

## Usage

### Basic Fast Context

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Explain how the login function works" --fast-context ./src
```

**Expected Output:**

```
⚡ Fast Context enabled - searching ./src

📂 Found relevant files:
  • src/auth/login.py (95% relevance)
  • src/auth/utils.py (78% relevance)
  • src/models/user.py (65% relevance)

╭─ Agent Info ─────────────────────────────────────────────────────────────────╮
│  👤 Agent: DirectAgent                                                       │
│  Role: Assistant                                                             │
│  📄 Context: 3 files, 245 lines                                             │
╰──────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Based on the codebase, the login function in `src/auth/login.py` works as   │
│ follows:                                                                     │
│                                                                              │
│ 1. **Input Validation**: The function first validates the email format      │
│    using the `validate_email()` helper from `utils.py`                      │
│                                                                              │
│ 2. **User Lookup**: It queries the database using the User model to find    │
│    the user by email                                                         │
│                                                                              │
│ 3. **Password Verification**: Uses bcrypt to compare the hashed password    │
│                                                                              │
│ 4. **Token Generation**: On success, generates a JWT token with user claims │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Specify Search Path

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Search specific directory
praisonai "How does the API handle errors?" --fast-context ./src/api

# Search from project root
praisonai "Explain the database schema" --fast-context /path/to/project

# Search current directory
praisonai "Find all test files" --fast-context .
```

### Combine with Other Features

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Fast context with metrics
praisonai "Optimize this function" --fast-context ./src --metrics

# Fast context with guardrail
praisonai "Refactor the code" --fast-context ./src --guardrail "Maintain backward compatibility"

# Fast context with planning
praisonai "Add new feature" --fast-context ./src --planning
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    A[Prompt] --> B[Fast Context Search]
    B --> C[Relevant Files]
    C --> D[Context Injection]
    D --> E[Agent + Context]
    E --> F[Response]
```

1. **Query Analysis**: Analyzes your prompt to understand what code is relevant
2. **Codebase Search**: Searches the specified directory for matching files
3. **Relevance Ranking**: Ranks files by relevance to your query
4. **Context Injection**: Adds relevant code snippets to the agent's context
5. **Enhanced Response**: Agent responds with full codebase awareness

## Use Cases

### Code Explanation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Explain how the payment processing works" --fast-context ./src
```

### Bug Investigation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Why might the user session expire unexpectedly?" --fast-context ./src/auth
```

**Expected Output:**

```
⚡ Fast Context enabled

📂 Found relevant files:
  • src/auth/session.py
  • src/auth/middleware.py
  • src/config/settings.py

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Based on the code analysis, there are several potential causes for          │
│ unexpected session expiration:                                               │
│                                                                              │
│ 1. **Short Timeout**: In `settings.py`, `SESSION_TIMEOUT` is set to 300     │
│    seconds (5 minutes), which may be too short for some use cases           │
│                                                                              │
│ 2. **Missing Refresh**: The `session.py` doesn't implement token refresh    │
│    on activity, so sessions expire even during active use                   │
│                                                                              │
│ 3. **Race Condition**: In `middleware.py` line 45, there's a potential      │
│    race condition when checking session validity                            │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Code Review

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Review the error handling in this codebase" --fast-context ./src
```

### Feature Planning

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "How would I add OAuth support based on the current auth system?" --fast-context ./src/auth
```

### Documentation Generation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Generate API documentation for the user endpoints" --fast-context ./src/api/users
```

## Search Configuration

### File Types Searched

By default, Fast Context searches common code files:

| Language   | Extensions                   |
| ---------- | ---------------------------- |
| Python     | `.py`                        |
| JavaScript | `.js`, `.jsx`, `.ts`, `.tsx` |
| Go         | `.go`                        |
| Rust       | `.rs`                        |
| Java       | `.java`                      |
| C/C++      | `.c`, `.cpp`, `.h`, `.hpp`   |
| Ruby       | `.rb`                        |
| PHP        | `.php`                       |

### Ignored Paths

These directories are automatically excluded:

* `node_modules/`
* `venv/`, `.venv/`
* `__pycache__/`
* `.git/`
* `dist/`, `build/`

## Best Practices

<Tip>
  Be specific with your search path. Searching a smaller, relevant directory produces better results than searching the entire project.
</Tip>

<Warning>
  Large codebases may result in high token usage. Use `--metrics` to monitor costs.
</Warning>

<CardGroup cols={2}>
  <Card title="Specific Paths">
    Target specific directories for better relevance
  </Card>

  <Card title="Clear Prompts">
    Use specific technical terms that match your code
  </Card>

  <Card title="Iterative Search">
    Start broad, then narrow down to specific modules
  </Card>

  <Card title="Monitor Tokens">
    Use `--metrics` to track context size and costs
  </Card>
</CardGroup>

## Performance Tips

| Scenario         | Recommendation                         |
| ---------------- | -------------------------------------- |
| Large codebase   | Search specific subdirectories         |
| Many files found | Refine your prompt to be more specific |
| Slow search      | Exclude unnecessary directories        |
| High token usage | Limit search depth or file count       |

## Related

* [Fast Context Feature](/features/fast-context)
* [Knowledge CLI](/docs/cli/knowledge)
* [Metrics CLI](/docs/cli/metrics)
