top-down-typescript

A TypeScript and JavaScript style guide that puts the main caller before the helper functions it uses and favors functions over classes. It also covers unused code, blank lines, comments, and linter changes.

In plain words
What is it for?
Use it before writing or reviewing TypeScript or JavaScript code, including code included in specifications or implementation plans.
Why use it?
It makes source files read from the main behavior down to the details, so developers can understand the overall flow first. Consistent ordering also makes code reviews and agent-written changes easier to follow.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/paleo/alignfirst/top-down-typescript
Any agent
npx skills add paleo/alignfirst --skill top-down-typescript
Clone the repo
git clone --depth 1 https://github.com/paleo/alignfirst

Made for: Claude Code, Codex.

Per session 53 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,464 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00053 $0.02464
Opus 5 $0.00026 $0.01232
Sonnet 5 $0.00011 $0.00493
Haiku 4.5 $0.00005 $0.00246

Measured 2d ago against content hash 0c7fb229567d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

top-down-typescript scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/top-down-typescript/SKILL.md · 229 lines

How it starts

The opening of the file, as written. The whole thing — 229 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Top-Down TypeScript Coding Style

General Rules

  • Dead (unused) code SHOULD NOT be kept (YAGNI principle).
  • Do not write multiple consecutive blank lines.
  • Changes to linter rules MUST be discussed before being implemented.
  • Code SHOULD NOT contain commented-out code, unless a comment explains why.

Code Organization

Usage comes first, implementation after. Exception: with inheritance — when an interface extends another, write the parent first.

  • Order code top-down: each file reads as a story, from entry point to leaves. The reader meets the highest-level thing first, then drills down into its dependencies:

    // 1. Imports
    import { ... } from "...";
    
    // 2. Module-level constants and variables (exported first, then internal)
    export const PUBLIC_CONST = ...;
    const INTERNAL_CONST = ...;
    
    // 3. Shared types — main type first, then types it references
    export interface MainType {
      detail: DetailType;
    }
    export interface DetailType { ... }
    
    // 4. Entry-point (exported) function
    export function doThing() {
      stepOne();
      stepTwo();
    }
    
    // 5. Internal functions called by the entry point, in call order
    function stepOne() {
      stepOneHelper();
    }
    function stepOneHelper() { ... }
    
    function stepTwo() { ... }
    
  • Module-level constants and variables (const, let, var value declarations at the top of the file — both exported and internal) MUST be placed immediately after imports, before any type definitions, functions, or classes. The reader sees them first and treats them as the file's configuration surface.

  • Functions: write the caller first, then the functions it calls, recursively. A helper appears just below its caller, not grouped at the bottom of the file. If a helper is called by several siblings, place it after its first caller.

  • Types: write the main (top-level) type first, then the types it references, recursively. Same top-down rule as functions.

  • Types attached to a single function (or class, or other declaration) — i.e. used only in that one signature, like a MyComponentProps interface used only by MyComponent — must be placed immediately before that declaration, not in the top type block.

  • Exports are not a sorting criterion on their own: a function being exported does not pull it to the top — its position is determined by who calls it. The entry points of a file are usually exported, which is why they tend to appear first, but that is a consequence of the top-down rule, not the rule itself.

Read the full file on GitHub · 229 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 229 lines · 53 tokens per session scan A 0c7fb229567d

Subscribe to this mod's changes

top-down-typescript is a skill published in the GitHub repository paleo/alignfirst (85 stars, last pushed 3d ago), licensed CC0-1.0. It adds 53 tokens to every session and 2,464 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.