tonl
CLAUDE.md831 starsChanged 6 months agoMITView on GitHub
TONL (Token-Optimized Notation Language) is a TypeScript library that provides a text-first, LLM-friendly serialization format designed to reduce token costs in language model prompts while maintaining human readability. The project offers both a programmatic API and CLI tool for converting between JSON and TONL formats. Run specific test categories: - Core functionality: node --test test/encode_decode_roundtrip.test.ts test/parser.test.ts - Schema validation: node --test test/schema.test.ts test/schema-constraints.test.ts - Query system: node --test test/query-*.test.ts - Modification API: node --test test/modification-*.test.ts - Streaming: node --test test/stream.test.ts
1 other project uses a version of this.
Adopted by
Most recently taken up by
- ersinkoc/tonlword for word, first seen Oct 8, 2026
Other versions1 project uses a version of this.
Word for word · 1
- ersinkoc/tonl★ 831100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
14 rules. About 0 are common, 5 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
Run specific test categories:
- Very specific: line 62
content-parser.ts: - Document-level parsing orchestration - Very specific: line 135
Build: Run npm run build to compile to dist/ (required before testing)
- Very specific: line 136
Test: Run npm test to verify functionality, npm test:all for comprehensive testing
- Very specific: line 137
Examples: Run npm run test:examples to validate all feature examples
- Very specific: line 138
CLI Testing: Use npm run link to install CLI locally for development
- Very specific: line 139
Browser Testing: Use npm run build:browser to generate browser builds
- Very specific: line 140
Benchmark: Use npm run bench* commands for performance analysis
- Very specific: line 141
Query Performance: Test with npm run bench-query for query optimization
- Very specific: line 146
Test suite in test/ with comprehensive feature coverage (46 test suites)
- Distinctive: line 168
Delimiter handling: All supported delimiters with auto-detection
- Distinctive: line 174
Schema Validation: All 13 constraint types, error reporting, type generation
- Distinctive: line 184
Example validation: All documented examples are tested automatically
- Distinctive: line 186
When adding new features, ensure:
≈ “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.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
TONL (Token-Optimized Notation Language) is a TypeScript library that provides a text-first, LLM-friendly serialization format designed to reduce token costs in language model prompts while maintaining human readability. The project offers both a programmatic API and CLI tool for converting between JSON and TONL formats.
Development Commands
# Build and test
npm run build # TypeScript compilation
npm run build:browser # Generate browser builds (ESM, UMD, IIFE)
npm run build:all # Build both Node.js and browser versions
npm test # Build and run stable test suite
npm run test:all # Build and run all tests including comprehensive
npm run test:examples # Build and validate all feature examples
npm run dev # Watch mode development
npm run clean # Clean build artifacts
# Benchmarking and performance analysis
npm run bench # Byte size compression analysis
npm run bench-tokens # Token estimation across multiple LLM models
npm run bench-comprehensive # Full performance analysis
npm run bench-query # Query system performance testing
# CLI development
npm run link # Install tonl command locally for testingTesting
- Framework: Node.js built-in test runner (
node:test) - Test files: 46 comprehensive test suites covering all modules
- Coverage: 100% test coverage (791+ tests passing)
- Test command:
npm test(runs stable test suite),npm test:all(runs all tests) - Feature coverage:
npm run test:featuresvalidates complete feature set
Run specific test categories:
- Core functionality:
node --test test/encode_decode_roundtrip.test.ts test/parser.test.ts - Schema validation:
node --test test/schema.test.ts test/schema-constraints.test.ts - Query system:
node --test test/query-*.test.ts - Modification API:
node --test test/modification-*.test.ts - Streaming:
node --test test/stream.test.ts
Architecture
Core Components (src/)
types.ts- Core type definitions and interfaces for the TONL formatindex.ts- Main entry point exporting public API (encodeTONL,decodeTONL,encodeSmart,TONLDocument)document.ts- TONLDocument class providing high-level document API (query, navigation, modification)encode.ts- JSON to TONL conversion with nested structure supportdecode.ts- TONL to JSON conversion (orchestrates modular parser)parser.ts- Low-level parsing utilities for TONL lines, headers, and delimiter detectioninfer.ts- Type inference and coercion utilitiescli.ts- Command-line interface withencode,decode,stats,format,validate,query,generate-typescommands
Parser Modules (src/parser/)
content-parser.ts- Document-level parsing orchestrationblock-parser.ts- Multi-line block and array parsingvalue-parser.ts- Single-line object and inline value parsingline-parser.ts- Primitive value parsingutils.ts- Parser helper functionsindex.ts- Public parser exports
Feature Modules (src/)
query/- JSONPath-like query system with filtering, caching, and performance optimizationnavigation/- Tree traversal API with iterators, walkers, and navigation utilitiesmodification/- Complete CRUD operations, transactions, change tracking, and file editingindexing/- Performance indexing system (Hash, BTree, Compound) for fast queriesschema/- Schema validation, type generation, and constraint enforcementstream/- Streaming API for large files with encode/decode streams and query pipelinesrepl/- Interactive REPL for exploring TONL documentserrors/- Centralized error handling and custom error types
Utility Modules (src/utils/)
strings.ts- String handling, quoting, escaping, and indentation utilitiesmetrics.ts- Token estimation across multiple LLM tokenizers (GPT-5, Claude 3.5, Gemini 2.0, Llama 4)
Browser Support (src/browser-*.ts)
browser.ts- Browser-optimized entry pointdocument-browser.ts- Browser-compatible TONLDocumentbrowser-core.ts- Core browser utilitiesbrowser-simple.ts- Lightweight browser API
Key Features
- TONLDocument API: High-level document interface with query, navigation, and modification
- Smart Encoding: Automatically analyzes content to choose optimal delimiters and formatting
- JSONPath Queries: Advanced query system with filtering and caching
- Complete CRUD: Full modification API with transactions and change tracking
- Performance Indexing: Multiple index types for optimized queries
- Schema Validation: Comprehensive validation with 13 constraint types
- Streaming Support: Handle large files with minimal memory usage
- Multi-delimiter Support:
,,|,\t,;with auto-detection - Type Hints: Optional schema information for validation
- Round-trip Safety: Perfect bidirectional conversion with JSON
- Token Optimization: 32-45% token reduction compared to JSON
CLI Usage Examples
# Encode JSON to TONL with smart optimization
tonl encode data.json --out data.tonl --smart --stats
# Decode TONL back to JSON
tonl decode data.tonl --out data.json
# Query TONL files with JSONPath expressions
tonl query data.tonl "users[?(@.age > 25)]"
tonl get data.tonl "users[0].email"
# Validate against schema
tonl validate data.tonl --schema schema.tonl
# Compare token costs across different models
tonl stats data.json --tokenizer gpt-5
# Format TONL file with specific delimiter
tonl format data.tonl --delimiter "," --out formatted.tonl
# Generate TypeScript types from schema
tonl generate-types schema.tonl --out types.tsDevelopment Workflow
- Changes: Edit TypeScript files in
src/ - Build: Run
npm run buildto compile todist/(required before testing) - Test: Run
npm testto verify functionality,npm test:allfor comprehensive testing - Examples: Run
npm run test:examplesto validate all feature examples - CLI Testing: Use
npm run linkto install CLI locally for development - Browser Testing: Use
npm run build:browserto generate browser builds - Benchmark: Use
npm run bench*commands for performance analysis - Query Performance: Test with
npm run bench-queryfor query optimization
File Structure Patterns
- Source code in
src/with modular separation by feature - Test suite in
test/with comprehensive feature coverage (46 test suites) - Examples in
examples/demonstrating all major features and use cases - Benchmarks in
bench/with sample fixtures inbench/fixtures/ - Compiled output in
dist/(auto-generated, includes browser builds) - Documentation in
docs/(API.md, CLI.md, SPECIFICATION.md, etc.) - Browser builds in
dist/browser/(ESM, UMD, IIFE formats)
Configuration
- TypeScript: ES2022 target, strict mode enabled
- Module System: ES modules with
"type": "module" - Node.js: Requires >= 18.0.0
- Dependencies: Zero runtime dependencies (pure TypeScript)
- CLI: Distributed as
dist/cli.jswithtonlcommand
Testing Strategy
The test suite provides comprehensive coverage across all features:
Core Functionality
- Round-trip fidelity: Perfect encode/decode accuracy for all data types
- Edge cases: Special characters, multiline strings, complex nesting
- Delimiter handling: All supported delimiters with auto-detection
- Error handling: Robust error recovery and validation
Feature-Specific Testing
- Query System: JSONPath expressions, filtering, caching, performance
- Modification API: CRUD operations, transactions, change tracking
- Schema Validation: All 13 constraint types, error reporting, type generation
- Indexing: Hash, BTree, and compound index performance
- Streaming: Large file handling, encode/decode streams, memory efficiency
- Navigation: Tree traversal, iterators, walkers, path finding
Quality Assurance
- 791+ tests across 46 test suites with 100% coverage
- Feature integration: End-to-end testing of complete workflows
- Performance benchmarks: Comprehensive performance analysis
- Security testing: 96 security-focused tests preventing vulnerabilities
- Example validation: All documented examples are tested automatically
When adding new features, ensure:
- Comprehensive test coverage for the new functionality
- Integration tests with existing features
- Performance benchmarks where applicable
- Security tests for any new attack surfaces
- Documentation examples are included in test suite
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
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.

