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

# Monorepo Scopes

> Limit operations to specific paths in your repository

Scopes let you focus on specific parts of a large repository, making wit faster and less noisy.

## Overview

In a monorepo, you often only care about one package or service. Scopes limit all wit operations to the paths you specify.

```bash theme={null}
# Set scope to frontend package
wit scope set packages/frontend/

# Now all commands are scoped
wit status   # Only shows frontend files
wit add .    # Only stages frontend files
wit log      # Only shows frontend commits
```

## Commands

### View Current Scope

```bash theme={null}
wit scope
```

Output:

```
Current scope: packages/frontend/
```

Or if no scope:

```
Current scope: (entire repository)
```

### Set Scope

```bash theme={null}
wit scope set <path>
```

**Examples:**

```bash theme={null}
# Scope to a directory
wit scope set packages/frontend/

# Scope to multiple paths (comma-separated)
wit scope set packages/frontend/,packages/shared/

# Scope to a pattern
wit scope set "src/**/*.ts"
```

### Use Preset

```bash theme={null}
wit scope use <preset>
```

Presets are predefined scopes in your config:

```bash theme={null}
wit scope use frontend
wit scope use backend
wit scope use docs
```

### Clear Scope

```bash theme={null}
wit scope clear
```

Returns to operating on the entire repository.

## Configuration

Define presets in `.wit/config`:

```ini theme={null}
[scope "frontend"]
    paths = packages/frontend/
    
[scope "backend"]
    paths = packages/backend/,packages/api/
    
[scope "docs"]
    paths = docs/,*.md
```

## Effect on Commands

When a scope is set, these commands are affected:

| Command  | Effect                                           |
| -------- | ------------------------------------------------ |
| `status` | Only shows scoped files                          |
| `add .`  | Only stages scoped files                         |
| `log`    | Only shows commits affecting scoped paths        |
| `diff`   | Only shows changes in scoped files               |
| `commit` | Commits all staged files (scope affects staging) |
| `blame`  | Works on any file (not affected)                 |

## Example Monorepo Structure

```
my-monorepo/
├── packages/
│   ├── frontend/
│   │   ├── src/
│   │   └── package.json
│   ├── backend/
│   │   ├── src/
│   │   └── package.json
│   └── shared/
│       └── src/
├── docs/
├── scripts/
└── package.json
```

### Working on Frontend

```bash theme={null}
# Set scope
wit scope set packages/frontend/

# Work normally - only frontend files
wit status
wit add src/components/Button.tsx
wit commit -m "Update Button component"

# Clear when done
wit scope clear
```

### Using Presets

```bash theme={null}
# Quick scope switching
wit scope use frontend
# ... work on frontend ...

wit scope use backend
# ... work on backend ...

wit scope clear
# ... work on everything ...
```

## Use Cases

### Focus During Development

```bash theme={null}
# Focus on what you're working on
wit scope set packages/auth/

# Less noise in status
wit status
# Only shows auth package files
```

### Scoped Commits

```bash theme={null}
# Ensure you only commit frontend changes
wit scope set packages/frontend/
wit add .
wit commit -m "Frontend: Update styles"
```

### Scoped History

```bash theme={null}
# What changed in the API recently?
wit scope set packages/api/
wit log --oneline -n 20
```

### CI/CD Pipelines

```bash theme={null}
# Only run tests if package changed
wit scope set packages/auth/
if [ "$(wit status --porcelain)" ]; then
    npm run test:auth
fi
```

## Tips

<Tip>
  Set scope in your terminal profile for focused work:

  ```bash theme={null}
  alias fe='wit scope use frontend'
  alias be='wit scope use backend'
  alias all='wit scope clear'
  ```
</Tip>

<Tip>
  Use scopes with other commands:

  ```bash theme={null}
  wit scope set packages/frontend/
  wit stats  # Stats for frontend only
  wit cleanup  # Branches affecting frontend
  ```
</Tip>

## Limitations

* Scopes are session-based (not persisted)
* Some commands ignore scopes (e.g., `branch`, `switch`)
* Scopes don't affect file system operations
