agentleFS
tuanngocptntuanngocptn/nport/CLAUDE.md

nport

CLAUDE.md769 starsChanged 8 months agoMITView on GitHub

See also .claude/rules/ for detailed per-topic rules (TypeScript style, patterns, common tasks, project overview). NPort is a free, open-source ngrok alternative that creates secure HTTP/HTTPS tunnels from localhost to public URLs using Cloudflare's global edge network. It has three components: Traffic flow: Browser → myapp.nport.link → Cloudflare Edge → cloudflared → localhost:port CI uses npm ci --ignore-scripts for the CLI to skip cloudflared download.

  • Installs packages
  • In this repositoryOne other file it gives its agents.

The file

We split this CLAUDE.md into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    ESM throughout: Always use .js extension in relative imports (this is required, not optional)

    line 48
  2. Very specific:

    Type imports: Always use import type { ...

    line 49
  3. Very specific:

    Prefer interface for object shapes, type for unions/aliases

    line 52

≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

See also .claude/rules/ for detailed per-topic rules (TypeScript style, patterns, common tasks, project overview).

Project Overview

NPort is a free, open-source ngrok alternative that creates secure HTTP/HTTPS tunnels from localhost to public URLs using Cloudflare's global edge network. It has three components:

  1. CLI (src/) — TypeScript command-line tool bundled via esbuild
  2. Backend (server/) — Cloudflare Worker that manages tunnel lifecycle (creates/deletes tunnels + DNS via Cloudflare APIs)
  3. cloudflared binary (bin/) — Downloaded at install/first-run; handles the actual tunnel connection

Traffic flow: Browser → myapp.nport.link → Cloudflare Edge → cloudflared → localhost:port


Commands

CLI (root directory)

npm install        # Installs deps + downloads cloudflared (postinstall hook)
npm run build      # esbuild → dist/index.js
npm run dev        # esbuild --watch (fast, no minification)
npm start          # node dist/index.js
npm test           # vitest run (tests/**/*.test.ts)
npm run test:watch # vitest --watch
npm run lint       # tsc --noEmit

Server (server/ directory)

cd server
npm install
npm run dev        # wrangler dev (local CF Workers preview)
npm run deploy     # wrangler deploy
npm test           # vitest run
npm run typecheck  # tsc --noEmit

TypeScript Conventions

  • ESM throughout: Always use .js extension in relative imports (this is required, not optional)
  • Type imports: Always use import type { ... } for type-only imports
  • Import order: external packages → internal modules → types
  • strict: true — full type safety; avoid any
  • Prefer interface for object shapes, type for unions/aliases
// ✅ Correct
import axios from 'axios';
import { CONFIG } from './config.js';
import type { TunnelConfig } from './types/index.js';

// ❌ Wrong — no .js extension, uses `any`
import { something } from './module';
function process(data: any) { ... }

Key Modules

FileResponsibility
src/tunnel.tsTunnelOrchestrator.start() / cleanup() — orchestrates entire tunnel lifecycle
src/api.tsAPIClient — POST create / DELETE delete against backend
src/binary.tsBinaryManager — validates, spawns, and handles cloudflared stdout/stderr
src/bin-manager.tsensureCloudflared() — downloads cloudflared from GitHub (platform-specific)
src/state.tsTunnelState singleton — runtime state (tunnelId, subdomain, port, process)
src/config-manager.tsConfigManager singleton — persists ~/.nport/config.json
src/analytics.tsAnalyticsManager singleton — GA4 Measurement Protocol
server/src/index.tsCF Worker fetch handler + scheduled cleanup (every 30 min)

Configuration Priority (Backend URL)

  1. CLI flag --backend / -b
  2. Saved config ~/.nport/config.json via --set-backend
  3. Environment variable NPORT_BACKEND_URL
  4. Default https://api.nport.link

Environment Variables

VariableEffect
NPORT_BACKEND_URLOverride backend URL
NPORT_ANALYTICS=falseDisable GA4 tracking
NPORT_DEBUG=trueEnable analytics debug logs

CI Pipelines

WorkflowTriggerWhat it does
ci.ymlpush/PR to mainType-check + test CLI; type-check + test server
deploy-server.ymlpush to server/**Deploy CF Worker via wrangler-action
deploy-website.ymlpush to website/**Deploy to Cloudflare Pages
release-npm.ymlGitHub releaseBuild + npm publish

CI uses npm ci --ignore-scripts for the CLI to skip cloudflared download.


Adding a New Language

  1. src/constants.ts → AVAILABLE_LANGUAGES — add language code
  2. src/types/i18n.ts → LanguageCode — add union type
  3. src/lang.ts → TRANSLATIONS — add translation object
  4. npm run build

Adding a CLI Flag

  1. src/args.ts → ArgumentParser — add parsing method
  2. src/types/config.ts → ParsedArguments — add field
  3. src/index.ts → main() — handle the flag
  4. tests/ → add unit tests

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.