Skill v1.0.0
currentAutomated scan100/100version: "1.0.0" name: context-analysis description: Analyze plain text documents to understand their semantic structure and token distribution. Use when asked to analyze context, visualize token usage, segment text, identify components, create waffle charts, or compare multiple documents.
Context Analysis
Analyze plain text documents to understand their semantic structure and token distribution. This skill helps visualize how tokens are distributed across different semantic components of a document.
Workflow
When analyzing a document, follow these steps:
1. Parse the Text
Convert the input text file to JSON format:
./scripts/parse.sh input.txt > parsed.json
2. Count Tokens
Add token counts using tiktoken (GPT-4o encoding):
./scripts/count-tokens.sh parsed.json > counted.json
3. Segment Large Parts
For parts with more than 500 tokens, identify semantic breakpoints and split them.
You (Claude) should do this directly:
- Read the text of each large part
- Identify natural semantic boundaries (topic changes, section breaks, logical divisions)
- Split into coherent chunks
- Update the JSON with new parts (use IDs like
part-1.1,part-1.2, etc.)
After segmenting, recount tokens:
./scripts/count-tokens.sh segmented.json > recounted.json
4. Identify Components
Analyze the document and identify the distinct semantic components it contains.
You (Claude) should do this directly:
- Read all parts
- Identify categories/themes (e.g., "introduction", "methodology", "examples", "conclusion")
- Assign each part to a component
- Add to JSON:
componentsarray andcomponentfield on each part - Calculate
component_tokenstotals
5. Assign Colors
Run the colorization script to assign consistent colors:
./scripts/colorise.sh componentised.json > colored.json
6. Generate Visualizations
./scripts/waffle-chart.sh colored.json > waffle.html./scripts/bar-chart.sh colored.json > bar-chart.html./scripts/text-view.sh colored.json > text-view.html
Quick Commands
For a complete analysis pipeline:
# Parse and count./scripts/parse.sh input.txt > /tmp/1-parsed.json./scripts/count-tokens.sh /tmp/1-parsed.json > /tmp/2-counted.json# You segment and componentise the JSON directly, then:./scripts/colorise.sh /tmp/3-componentised.json > /tmp/4-colored.json./scripts/waffle-chart.sh /tmp/4-colored.json > waffle.html
For multiple files:
./scripts/group.sh input_folder/ output_dir/
Data Format
The JSON format used throughout:
{"source": "filename.txt","parts": [{"id": "part-1","text": "The actual text content...","token_count": 150,"component": "introduction"}],"components": ["introduction", "methodology", "results"],"component_tokens": {"introduction": 500,"methodology": 1200,"results": 800},"total_tokens": 2500}
Segmentation Guidelines
When segmenting large parts (>500 tokens):
- Look for natural breakpoints:
- Markdown headings (
#,##, etc.) - Topic transitions
- Logical section boundaries
- List groupings
- Create semantically coherent chunks:
- Each segment should cover one topic/concept
- Aim for 100-500 tokens per segment
- Preserve context within segments
- Update IDs hierarchically:
part-1splits intopart-1.1,part-1.2, etc.
Component Identification Guidelines
When identifying components:
- Read all parts to understand the document structure
- Identify 3-10 distinct semantic categories
- Use descriptive, lowercase names with underscores
- Common patterns:
- Documents:
introduction,methodology,results,conclusion - Technical:
configuration,implementation,examples,api_reference - Instructional:
overview,prerequisites,steps,troubleshooting
- Assign each part to exactly one component
- Use
otherfor parts that don't fit elsewhere
Available Colors
Components are assigned these colors:
blue- Primary content, introductionsemerald- Workflows, processes, methodologypurple- Style, personality, guidelinesorange- Context, examples, highlightsindigo- Code, technical contentslate- Environment, configurationgray- Tools, utilities, other
References
See the references/ folder for detailed documentation on each step.