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

# 4.3 Plugin context

> Reference for PluginContext and the logger, events, navigation, notifications, auth, and configuration services.

A plugin receives a `PluginContext` in its lifecycle hooks, commands, and entry component. The context exposes only the services below.

```tsx theme={"system"}
import type { PluginEntryProps } from "@kcode/plugin-sdk";

export function MyEntry({ context }: PluginEntryProps) {
  context.logger.info("Entry rendered");
  const refresh = context.configuration.get<number>("refreshInterval");
  return <p>Refresh every {refresh} seconds</p>;
}
```

## 4.3.1 Members

| Member | Type | Purpose |
| - | - | - |
| `pluginId` | `string` | ID of the plugin that owns the context. |
| `logger` | `Logger` | `debug`, `info`, `warn`, `error`, and optional `withScope`. |
| `events` | `EventBus` | `publish`, `emit` (alias), `subscribe`, and `unsubscribe`. |
| `navigation` | `NavigationService` | `navigate(path)`. |
| `notifications` | `NotificationService` | `notify`, `info`, `success`, `warning`, `error`, and `dismiss`. |
| `auth` | `AuthService` | `getCurrentUser`, `isAuthenticated`, and `hasPermission`. |
| `configuration` | `PluginConfigurationService` | `get`, `set`, and `getAll` for the plugin's declared settings. |

## 4.3.2 Events

```ts theme={"system"}
const unsubscribe = context.events.subscribe("operations.refresh.requested", (payload) => {
  context.logger.debug("Refresh requested", { payload });
});

await context.events.publish("operations.refresh.requested", { requestedAt: new Date().toISOString() });
unsubscribe();
```

`subscribe` returns an unsubscribe function. The default bus accepts any event name with an unknown payload.

## 4.3.3 Notifications

| Level | Shortcut |
| - | - |
| `info` | `notifications.info(title, message?)` |
| `success` | `notifications.success(title, message?)` |
| `warning` | `notifications.warning(title, message?)` |
| `error` | `notifications.error(title, message?)` |

Each call returns a `Notification` with `id`, `level`, `title`, optional `message`, and `createdAt`. `dismiss(id)` returns `true` when it removed one.

## 4.3.4 Authentication

`AuthenticatedUser` has `id`, `username`, `displayName`, and `permissions`. Use `hasPermission(permissionId)` before running a privileged action.

> [!WARNING]
>
> In the web app, the demo runtime returns `true` from `hasPermission` for every permission. See [Credentials and access control](https://docs.khanhng.com/kcode-robot-suite/security/credentials-and-access-control.md).

## 4.3.5 Configuration

`get` returns a copy of the stored value, or `undefined` when none is stored. `get` and `set` accept only keys the plugin declared in `settings`. `set` validates the value type.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.