# Customizing Addon Context

This guide shows how to customize the runtime context of an addon.

***

### Overview

Each addon receives an `AddonContext`, which provides access to:

* addon ID
* filesystem paths
* feature manager

By default, OMS creates this context automatically.

However, an addon can customize how the context is built by overriding `configureContext(...)`.

***

### 1. Default behavior

```kotlin
class HelloWorldAddon : OmsAddon(HelloWorldMod.MOD_ID)
```

OMS creates a default `AddonContextSpec` and builds the context internally.

***

### 2. Customizing the context

Override `configureContext(...)` to modify the context specification:

```kotlin
override fun configureContext(spec: AddonContextSpec): AddonContextSpec {
    return spec.copy(
        featureManagerFactory = {
            CustomFeatureManager( ... )
        }
    )
}
```

***

### 3. What can be customized

`AddonContextSpec` allows overriding selected factories:

```kotlin
data class AddonContextSpec(
    val id: String,
    val pathsFactory: (() -> AddonPaths)? = null,
    val featureManagerFactory: (() -> FeatureManager)? = null,
)
```

Typical use cases:

* custom `FeatureManager`
* custom filesystem structure
* specialized infrastructure setup

***

### 4. Important constraints

* `id` must not be changed
* only override what you need
* keep default behavior for everything else

***

### When to use this

Use context customization when:

* default feature manager behavior is not sufficient
* you need a custom filesystem layout
* your addon requires specialized infrastructure

Most addons do not need to override the context.

***

### Notes

* Context is created once during initialization
* It remains stable during runtime
* Features receive the finalized context


---

# Agent Instructions: 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:

```
GET https://conboi.gitbook.io/oms-wiki/developer-guide/implementation-guides/customizing-addon-context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
