# How the i-have-adhd Rules Persistence Model Works During a Session: Injection, Tagging, and Re-injection

> Understand how the i-have-adhd rules persistence model works. Learn about injection tagging and re-injection to maintain rules throughout your session.

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

---

**The i-have-adhd skill persists rules throughout a conversational session by injecting the full ruleset once at startup via SessionStart hooks, tracking it with a special message type (`i-have-adhd-rules`), and automatically re-injecting the rules if model-side context compaction drops them.**

The i-have-adhd project implements a sophisticated persistence model designed to keep its 10 ADHD-friendly rules active throughout your entire conversational session without requiring repeated injections on every request. Unlike simple system prompts that get re-sent repeatedly, this persistence model uses a combination of session hooks, message type tagging, and compaction-aware re-injection to maintain rule continuity.

## Session-Start Hook Injection

The persistence model begins with a **SessionStart hook** that executes exactly once when a new conversation begins. Located in the repository at [`hooks/always-on.sh`](https://github.com/ayghri/i-have-adhd/blob/main/hooks/always-on.sh), `hooks/always-on.ps1`, and `hooks/always-on.mjs`, these scripts read the canonical rule source from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md) and insert it as a system-style banner containing the header *"ADHD MODE ACTIVE"* and the full rule text.

This injection happens only at session initialization, not on every API request, which optimizes token usage while ensuring the model receives the complete behavioral guidelines immediately.

```bash

# Activate ADHD mode at session start (runs once per session)

./hooks/always-on.sh      # Bash

./hooks/always-on.ps1     # PowerShell  

./hooks/always-on.mjs     # JavaScript

```

## Message-Type Tagging and Context Tracking

Once injected, the rules are stored with a special message type identifier defined in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts). The extension marks the injected banner with the type **`i-have-adhd-rules`**, allowing the runtime to track whether the rules remain present in the model's context window.

The runtime periodically checks `rulesAreInContext()` to verify that the `i-have-adhd-rules` message still exists in the conversation history. As long as this tag persists, the system considers the rules "live" and active for all subsequent interactions.

```typescript
// In extensions/i-have-adhd.ts - check and re-inject if needed
if (!rulesAreInContext(ctx)) {
  injectRules(ctx);  // Re-inject rules if compaction dropped them
}

```

## Explicit Turn-Off Commands

The rules remain active for the entire session duration unless explicitly disabled. Users can issue **turn-off commands** such as `stop adhd mode` or `normal mode` to disable the rule set. When the extension detects these commands, it removes the `i-have-adhd-rules` message from the conversation history.

This deletion effectively disables the rule set for the remainder of the session without requiring a full session restart.

## Compaction Safety and Re-injection

Modern language models automatically **compact context windows** by dropping older messages when conversations grow long. To prevent the rules from disappearing during extended sessions, [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) includes logic to detect when the rules have been dropped and automatically re-inject them.

If `rulesAreInContext()` returns false, the extension executes `injectRules(ctx)` to add a second copy of the ruleset, ensuring that the ADHD-friendly guidelines survive any automatic pruning the model performs.

## Always-On Configuration

For users who want the rules active in every new session without manual activation, the repository supports an **Always-On option**. Creating a flag file at `~/.claude/.i-have-adhd-always` triggers the SessionStart hook automatically for every new conversation.

Removing this flag file disables the automatic behavior, returning to manual activation only.

```bash

# Enable ADHD mode for every new session

touch ~/.claude/.i-have-adhd-always

# Disable automatic activation

rm ~/.claude/.i-have-adhd-always

```

## Summary

- **Single injection**: The SessionStart hook ([`hooks/always-on.sh`](https://github.com/ayghri/i-have-adhd/blob/main/hooks/always-on.sh), `hooks/always-on.ps1`, `hooks/always-on.mjs`) loads rules from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md) once at session start.
- **Type tagging**: Rules are marked with `i-have-adhd-rules` message type for context tracking.
- **Compaction defense**: The runtime re-injects rules via `injectRules()` if `rulesAreInContext()` detects they were dropped.
- **Explicit control**: Users disable rules with `stop adhd mode` or `normal mode` commands.
- **Persistent flag**: The `~/.claude/.i-have-adhd-always` file enables automatic activation for all future sessions.

## Frequently Asked Questions

### How does the i-have-adhd extension prevent rule loss during long sessions?

The extension implements **compaction safety** in [`extensions/i-have-adhd.ts`](https://github.com/ayghri/i-have-adhd/blob/main/extensions/i-have-adhd.ts) by monitoring the conversation context with `rulesAreInContext()`. If model-side context compaction removes the rules message, the runtime automatically calls `injectRules(ctx)` to re-insert the ruleset, ensuring the ADHD guidelines remain active regardless of conversation length.

### Can I make ADHD mode automatically start for every new session?

Yes. Create a flag file at `~/.claude/.i-have-adhd-always` to enable the Always-On option. When this file exists, the SessionStart hook ([`hooks/always-on.sh`](https://github.com/ayghri/i-have-adhd/blob/main/hooks/always-on.sh) or platform equivalents) automatically injects the rules at the beginning of every new session. Delete the file to disable this behavior.

### What files control the initial injection of the rules?

The initial injection is handled by the SessionStart hooks located at [`hooks/always-on.sh`](https://github.com/ayghri/i-have-adhd/blob/main/hooks/always-on.sh) (Bash), `hooks/always-on.ps1` (PowerShell), and `hooks/always-on.mjs` (JavaScript). These scripts read the canonical rules from [`skills/i-have-adhd/SKILL.md`](https://github.com/ayghri/i-have-adhd/blob/main/skills/i-have-adhd/SKILL.md) and insert them as a banner with the "ADHD MODE ACTIVE" header.

### How do I manually disable the rules during an active session?

Issue the command `stop adhd mode` or `normal mode` during your conversation. The extension detects these commands and removes the `i-have-adhd-rules` message from the conversation context, immediately disabling the rule set for the remainder of the session without requiring a restart.