# API Endpoints Used by the i-have-adhd Plugin: Internal Hooks and Runtime Integration

> Discover the internal API endpoints and hooks the i-have-adhd plugin uses for runtime integration within Pi. Learn how it extends functionality without external calls.

- Repository: [Ayoub Ghriss/i-have-adhd](https://github.com/ayghri/i-have-adhd)
- Tags: api-reference
- Published: 2026-08-24

---

**The i-have-adhd plugin does not use external HTTP API endpoints; instead, it registers internal extension flags, slash commands, and event hooks within the Pi runtime via [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts).**

The ayghri/i-have-adhd repository implements a Pi-Coding-Agent extension designed to reformat AI output for ADHD-friendly readability. Rather than calling remote web services, this plugin integrates deeply with the host runtime through registered commands and lifecycle event listeners that intercept user input and manage session states.

## Extension Flags and Command Registration

The plugin registers two primary user-facing entry points in the Pi environment. According to the source code in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts), these registrations occur during extension initialization.

**The `adhd` Startup Flag (lines 63-67)**

The extension declares a boolean flag that users can pass when launching the Pi agent. When enabled, this flag automatically activates ADHD mode at session start without requiring manual toggling. The implementation uses `pi.registerFlag` to bind the flag name to the internal state manager.

**The `i-have-adhd` Toggle Command (lines 69-71)**

The plugin exposes a slash command accessible via `/i-have-adhd [on|off]`. This command handler inspects the argument and updates the session configuration accordingly. If invoked without arguments, it toggles the current state between enabled and disabled.

## Event Hooks and Session Lifecycle

The extension subscribes to several Pi runtime events to maintain consistent behavior across session boundaries and context changes. These hooks are defined in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) and operate as asynchronous listeners.

**Input Interception via `pi.on("input")` (lines 93-102)**

The input listener serves dual purposes. First, it detects the alias `/skill:i-have-adhd` as a shortcut to toggle the mode. Second, it monitors for stop phrases such as "stop adhd mode" to immediately deactivate the formatting rules without requiring the slash command syntax.

**Session Initialization Hooks (lines 119-122)**

Three distinct session-level hooks ensure state persistence:
- **`session_start`**: Restores the previously saved ADHD state or applies the default when a new conversation begins.
- **`session_tree`**: Reapplies the state logic whenever the session tree is rebuilt during context management.
- **`session_compact`**: Ensures the ruleset is correctly injected or removed following a context compaction event that truncates conversation history.

## Message Injection and State Management

When toggling states, the plugin uses internal messaging utilities rather than external APIs. The `pi.sendMessage` function transmits system-level messages that modify the conversation context.

**Ruleset Injection (lines 117-130)**

Upon activation, the extension sends a message with type `RULES_MESSAGE_TYPE` containing the full formatting guidelines sourced from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md). When disabled, it sends a `DISABLED_MESSAGE_TYPE` notification to clear the active constraints. The `pi.ui.getStatus('i-have-adhd')` utility (referenced in the UI integration) returns `"● ADHD ON"` when active or `undefined` when inactive.

## Practical Usage Examples

Enable ADHD mode programmatically within a Pi session:

```typescript
// Explicitly turn on ADHD formatting
await pi.runCommand('i-have-adhd', 'on');

```

Toggle the mode using the skill alias:

```typescript
// Send the shortcut alias detected by the input listener
await pi.sendMessage({ text: '/skill:i-have-adhd' });

```

Disable the mode using natural language:

```typescript
// The input listener catches this phrase and triggers deactivation
await pi.sendMessage({ text: 'stop adhd mode' });

```

Check current status in the UI layer:

```typescript
const status = pi.ui.getStatus('i-have-adhd');
console.log(status); // Returns "● ADHD ON" or undefined

```

## Summary

- The i-have-adhd plugin operates entirely through internal Pi runtime hooks with no external HTTP dependencies.
- **Extension flag `adhd`** enables automatic activation at session startup via `pi.registerFlag` in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts).
- **Command `i-have-adhd`** provides manual toggle functionality with optional `on` or `off` arguments.
- **Event listeners** for `input`, `session_start`, `session_tree`, and `session_compact` maintain state consistency across conversation lifecycle events.
- **Message types `RULES_MESSAGE_TYPE` and `DISABLED_MESSAGE_TYPE`** handle the injection and removal of formatting rules via `pi.sendMessage`.
- Rule content is stored in [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md) and injected as system context when the mode is active.

## Frequently Asked Questions

### Does the i-have-adhd plugin make external API calls?

No. According to the ayghri/i-have-adhd source code, the plugin is a self-contained Pi-Coding-Agent extension. All functionality is implemented through internal hooks and commands registered with the Pi runtime; no HTTP requests to external services are performed.

### How do I enable ADHD mode automatically when starting a Pi session?

Pass the `--adhd` flag when initializing the Pi agent. This flag is registered in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) (lines 63-67) and triggers the session-start hook to activate formatting rules immediately upon conversation creation.

### What file contains the actual ADHD formatting rules injected into conversations?

The formatting guidelines are stored in [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md). When ADHD mode is activated, the extension reads this file and injects its contents as a `RULES_MESSAGE_TYPE` message into the conversation context via `pi.sendMessage`.

### Can I disable ADHD mode mid-conversation using natural language?

Yes. The input listener defined at lines 93-102 in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) monitors for stop phrases. Typing "stop adhd mode" or similar variations triggers the deactivation logic without requiring the `/i-have-adhd off` slash command syntax.