add-global

Create a reactive global variable that derives from atoms with subscription support

16 stars

Best use case

add-global is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create a reactive global variable that derives from atoms with subscription support

Teams using add-global should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/add-global/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/add-global/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/add-global/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How add-global Compares

Feature / Agentadd-globalStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create a reactive global variable that derives from atoms with subscription support

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Add Global Skill

## Usage
```
/add-global <globalName>
```

---

## Step 1: Ask Questions

### 1. Global Purpose
```
What derived state does this global provide?
Brief description:
```

### 2. Source Atoms
```
Which atoms does this global derive from?
(List atom names from src/atoms/)

Examples: myInventoryAtom, myGardenAtom, weatherAtom
```

### 3. Derivation Logic
```
How is the global value computed from atoms?

A) Simple merge - Combine fields from multiple atoms
B) Transformation - Transform/filter atom data
C) Aggregation - Compute stats/totals from atoms
D) Complex - Multiple transformations
```

### 4. Update Sensitivity
```
Should subscribers react to every atom change?

A) Yes - Every change triggers update
B) No - Only meaningful changes (use subscribeStable)
```

### 5. Public API
```
Expose in window.Gemini.Globals?

A) Yes
B) No - Internal only
```

---

## Step 2: Create Global File

### Create `src/globals/variables/<globalName>.ts`

```typescript
import { createReactiveGlobal } from '../core/reactive';
import { Store } from '../../atoms';
import type { GlobalVariable, Unsubscribe } from '../core/types';

// ─────────────────────────────────────────────────────────────────────────────
// Types
// ─────────────────────────────────────────────────────────────────────────────

export interface <GlobalName> {
    // Derived fields
    field1: string;
    field2: number;
}

// ─────────────────────────────────────────────────────────────────────────────
// Derivation
// ─────────────────────────────────────────────────────────────────────────────

async function derive<GlobalName>(): Promise<<GlobalName>> {
    const atom1 = await Store.select('sourceAtom1');
    const atom2 = await Store.select('sourceAtom2');

    return {
        field1: atom1?.value ?? 'default',
        field2: atom2?.count ?? 0,
    };
}

// ─────────────────────────────────────────────────────────────────────────────
// Reactive Global
// ─────────────────────────────────────────────────────────────────────────────

const <globalName>Global = createReactiveGlobal<<GlobalName>>({
    name: '<globalName>',
    atomKeys: ['sourceAtom1', 'sourceAtom2'],  // Atoms to watch
    derive: derive<GlobalName>,
});

// ─────────────────────────────────────────────────────────────────────────────
// Public API
// ─────────────────────────────────────────────────────────────────────────────

let instance: GlobalVariable<<GlobalName>> | null = null;

export function get<GlobalName>(): GlobalVariable<<GlobalName>> {
    if (!instance) {
        instance = <globalName>Global;
    }
    return instance;
}
```

---

## Step 3: Register

### In `src/globals/index.ts`

```typescript
export { get<GlobalName> } from './variables/<globalName>';
export type { <GlobalName> } from './variables/<globalName>';
```

### In `src/api/index.ts` (if public)

```typescript
import { get<GlobalName> } from '../globals';

Globals: {
    // ... existing
    <globalName>: get<GlobalName>(),
}
```

---

## Step 4: Validate

### Structure
- [ ] File created in `src/globals/variables/<name>.ts`
- [ ] Type interface defined
- [ ] Derivation function implemented
- [ ] `createReactiveGlobal()` with correct `atomKeys`
- [ ] Lazy singleton getter exported

### API
- [ ] `get()` returns current value
- [ ] `subscribe(callback)` receives all updates
- [ ] `subscribeStable(callback)` receives meaningful updates only
- [ ] `destroy()` is idempotent

### Registration
- [ ] Exported from `src/globals/index.ts`
- [ ] Exposed in `src/api/index.ts` (if public)

---

## Usage Patterns

### Basic subscription
```typescript
const global = get<GlobalName>();

// Get current value
const value = global.get();

// Subscribe to all changes
const unsub = global.subscribe((value) => {
    console.log('Updated:', value);
});

// Cleanup
unsub();
```

### Stable subscription (less frequent)
```typescript
const unsub = global.subscribeStable((value) => {
    // Only fires on meaningful changes
    updateUI(value);
});
```

### In components/features
```typescript
const cleanups: (() => void)[] = [];

function start(): void {
    const unsub = get<GlobalName>().subscribe((value) => {
        onValueChange(value);
    });
    cleanups.push(unsub);
}

function stop(): void {
    cleanups.forEach(fn => fn());
    cleanups.length = 0;
}
```

---

## References

- Rules: `.claude/rules/state/globals.md`
- Existing globals: `src/globals/variables/`
- Core: `src/globals/core/`

Related Skills

global-standards

16
from diegosouzapw/awesome-omni-skill

Project-wide coding standards and conventions specialist. Use PROACTIVELY when writing code, making architectural decisions, or establishing project conventions. Covers coding style, commenting, error handling, validation, tech stack consistency, and project conventions across all languages and frameworks.

global-methylation-profile

16
from diegosouzapw/awesome-omni-skill

This skill performs genome-wide DNA methylation profiling. It supports single-sample and multi-sample workflows to compute methylation density distributions, genomic feature distribution of the methylation profile, and sample-level clustering/PCA. Use it when you want to systematically characterize global methylation patterns from WGBS or similar per-CpG methylation call files.

Global Error Handling

16
from diegosouzapw/awesome-omni-skill

Your approach to handling global error handling. Use this skill when working on files where global error handling comes into play.

globalexceptionhandler-class

16
from diegosouzapw/awesome-omni-skill

Structure of GlobalExceptionHandler class.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

n8n-node-configuration

16
from diegosouzapw/awesome-omni-skill

Operation-aware node configuration guidance. Use when configuring nodes, understanding property dependencies, determining required fields, choosing between get_node detail levels, or learning common configuration patterns by node type.

n8n-code-python

16
from diegosouzapw/awesome-omni-skill

Write Python code in n8n Code nodes. Use when writing Python in n8n, using _input/_json/_node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes.

n8n-builder

16
from diegosouzapw/awesome-omni-skill

Expert n8n workflow builder that creates, deploys, and manages n8n workflows programmatically via the n8n REST API. Use when asked to create n8n workflows, automate n8n tasks, build automations, design workflow pipelines, connect services via n8n, or manage existing n8n workflows. Handles webhook flows, scheduled tasks, AI agents, database syncs, conditional logic, error handling, and any n8n node configuration.

N+1 Query Detection

16
from diegosouzapw/awesome-omni-skill

Detect N+1 query patterns in GORM repository and service code — identify loops that execute queries, missing preloads, and unbounded fetches

myth

16
from diegosouzapw/awesome-omni-skill

Complete guide for using the Myth .NET ecosystem - enterprise-grade libraries for building scalable applications with SOLID principles, clean architecture, CQRS, validation, pipelines, and DDD patterns

mypy

16
from diegosouzapw/awesome-omni-skill

mypy - Static type checker for Python with gradual typing, strict mode, Protocol support, and framework integration

mypa

16
from diegosouzapw/awesome-omni-skill

Personal communication hub. Send tezits to family/team members, manage messages, get briefings, interrogate context, and share mirrors. Voice-first with Library of Context preservation and Tezit Protocol support.