# How the Pi / OMP Extension Implements I-Have-ADHD Mode

> Discover how the Pi / OMP extension implements I-Have-ADHD mode. Learn about dynamic rule injection, state persistence, and runtime toggling for an enhanced user experience.

- Repository: [Ayoub Ghriss/i-have-adhd](https://github.com/ayghri/i-have-adhd)
- Tags: internals
- Published: 2026-09-09

---

**The Pi / OMP extension implements I-Have-ADHD mode by dynamically injecting ADHD-specific rules from [`SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/SKILL.md) into the model context when enabled, persisting state across sessions via custom entries, and providing CLI flags and slash commands for runtime toggling.**

The `ayghri/i-have-adhd` repository provides a specialized focus mode for neurodivergent users within the Pi and OMP (Open-Multi-Platform) runtimes. This extension seamlessly integrates with the conversation flow by loading rules from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md), managing context injection through the `ExtensionAPI`, and maintaining state persistence across session lifecycle events.

## Rule Loading and Configuration Parsing

The extension initializes by loading two critical resources during startup.

**`loadRules()`** reads [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md), strips YAML front-matter, and stores the raw rule text in memory for later injection. This function ensures the model receives only the actionable guidance without metadata headers.

**`loadConfig()`** parses the optional [`i-have-adhd.json`](https://github.com/ayghri/i-have-adhd/blob/main/i-have-adhd.json) file for boolean flags including `alwaysOn` (which enables the mode by default) and `hideStatus` (which suppresses the UI indicator).

## User Interface Controls

The extension registers dual interaction mechanisms for different user workflows.

**`registerFlag()`** adds the `--adhd` CLI flag to the Pi/OMP runtime. When present at startup, this flag forces the mode enabled before any user input processes.

**`registerCommand()`** implements the `/i-have-adhd` slash command, accepting `on`, `off`, or no arguments to toggle state at runtime. This command provides immediate feedback through the chat interface regardless of the initial CLI configuration.

## Session State Persistence

State survival across conversation tree rebuilds depends on custom session management.

The extension declares **custom session entries** using the `STATE_ENTRY_TYPE` constant to store enabled/disabled boolean values. During lifecycle events `session_start` and `session_tree`, the **`getSavedState()`** function retrieves these entries and restores the previous configuration. The system also listens to `session_compact` events to maintain synchronization during context compression.

## Context Injection and Removal

The **`syncContext()`** function in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) manages model context through conditional message injection.

When enabling the mode, the extension sends a `RULES_MESSAGE_TYPE` custom message containing the rule header and processed [`SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/SKILL.md) content, but only if **`rulesAreInContext()`** returns false. This helper function relies on **`latestMarkerIsActive()`** from [`extensions/context-compat.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/context-compat.ts) to detect whether rules currently exist in the conversation history.

When disabling the mode, the extension injects a `DISABLED_MESSAGE_TYPE` message containing an "ADHD MODE OFF" notice. This marker signals the model to stop applying ADHD-specific formatting without removing the conversation history.

## Input Handling and Stop Phrases

The extension processes every user input through dedicated handlers to detect conversational control signals.

The input handler recognizes the built-in skill alias `/skill:i-have-adhd` for manual activation. It also monitors for stop phrases including "stop adhd mode" and "normal mode" to trigger automatic deactivation. When detected, the system optionally returns a `DISABLE_CONFIRMATION` message to confirm the mode change.

When active, the extension displays a green "● ADHD ON" badge via **`ctx.ui.setStatus()`** unless the `hideStatus` configuration flag is set to true.

## Practical Usage Examples

Enable ADHD mode at startup using the CLI flag:

```bash
pi --adhd

```

Toggle mode at runtime within a conversation:

```typescript
await pi.runCommand("/i-have-adhd");

```

Check active state programmatically from another extension:

```typescript
if (ctx.sessionManager.hasCustomEntry("i-have-adhd-state")) {
  // Apply ADHD-friendly output formatting
}

```

Disable mode using natural language input:

```typescript
await pi.sendMessage({ text: "stop adhd mode" });

```

## Summary

- **Rule Management**: The extension loads ADHD guidelines from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md) via `loadRules()` and optional settings from [`i-have-adhd.json`](https://github.com/ayghri/i-have-adhd/blob/main/i-have-adhd.json) via `loadConfig()`
- **State Persistence**: Session state survives restarts through custom entries (`STATE_ENTRY_TYPE`) retrieved by `getSavedState()` during `session_start` and `session_tree` events
- **User Controls**: The `--adhd` CLI flag and `/i-have-adhd` slash command provide flexible activation mechanisms via `registerFlag()` and `registerCommand()`
- **Context Synchronization**: `syncContext()` injects `RULES_MESSAGE_TYPE` when enabled and `DISABLED_MESSAGE_TYPE` when disabled, using `rulesAreInContext()` and `latestMarkerIsActive()` for detection
- **Conversational Control**: Input handlers detect stop phrases like "stop adhd mode" and return `DISABLE_CONFIRMATION` when turning off the mode
- **Visual Feedback**: The `ctx.ui.setStatus()` method displays a green "● ADHD ON" badge unless disabled via configuration

## Frequently Asked Questions

### How does the Pi extension remember ADHD mode between sessions?

The extension stores the current state in a custom session entry defined by the `STATE_ENTRY_TYPE` constant according to the `ayghri/i-have-adhd` source code. When the Pi runtime triggers `session_start` or `session_tree` events, the `getSavedState()` function retrieves this entry from the session manager and restores the previous configuration, ensuring the mode persists across conversation tree rebuilds and application restarts.

### Can I hide the ADHD status indicator in the UI?

Yes. Create an [`i-have-adhd.json`](https://github.com/ayghri/i-have-adhd/blob/main/i-have-adhd.json) configuration file in your project root and set the boolean `"hideStatus": true`. When this flag is present, the extension skips the `ctx.ui.setStatus()` call that normally displays the green "● ADHD ON" badge, while maintaining all other ADHD mode functionality including rule injection and context management.

### What happens to the model context when I disable ADHD mode?

When disabled through the `/i-have-adhd off` command or stop phrases, the extension checks if `RULES_MESSAGE_TYPE` messages remain in the context using `rulesAreInContext()`. If detected, it injects a `DISABLED_MESSAGE_TYPE` custom message containing an "ADHD MODE OFF" notice. This marker ensures the model stops applying ADHD-specific rules without surgically removing previous conversation history containing rule applications.

### Is this implementation compatible with both Pi and OMP runtimes?

Yes. Both runtimes share the identical implementation in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) because they conform to the same `ExtensionAPI` contract. The `.opencode/plugins/i-have-adhd.mjs` file serves as the OpenCode-specific entry point that loads the same TypeScript extension, ensuring consistent behavior across Pi, OMP, and OpenCode platforms.