hyderhusainarastu/context-window-text-chunking/context-window-text-chunking

Claude Code and agent skill by hyderhusainarastu/context-window-text-chunking

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Splits a long text or markdown document into paragraph-boundary-aware chunks that fit an LLM context window, with optional overlap. Use when a paper, transcript, extracted PDF text or log is too large for one request and must not be cut mid-paragraph.

Install

npx vskill@latest install hyderhusainarastu/context-window-text-chunking/context-window-text-chunking

SKILL.md

The same SKILL.md was published earlier as hyderhusainarastu/context-window-text-chunking/context-window-text-chunking.

Context-Window Text Chunking

Purpose

Large documents routinely exceed what fits comfortably in a single model request, or exceed a budget you want to hold per request even when the window is technically big enough. The naive fix — cut the text every N characters — routinely severs a sentence mid-word, or worse, separates a claim from the evidence three lines later, right at the cut. This skill packs a document into size-bounded chunks while guaranteeing that no chunk boundary ever falls inside a paragraph. It also supports overlap, so consecutive chunks share a little trailing context instead of a hard cut, which helps when a downstream process (summarization, annotation, extraction) needs to reason across the seam.

This method was developed and proven while processing long extracted-text sources (150-plus-page books and papers) for a scholarly research pipeline, where each chunk had to be handed to a model for close reading and annotation, and where silently splitting a paragraph would have corrupted the annotation's claim-to-evidence linkage. The methodology generalizes to any long-document-into-model-context problem.

When to use this skill

Invoke this skill when:

  • A single document (plain text, markdown, extracted PDF text, transcript,

log) needs to be processed by a model but exceeds the context budget you want to spend on it in one call.

  • You need to preserve paragraph integrity — no chunk may start or end

mid-paragraph, because downstream processing (summarization, claim extraction, annotation, translation) depends on paragraphs staying whole.

  • You want chunks that can be processed independently in sequence (or in

parallel) and later reassembled or cross-referenced, optionally with shared context (overlap) between adjacent chunks.

Do not reach for this skill when:

  • The document already fits inside your context budget — chunking adds

bookkeeping for no benefit.

  • The content is structured data (JSON, CSV, code) rather than prose —

paragraph-boundary chunking assumes blank-line-separated prose; structured formats need a format-aware splitter instead.

  • You need semantic chunking (splitting by topic shift or embedding

similarity rather than by size) — this skill chunks by size with paragraph-boundary preservation, not by meaning.

Core method

  1. Read the whole document into memory. These are text files, not

binary streams; simplicity beats streaming for anything under a few hundred MB.

  1. Split into paragraphs, not lines or sentences. Use a blank-line

separator (one-or-more blank lines) as the paragraph boundary. This is the unit that must never be broken — a paragraph is the smallest chunk of text the method treats as atomic. Strip and discard empty paragraphs produced by leading/trailing whitespace or multiple consecutive blank lines.

  1. Choose a size unit and a target chunk size. Words are usually the

right unit for prose that will go to an LLM, because token count tracks word count far more closely than character count does across languages and vocabularies. Characters are useful when you need a hard byte-ish budget (e.g., a downstream system with a strict character limit) or when the text is not natural-language prose. Pick a target size comfortably under your actual context budget — leave headroom for the prompt wrapper, instructions, and the model's response.

  1. Greedily pack paragraphs into chunks. Walk the paragraph list in

order, accumulating a running size total for the current chunk. Before adding each paragraph, check whether adding it would push the current chunk's total over the target size. If the current chunk already has content and the paragraph would overflow it, close the current chunk and start a new one with that paragraph. Otherwise, append the paragraph and keep going. This is the entire algorithm — no lookahead, no rebalancing, just a running total and one comparison per paragraph.

  1. Handle the oversized-paragraph edge case explicitly. If a single

paragraph is larger than the target chunk size on its own, do not split it — split paragraphs is the one thing this method refuses to do. Let it form its own oversized chunk, and emit a warning so the caller knows a chunk exceeded the target and can decide whether that is acceptable (it usually is — a rare 3000-word paragraph in a 2000-word-target run is a much smaller problem than a paragraph torn in half).

  1. Optionally carry overlap between chunks. When a target overlap size

