Skip to main content
rule CX Codex

advanced-init-once — Claude Code rule: what it does, how to install

advanced-init-once prevents running app-wide startup logic inside component useEffect([]) hooks and suggests module-level guards or top-level initialization instead.

MIT ★ 7,191 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/advanced-init-once.md
Open on GitHub

What advanced-init-once does

This rule stops the agent from placing app-wide startup logic inside a component's useEffect([]). React components remount and re-run effects, causing startup routines like token checks or storage reads to fire twice in development.

The instruction directs Claude Code to either place one-time initialization at the entry module level or guard it with a module-level variable like didInit. This ensures functions such as checkAuthToken() execute strictly once per application lifecycle.

Without a module-level guard, React's development mode will trigger the effect multiple times on mount.

What it helps with

  • prevent duplicate startup logic when components remount
  • stop double authorization checks during development
  • move application initialization to the entry module level
  • guard component useEffect hooks with a module-level boolean

Example prompts for the agent

  • Check the app initialization in the auth component and prevent duplicate runs
  • Move startup data loading out of useEffect to the entry module
  • Add a module-level guard for checkAuthToken() on component remount

How to install advanced-init-once

Manually: put the files in place

.claude/rules/advanced-init-once.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about advanced-init-once

How to install advanced-init-once in Claude Code?

Save the rule into .claude/rules/advanced-init-once.md in your project root.

What does the advanced-init-once rule do?

It prevents Claude Code from placing app-wide startup code inside component useEffect hooks with empty dependency arrays. This avoids redundant network calls and token checks during remounts.

How does the rule handle initialization instead of useEffect?

It advises placing the setup code at the entry module top level or setting a module-level guard like didInit = true inside the effect.

Source text

advanced-init-once.md · MIT
---
title: Initialize App Once, Not Per Mount
impact: LOW-MEDIUM
impactDescription: avoids duplicate init in development
tags: initialization, useEffect, app-startup, side-effects
---

## Initialize App Once, Not Per Mount

Do not put app-wide initialization that must run once per app load inside `useEffect([])` of a component. Components can remount and effects will re-run. Use a module-level guard or top-level init in the entry module instead.

**Incorrect (runs twice in dev, re-runs on remount):**

```tsx
function Comp() {
  useEffect(() => {
    loadFromStorage()
    checkAuthToken()
  }, [])

  // ...
}
```

**Correct (once per app load):**

```tsx
let didInit = false

function Comp() {
  useEffect(() => {
    if (didInit) return
    didInit = true
    loadFromStorage()
    checkAuthToken()
  }, [])

  // ...
}
```

Reference: [Initializing the application](https://react.dev/learn/you-might-not-need-an-effect#initializing-the-application)

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
rendering-hydration-suppress-warning rendering-hydration-suppress-warning silences hydration warnings where the two renders are meant to differ: timestamps, per-render IDs, dates formatted for the visitor's locale. CX Codex +1 ★ 7,191repo stars bundle-defer-third-party bundle-defer-third-party prevents third-party trackers from inflating the initial bundle. It instructs the assistant to load analytics and monitoring after hydration. CX Codex +1 ★ 7,191repo stars bundle-conditional The bundle-conditional rule recommends loading large modules only when their feature is activated. It applies to lazy-loaded data and browser-only code in SSR builds. CX Codex +1 ★ 7,191repo stars react19-no-forwardref react19-no-forwardref is a Claude Code rule covering React 19 ref and context changes: pass ref as a prop and use use() instead of useContext(). It supports React 19 migrations. CX Codex +1 ★ 7,191repo stars rerender-defer-reads The rerender-defer-reads rule keeps callback-only reads of dynamic state out of component subscriptions. Use it when searchParams or localStorage is needed only after an action. CX Codex +1 ★ 7,191repo stars rendering-conditional-render The rendering-conditional-render rule prevents accidental rendering of zeros and NaN in JSX. It enforces explicit ternary operators instead of && checks, so falsy values stay out of the DOM. CX Codex +1 ★ 7,191repo stars server-serialization server-serialization is a Claude Code rule for limiting data passed across React Server/Client boundaries. It applies when client components receive props from server components. CX Codex +1 ★ 7,191repo stars rerender-simple-expression-in-memo The rerender-simple-expression-in-memo rule advises against using useMemo for simple expressions that return a boolean, number, or string. It applies when reviewing React component calculations. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open