home / skills / oimiragieo / agent-studio / toon-format

This skill reviews JavaScript code for TOON format compliance, suggests improvements, and explains why patterns align with toon guidelines.

npx playbooks add skill oimiragieo/agent-studio --skill toon-format

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
5.7 KB
---
name: toon-format
description: TOON Format Rules for Claude Code
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]

best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Toon Format Skill

<identity>
You are a coding standards expert specializing in toon format.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

# TOON Format Rules for Claude Code

## Overview

**Token-Oriented Object Notation (TOON)** is a compact, human-readable serialization format designed for LLM prompts. TOON provides approximately **50% token savings** compared to JSON for uniform tabular data.

**Reference**: [TOON GitHub](https://github.com/toon-format/toon) | [TOON Spec v1.3](https://github.com/toon-format/toon/blob/main/SPEC.md)

## When to Use TOON

Use TOON format when:

- **Uniform arrays of objects** - Same fields, primitive values only
- **Large datasets** with consistent structure
- **Token efficiency** is a priority (LLM input/output)
- **Data is consumed by LLMs** (not APIs or storage)

### Example: Good TOON Use Case

```toon
users[3]{id,name,role,lastLogin}:
  1,Alice,admin,2025-01-15T10:30:00Z
  2,Bob,user,2025-01-14T15:22:00Z
  3,Charlie,user,2025-01-13T09:45:00Z
```

**Token savings**: ~50% vs equivalent JSON

## When NOT to Use TOON

Do NOT use TOON when:

- **Non-uniform data structures** - Mixed types, varying fields
- **Deeply nested objects** - Complex hierarchies
- **API responses** - Standard JSON expected
- **Storage formats** - JSON compatibility required
- **Objects with varying field sets** - Each object has different keys

### Example: JSON is Better Here

```json
{
  "user": {
    "profile": {
      "settings": { "theme": "dark" }
    }
  },
  "items": [1, { "a": 1 }, "x"]
}
```

This mixed structure should use JSON, not TOON.

## Syntax Guidelines

### Basic Rules

1. **2-space indentation** - Standard for nested structures
2. **Tabular format** - For uniform object arrays (use when possible)
3. **List format** - For mixed/non-uniform data
4. **Length markers** - Array headers show count: `items[2]`
5. **Field headers** - Tabular arrays include field names: `items[2]{id,qty,price}:`

### Format Examples

**Object:**

```
id: 1
name: Ada
```

**Primitive array (inline):**

```
tags[2]: reading,gaming
```

**Tabular array (uniform objects):**

```
items[2]{sku,qty,price}:
  A1,2,9.99
  B2,1,14.50
```

**List format (non-uniform):**

```
items[3]:
  - 1
  - a: 1
  - x
```

## Using TOON in Claude Code

### For Input (Sending Data to Claude)

1. **Wrap in fenced code block** - Use ` ```toon` label for clarity
2. **Structure is self-documenting** - The format syntax is usually sufficient
3. **Explicit length markers** - Help Claude track structure, especially for large tables

**Example:**

````
Here's the user data:

```toon
users[3]{id,name,role}:
  1,Alice,admin
  2,Bob,user
  3,Charlie,user
````

Please analyze the user roles.

```

### For Output (Claude Generating TOON)

When requesting Claude to generate TOON:

1. **Show the expected header format** - `users[N]{id,name,role}:`
2. **State the rules explicitly** - 2-space indent, `[N]` matches row count
3. **Provide a template** - Show what format you expect

**Example:**
```

Return the filtered users in TOON format:

```toon
users[N]{id,name,role}:
  [rows here]
```

Rules: 2-space indent, [N] matches actual row count, no trailing spaces.

```

### Integration with Claude Projects and Artifacts

- **Artifacts**: TOON can be used in artifact specifications for structured data
- **Subagents**: Reference TOON rules when subagents process tabular data
- **Hooks**: Use TOON format in hook data if passing structured data between hooks

## Advanced Options

### Custom Delimiters

For large uniform tables, consider tab delimiters:

```

items[2|]{sku|name|qty}:
A1|Widget|2
B2|Gadget|1

```

Tabs (`\t`) can provide additional token savings but may have display issues in some editors.

### Length Marker

Optional hash prefix for clarity:

```

tags[#3]: reading,gaming,coding
items[#2]{sku,qty}: A1,2 B2,1

```

## Decision Tree

1. **Is the data uniform arrays of objects with same fields?**
   - ✅ YES → Use TOON tabular format
   - ❌ NO → Continue

2. **Is the data mixed types or varying structures?**
   - ✅ YES → Use JSON
   - ❌ NO → Continue

3. **Is token efficiency important?**
   - ✅ YES → Use TOON list format for simple arrays
   - ❌ NO → Use JSON

4. **Is this for API or storage?**
   - ✅ YES → Use JSON
   - ❌ NO → Consider TOON if uniform

## Implementation Notes

- **Show format, don't describe** - The TOON structure is self-documenting
- **Link to spec** - Reference TOON spec for edge cases and full syntax
- **Token counts vary** - Benchmarks use GPT-style tokenizers; actual savings may differ
- **Not a drop-in replacement** - TOON is for LLM prompts, not general-purpose JSON replacement
```

</instructions>

<examples>
Example usage:
```
User: "Review this code for toon format compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill helps developers apply TOON (Token-Oriented Object Notation) rules when producing or reviewing prompt-friendly tabular data for Claude. It focuses on token-efficient, uniform arrays of objects and prescribes clear, minimal syntax and structure for input and output. The goal is compact, predictable representations that reduce token usage while keeping data human-readable.

How this skill works

The skill inspects data structures and determines whether TOON is appropriate by checking uniformity, field consistency, and nesting depth. It enforces header formats (name[N]{fields}:), 2-space indentation, explicit length markers, and tabular vs list selection rules. It also suggests delimiters, templates for Claude input/output, and refactors non-uniform data into JSON where TOON is not suitable.

When to use it

  • When you have large uniform arrays of objects with identical primitive fields
  • When token efficiency for LLM prompts is important
  • When data will be consumed directly by Claude or other LLMs, not an API expecting JSON
  • When you need self-documenting, compact tabular representations for prompts
  • When preparing artifact specifications or hook payloads for subagents that accept TOON

Best practices

  • Prefer tabular TOON for uniform rows: include a header with exact field order and a correct [N] count
  • Use 2-space indentation and avoid trailing spaces to keep format consistent
  • Use list format or JSON for mixed or deeply nested data—do not force TOON on non-uniform structures
  • Provide a template header in prompts so Claude returns data in the expected TOON layout
  • Use explicit length markers (N or #N) for large tables so row counts are verifiable

Example use cases

  • Sending a large user table to Claude for role analysis using users[3]{id,name,role}:
  • Requesting Claude to output filtered rows in TOON by supplying a template header and rules
  • Compressing uniform product catalogs for prompt-based transformations to reduce token cost
  • Embedding TOON-formatted artifacts in a project spec consumed by subagents that read plain text
  • Choosing JSON for API responses while using TOON inside prompt bodies passed to the model

FAQ

Can TOON represent nested objects or arrays?

No—avoid TOON for deep nesting. Use JSON when structures are hierarchical or fields vary between objects.

How strict must the [N] length marker be?

It should match the actual row count. Use #[N] optionally for clarity. Mismatched counts reduce reliability and may confuse model parsing.