is set, after closing a chunk, walk backward through that chunk's paragraphs accumulating them until the overlap budget is met, and seed the next chunk with that trailing paragraph run before continuing the forward walk. Overlap must be measured in the same unit as chunk size and must be meaningfully smaller than the chunk size (as a rule of thumb, keep it under half), or the packer stalls: if overlap is close to or larger than the target, the next paragraph after the overlap immediately overflows the chunk again and the chunk barely advances past where the last one ended.

  1. Write chunks with predictable, sortable filenames. Zero-pad the

chunk number to at least two digits (or to the width of the total chunk count, whichever is larger) so that ls / glob ordering matches document order: chunk_01.txt, chunk_02.txt, ... chunk_10.txt sorts correctly; chunk_1.txt ... chunk_10.txt does not.

  1. Verify coverage. Sum the sizes of the written chunks (or, without

overlap, just confirm every paragraph appears in exactly one chunk) and compare against the source document's total size. Coverage should equal 100% without overlap, or be greater than 100% with overlap (since overlapped content is counted twice). Coverage under 100% signals a bug that dropped content — treat it as fatal, not a warning to ignore.

How to execute this skill

Use the bundled script rather than re-deriving the algorithm by hand — it already implements steps 1-8 above, including the oversized-paragraph warning and the coverage check.

bash
python3 scripts/chunk_text.py \
--input your-project/paper/document.txt \
--out-dir your-project/paper/_chunks/document/ \
--chunk-size 4000 \
--unit words \
--overlap 200 \
--manifest

Key flags (see --help for the complete, current list — it is the source of truth if this document and the script ever drift):

  • --input (required): path to the source text file.
  • --out-dir (required): directory the chunks are written into; created if

missing.

  • --chunk-size (default 2000): target size of each chunk, in --unit.
  • --unit (words | chars, default words): the size unit.
  • --overlap (default 0): trailing content, in --unit, repeated at the

start of each next chunk; 0 disables overlap. Must be smaller than --chunk-size.

  • --prefix (default chunk): filename prefix — chunks are written as

<prefix>_01.txt, <prefix>_02.txt, etc.

  • --paragraph-pattern (default \n\s*\n+): regex used to detect paragraph

boundaries; override this if your source uses a non-standard paragraph separator (e.g., a single hard newline per paragraph, or a markdown rule like --- between sections).

  • --manifest: also write manifest.json in --out-dir summarizing every

chunk (filename, paragraph count, size).

  • --dry-run: print chunk boundaries and sizes without writing any files —

use this first to sanity-check a chunk-size/overlap choice before committing to disk output.

Choosing chunk size and overlap

  • Pick --chunk-size well under your model's usable context, not at its

limit. A common starting point is to leave 30-50% of the window for instructions, few-shot material, and the response.

  • Use --overlap when downstream processing needs continuity across chunk

seams (e.g., a model summarizing chunk N benefits from seeing the tail of chunk N-1 for pronoun resolution or thread continuity). Skip overlap entirely (--overlap 0, the default) when chunks are processed fully independently and continuity does not matter — it keeps chunk count and total token spend lower.

  • Run with --dry-run first on a new document to see the resulting chunk

count and sizes before writing files, especially if you are unsure how paragraph lengths in the source are distributed.

Verification checklist before trusting chunk output

  • [ ] Chunk count and per-chunk sizes reported by the script look sane for

the document's total size and your target.

  • [ ] No "oversized paragraph" warning, or if one appears, the flagged

paragraph(s) are genuinely single long blocks in the source (e.g. a long quotation or table) and not a sign the paragraph regex failed to match the source's actual blank-line convention.

  • [ ] Coverage check passed (no "content may have been dropped" warning).
  • [ ] Spot-check the first and last few lines of two or three chunk files

to confirm chunk boundaries land between paragraphs, not mid-sentence.

  • [ ] If overlap is enabled, confirm the expected repeated paragraph(s)

actually appear at the start of the following chunk.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

  • SKILL.md in the repositoryCheckingSKILL.md

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hyderhusainarastu/context-window-text-chunking/context-window-text-chunking/badge)](https://verified-skill.com/skills/hyderhusainarastu/context-window-text-chunking/context-window-text-chunking)

Something wrong with this skill or its page? Tell us.