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

# Plugin Settings

> Typed per-plugin settings and optional settings screens

Extensions get their own isolated, type-safe settings store. Every plugin has its own namespace that the host persists across app restarts and plugin updates. Use it to store configuration your extension exposes to users.

Unlike the global [`Settings`](/extensions/api-reference/settings) service — which reads and writes Klyx's own editor settings — `PluginSettings` is scoped to your plugin. Each value is a `key -> value` pair stored as a string.

## Accessing the settings

`PluginSettings` is a per-plugin runtime service. Access it with `by runtime()`:

```kotlin theme={null}
private val settings: PluginSettings by runtime()
```

## Reading values

Typed getters return a default when the key is absent:

```kotlin theme={null}
val fontSize = settings.getInt("fontSize", 14)       // Int
val wordWrap = settings.getBoolean("wordWrap")        // Boolean
val label    = settings.getString("label", "Default") // String?
val ratio    = settings.getFloat("ratio", 0.5f)       // Float
val count    = settings.getLong("count", 0L)          // Long
val tags     = settings.getStringSet("tags")          // Set<String>
```

All getters except `getString` are non-null with sensible defaults. `getString` returns `null` when the key is absent and no default is provided.

## Writing values

Typed putters persist the value immediately:

```kotlin theme={null}
settings.putInt("fontSize", 18)
settings.putBoolean("wordWrap", true)
settings.putString("label", "My extension")
settings.putFloat("ratio", 0.75f)
settings.putLong("count", 42L)
settings.putStringSet("tags", setOf("kotlin", "android"))
```

Remove keys with:

```kotlin theme={null}
settings.remove("label")
settings.clear() // clears all values for this plugin
```

## Observing changes

`values` is a reactive `StateFlow` that emits a new snapshot whenever any value changes:

```kotlin theme={null}
val values by settings.values.collectAsState()
```

```kotlin theme={null}
pluginScope.launch {
    settings.values.collect { current ->
        // React to setting changes
    }
}
```

## Supported types

`String`, `Int`, `Long`, `Float`, `Boolean`, and `Set<String>` are supported out of the box. For anything else, serialize to a `String` yourself (for example with kotlinx.serialization) and use `putString`/`getString`.

## Optional settings screen

An extension can expose a dedicated settings screen in the Klyx app. Registration is **optional** — the settings button only appears in the plugin's details screen for plugins that register one.

Register your settings UI with the `PluginSettingsRegistry`:

```kotlin theme={null}
private val settingsRegistry: PluginSettingsRegistry by plugin()

override suspend fun onStart() {
    settingsRegistry.register {
        // `this` is the typed PluginSettings for this plugin
        Column {
            val wordWrap by remember {
                mutableStateOf(getBoolean("wordWrap"))
            }
            Row {
                Text("Word wrap")
                Switch(
                    checked = wordWrap,
                    onCheckedChange = { enabled ->
                        pluginScope.launch { putBoolean("wordWrap", enabled) }
                    }
                )
            }
        }
    }
}
```

The registered composable is invoked by the host with your plugin's typed `PluginSettings` as the receiver, so you can read and write values directly. The registration is removed automatically when your plugin unloads.

## Security

> **Do not store secrets or sensitive data** — API keys, tokens, passwords, credentials, or personal data — in settings. Settings are stored in plain text and can be read by anyone with access to the app's data directory, exported by the user from the developer options, or inspected by other code running on the device. Treat every value you store here as public. Use the platform's secure storage (for example the Android Keystore) for anything that must remain private.
