token-aware-chunking

token-aware-chunking is a skill for Claude Code, Codex from alivirgo/Major-AI-Skills. It costs 23 tokens per session (1,220 once invoked), scanned A, original, MIT.

A method for splitting technical documentation and source code into search-sized sections using token counts and natural code or Markdown boundaries. Tokens are the text units used by language models.

In plain words
What is it for?
It prepares code and documentation for vector search and retrieval-augmented generation by splitting at headings, function blocks, and paragraph boundaries.
Why use it?
It avoids cutting code, words, or documentation sections apart and helps keep each section within an embedding model's input limit.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions Codex.

Part of the mas-efficiency-pack plugin — 5 skills shipped together

Good fit It prepares code and documentation for vector search and retrieval-augmented generation by splitting at headings, function blocks, and paragraph boundaries.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/alivirgo/major-ai-skills/token-aware-chunking
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.

Any agent
npx skills add alivirgo/Major-AI-Skills --skill token-aware-chunking
Clone the repo
git clone --depth 1 https://github.com/alivirgo/Major-AI-Skills

Made for: Claude Code, Codex.

Or install mas-efficiency-pack, the plugin that ships this one along with the rest of its 5 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for token-aware-chunking

README.md
[![agentmods](https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/token-aware-chunking/github.svg)](https://agentmods.dev/skills/alivirgo/major-ai-skills/token-aware-chunking)
Your own site
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/token-aware-chunking"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/token-aware-chunking/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for token-aware-chunking

Your own site · 80×15
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/token-aware-chunking"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/token-aware-chunking.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 23 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,220 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00023 $0.01220
Opus 5 $0.00012 $0.00610
Sonnet 5 $0.00005 $0.00244
Haiku 4.5 $0.00002 $0.00122

Measured today against content hash 9443023b51f9, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

token-aware-chunking 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 today.

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.

plugins/mas-efficiency-pack/skills/token-aware-chunking/SKILL.md · 131 lines

How it starts

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

Token-Aware Semantic Chunking Protocol (Boundary-Aligned RAG Slicing)

Overview

When indexing documentation or codebases for vector search and RAG retrieval, naive splitters slice text by fixed character counts (text[i:i+2000]).

Fixed-character chunking causes severe retrieval degradations:

  1. Broken Code Blocks: Splits a TypeScript interface or Python function midway through its body, creating unparseable syntax fragments.
  2. Mid-Word Token Clipping: Slices words across token boundaries, corrupting embedding vector representations.
  3. Embedding Model Ceiling Exceedance: A character count that translates to 8,250 tokens gets silently truncated by an embedding model with an 8,192-token ceiling.

The Token-Aware Semantic Chunking Protocol measures chunk size strictly using the target tokenizer (tiktoken / BPE) and splits text recursively along semantic boundaries (Markdown Headers, AST Function Blocks, Double Newlines).


Fixed-Character Slicing vs. Token-Aware Semantic Chunking

┌─────────────────────────────────────────────────────────────┐
│                 Text Chunking Mechanics                     │
│                                                             │
│  Fixed Character Slicing (`len(text) == 2000`):             │
│  • Chunk 1 ends: `function calculateTotal(price: num`       │
│  • Chunk 2 starts: `ber, tax: number) { return price + ...` │
│  ↳ Syntax broken across 2 chunks! Vector embedding corrupted│
│                                                             │
│  Token-Aware Semantic Slicing (512 Tokens / AST Boundary):  │
│  • Chunk 1: Complete `calculateTotal` function + docstring  │
│  • Chunk 2: Complete `processPayment` function              │
│  ↳ 100% Valid code syntax, exact 512-token budget adherence │
└─────────────────────────────────────────────────────────────┘

The 4-Tier Semantic Split Hierarchy

When partitioning text into token-bounded chunks, search for split delimiters in descending priority:

Read the full file on GitHub · 131 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. today Changed · -20 tokens per session 9443023b51f9
  2. 11d ago First seen · 131 lines · 43 tokens per session scan A 38a6bff88e80

Subscribe to this mod's changes

token-aware-chunking is a skill published in the GitHub repository alivirgo/Major-AI-Skills (1 stars, last pushed today), licensed MIT. It adds 23 tokens to every session and 1,220 once invoked, about $0.0001 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-31.

Related

Other skills, from other repositories

andrej-karpathy-v2

ANDREJ KARPATHY — SKILL COMPLETA v2.0 workflow skill. Use this skill when the user needs Agente que simula Andrej Karpathy — ex-Director of AI da Tesla, co-fundador da OpenAI, fundador da Eureka Labs, e o maior educador de deep learning do mundo and the operator should preserve the upstream workflow, copied support…

diegosouzapw/awesome-omni-skills · 94 tokens

azure-machine-learning

Expert knowledge for Azure Machine Learning development including troubleshooting, best practices, decision making, architecture & design patterns, limits & quotas, security, configuration, integrations & coding patterns, and deployment. Use when running AutoML jobs, Prompt Flow/RAG, online endpoints, feature stores…

MicrosoftDocs/Agent-Skills · 127 tokens

azure-data-factory

Expert knowledge for Azure Data Factory development including troubleshooting, best practices, decision making, architecture & design patterns, limits & quotas, security, configuration, integrations & coding patterns, and deployment. Use when building ADF pipelines, mapping data flows, SSIS IR/SHIR, CI/CD deployments…

MicrosoftDocs/Agent-Skills · 127 tokens

azure-databricks

Expert knowledge for Azure Databricks development including troubleshooting, best practices, decision making, architecture & design patterns, limits & quotas, security, configuration, integrations & coding patterns, and deployment. Use when using Unity Catalog, Lakeflow pipelines, Genie/AI Runtime, Delta…

MicrosoftDocs/Agent-Skills · 124 tokens

azure-hdinsight

Expert knowledge for Azure HDInsight development including troubleshooting, best practices, decision making, architecture & design patterns, limits & quotas, security, configuration, integrations & coding patterns, and deployment. Use when working with HDInsight Spark/Hive/Kafka/HBase clusters, Ambari/Oozie pipelines…

MicrosoftDocs/Agent-Skills · 119 tokens

ai-wrapper-product-v2

AI Wrapper Product workflow skill. Use this skill when the user needs Expert in building products that wrap AI APIs (OpenAI, Anthropic, and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing off.

diegosouzapw/awesome-omni-skills · 55 tokens