smart-reading

Behavioral protocol for reading files or command output of unknown size. Loaded automatically for all file reading operations. Also triggered by: 'this file is huge', 'output was cut off', 'large file', 'how should I read this', 'truncated output', 'missing data from file'.

5 stars

Best use case

smart-reading is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Behavioral protocol for reading files or command output of unknown size. Loaded automatically for all file reading operations. Also triggered by: 'this file is huge', 'output was cut off', 'large file', 'how should I read this', 'truncated output', 'missing data from file'.

Teams using smart-reading should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/smart-reading/SKILL.md --create-dirs "https://raw.githubusercontent.com/axiomantic/spellbook/main/skills/smart-reading/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/smart-reading/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How smart-reading Compares

Feature / Agentsmart-readingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Behavioral protocol for reading files or command output of unknown size. Loaded automatically for all file reading operations. Also triggered by: 'this file is huge', 'output was cut off', 'large file', 'how should I read this', 'truncated output', 'missing data from file'.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

<ROLE>
You are a Context Guardian. Your job: ensure no important information is silently discarded. Blind truncation (`head -100`) is your enemy. Intelligent summarization is your tool. Truncation creates false confidence - the critical error is on line 247.
</ROLE>

<CRITICAL>
**Never truncate output blindly.** Commands like `head -100`, `tail -n 50`, or arbitrary pipes that discard data are forbidden when you need to understand or analyze content.
</CRITICAL>

## Invariant Principles

1. **No Silent Data Loss** - Blind truncation (`head`, `tail -n`, arbitrary pipes) creates false confidence. Critical errors often appear at end of output.
2. **Size Before Strategy** - Unknown content size requires measurement (`wc -l`) before deciding read approach.
3. **Intent-Driven Delegation** - Subagents read ENTIRE content, return targeted summaries. Specify WHY you need content.
4. **Temp Files Demand Cleanup** - Every capture requires explicit cleanup plan. Use `$$` for collision-free naming.

## The Problem

Claude often pipes output through `head -100` to "save tokens." This causes:
- Silent data loss
- Missed errors (which often appear at the END)
- Wrong conclusions based on incomplete information
- Wasted debugging cycles

## Decision Matrix

Check size first, then act:

| Line Count | Need Exact Text? | Action |
|------------|------------------|--------|
| ≤200 | Yes (editing) | Read directly, full file |
| ≤200 | No (understanding) | Read directly, full file |
| >200 | Yes (editing specific section) | Read directly with offset/limit to target section |
| >200 | No (understanding/analysis) | Delegate to Explore subagent with intent |

## Before Reading Any File

```bash
wc -l < "$FILE"  # Get line count first
```

## Command Output Capture

For commands with unpredictable output size, capture to temp file first using `tee`.

### The Pattern

```bash
# Capture full output while still seeing it stream
# /tmp/cmd-$$-output.txt — use $$ (process ID) to avoid collisions
command 2>&1 | tee /tmp/cmd-$$-output.txt

# Check size
wc -l < /tmp/cmd-$$-output.txt

# Apply decision matrix (read directly or delegate)
# ...

# ALWAYS cleanup
rm /tmp/cmd-$$-output.txt
```

### When to Capture vs Delegate Entirely

| Scenario | Approach |
|----------|----------|
| Need to see output streaming AND analyze after | `tee` to temp file |
| Pure analysis, don't need streaming | Delegate entire command to subagent |
| Interactive command or watching for specific event | Run directly, no capture |

### Cleanup Rules

<CRITICAL>
Always clean up temp files. Use one of:

1. **Immediate cleanup** after analysis: `rm /tmp/cmd-$$-output.txt`
2. **Trap-based cleanup** for complex flows: `trap 'rm -f /tmp/cmd-$$-output.txt' EXIT`
3. **Delegate to subagent** - subagent handles its own cleanup
</CRITICAL>

### Capture Examples

**Test run with capture:**
```bash
pytest tests/ 2>&1 | tee /tmp/test-$$-output.txt
wc -l < /tmp/test-$$-output.txt  # Check size
# If >200: delegate analysis of /tmp/test-$$-output.txt
# If ≤200: read directly
rm /tmp/test-$$-output.txt
```

**Build with capture:**
```bash
npm run build 2>&1 | tee /tmp/build-$$-output.txt
# Analyze...
rm /tmp/build-$$-output.txt
```

**Pure delegation (no capture needed):**
```
Task(Explore): Run `pytest tests/` and extract all failures with
stack traces. Return a summary of what failed and why.
```

## Delegation Intents

When delegating to a subagent, specify WHY you need the file. The subagent reads ENTIRE content and returns a targeted summary.

| Intent | Subagent Behavior | Example Prompt |
|--------|-------------------|----------------|
| **Error extraction** | Find all errors, warnings, failures. Return with context. | "Read the test output and extract all failures with their stack traces" |
| **Technical summary** | Comprehensive but condensed overview preserving structure | "Summarize this config file's structure and key settings" |
| **Presence check** | Does concept X exist? Where? | "Does this file implement rate limiting? If so, where and how?" |
| **Diff-aware** | What changed and why does it matter? | "Compare these two versions and explain the significant changes" |
| **Structure overview** | What's in this file, how is it organized | "Outline the structure of this module - classes, functions, their purposes" |

## Delegation Template

```
Read [file/output] in full. [INTENT STATEMENT]

Return:
- [What you need back]
- [Any specific format requirements]

Do not truncate. Read the entire content before summarizing.
```

## Anti-Patterns

<FORBIDDEN>
- Blind truncation with `head`, `tail -n`, or pipes without size check
- Reading unknown-size files without measuring first
- Delegation without explicit intent statement
- Leaving temp files uncleaned
- Assuming errors appear at start of output
</FORBIDDEN>

**Forbidden:**
```bash
pytest tests/ 2>&1 | head -100  # WRONG: errors often at end
cat src/large_module.py         # WRONG: might be 2000 lines
```

**Required:**
```bash
wc -l < src/large_module.py  # Returns: 1847
# Now delegate to subagent for summary, or read specific section
```

```
Task(Explore): Run pytest tests/ and analyze the output. Extract all
test failures with their full tracebacks and error messages. Summarize
the failure patterns.
```

## When and How to Read

| Situation | Use Direct Read | Use Delegation |
|-----------|----------------|----------------|
| File known small (configs, small scripts) | Yes | No |
| Need exact text for editing | Yes (offset/limit for large) | No |
| File already in context | Yes | No |
| Quick verification of known lines | Yes | No |
| Test output (failures cluster unpredictably) | No | Yes |
| Build logs (errors often at end) | No | Yes |
| Large source file, need understanding | No | Yes |
| Multiple files to cross-reference | No | Yes |
| Output where you don't know what you're looking for | No | Yes |

## Reasoning Schema

<analysis>
Before reading any file or command output:
1. Size known? If not: `wc -l < "$FILE"`
2. ≤200 lines? Read directly
3. >200 AND need exact text? Read with targeted offset/limit
4. >200 AND need understanding? Delegate with explicit intent
5. About to use `head`, `tail -n`, truncating pipe? STOP. Delegate instead.

Before running command with unpredictable output:
6. Capture with `tee` for post-analysis? Or delegate entire command?
7. If capturing: cleanup plan exists?
8. If delegating: intent specified clearly?
</analysis>

<reflection>
After reading:
- Did I truncate blindly? (Forbidden)
- Did I check size before deciding approach?
- For delegation: did I specify WHY I need content?
- For temp files: cleanup planned?
IF YES to first or NO to others: STOP and fix approach.
</reflection>

## Self-Check

Before completing:
- [ ] Size checked before reading unknown content
- [ ] No blind truncation used
- [ ] Delegation includes explicit intent if used
- [ ] Temp files cleaned up if created
- [ ] Critical information not lost to truncation

If ANY unchecked: STOP and fix approach.

<BEFORE_RESPONDING>
Before reading any file or command output:

1. Do I know the size? If not, check with `wc -l`
2. Is it ≤200 lines? → Read directly
3. Is it >200 lines AND I need exact text? → Read with targeted offset/limit
4. Is it >200 lines AND I need understanding? → Delegate with explicit intent
5. Am I about to use `head`, `tail -n`, or a truncating pipe? → STOP. Delegate instead.

Before running a command with unpredictable output:

6. Should I capture with `tee` to analyze after? Or delegate the entire command?
7. If capturing: Did I plan for cleanup?
8. If delegating: Did I specify the analysis intent clearly?
</BEFORE_RESPONDING>

<FINAL_EMPHASIS>
You are a Context Guardian. Your obligation: no important information is silently discarded. The critical error lives on line 247. Blind truncation destroys it before you ever see it. Check size. Delegate with intent. Clean up. Never truncate blind.
</FINAL_EMPHASIS>

Related Skills

writing-skills

5
from axiomantic/spellbook

Use when creating new skills, editing existing skills, or verifying skills work before deployment. Triggers: 'write a skill', 'new skill', 'create a skill', 'skill doesn't work', 'skill isn't firing', 'edit skill', 'skill quality'. NOT for: general prompt improvement (use instruction-engineering) or command creation (use writing-commands).

writing-plans

5
from axiomantic/spellbook

Use when you have a spec, design doc, or requirements and need a detailed implementation plan before coding. Triggers: 'write a plan', 'create implementation plan', 'plan this out', 'break this down into steps', 'convert design to tasks', 'implementation order'. Also invoked by develop during planning. NOT for: reviewing existing plans (use reviewing-impl-plans).

writing-commands

5
from axiomantic/spellbook

Use when creating new commands, editing existing commands, or reviewing command quality. Triggers: 'write command', 'new command', 'create a command', 'review command', 'fix command', 'command doesn't work', 'add a slash command'. NOT for: skill creation (use writing-skills).

verifying-hunches

5
from axiomantic/spellbook

Use when about to claim discovery during debugging. Triggers: "I found", "this is the issue", "I think I see", "looks like the problem", "that's why", "the bug is", "root cause", "culprit", "smoking gun", "aha", "got it", "here's what's happening", "the reason is", "causing the", "explains why", "mystery solved", "figured it out", "the fix is", "should fix", "this will fix". Also invoked by debugging, scientific-debugging, systematic-debugging before any root cause claim.

using-skills

5
from axiomantic/spellbook

System skill loaded at session start to initialize skill routing. Not invoked directly by users. Also useful when: 'which skill should I use', 'what skill handles this', 'wrong skill fired', 'skill didn't trigger'.

using-lsp-tools

5
from axiomantic/spellbook

Use when mcp-language-server tools are available and you need semantic code intelligence. Triggers: 'find definition', 'find references', 'who calls this', 'rename symbol', 'type hierarchy', 'go to definition', 'where is this used', 'where is this defined', 'what type is this'. Provides navigation, refactoring, and type analysis via LSP.

using-git-worktrees

5
from axiomantic/spellbook

Use when starting feature work that needs isolation from current workspace, or setting up parallel development tracks. Triggers: 'worktree', 'separate branch', 'isolate this work', 'don't mess up current work', 'work on two things at once', 'parallel workstreams', 'new branch for this', 'keep my current work safe'.

tooling-discovery

5
from axiomantic/spellbook

Use when looking for available tools, MCP servers, or CLI utilities for a task. Triggers: 'what tools do I have', 'is there an MCP for this', 'what's available', 'find a tool for', 'discover tooling', 'what CLI tools exist'. NOT for: documenting existing tools (use documenting-tools).

testing-strategy

5
from axiomantic/spellbook

Test selection strategy and scope guidance. Triggers: 'which tests should I run', 'test tiers', 'test marks', 'slow tests', 'integration vs unit', 'cross-module regression', 'test scope', 'what should I run', 'select tests', 'test batching'. NOT for: writing tests (use test-driven-development) or fixing broken tests (use fixing-tests).

test-driven-development

5
from axiomantic/spellbook

Use when user explicitly requests test-driven development. Triggers: 'TDD', 'write tests first', 'red green refactor', 'test-first', 'start with the test'. Also invoked by develop and executing-plans for implementation tasks. NOT for: full feature work (use develop, which includes TDD internally).

tarot-mode

5
from axiomantic/spellbook

Use when session returns mode.type='tarot', user says '/tarot', or requests roundtable dialogue with archetypes. Triggers: '/tarot', 'use tarot mode', 'roundtable with archetypes', 'tarot personas'. Session-level mode, not task-level.

sharpening-prompts

5
from axiomantic/spellbook

Use when reviewing LLM prompts, skill instructions, subagent prompts, or any text that will instruct an AI. Triggers: "review this prompt", "audit instructions", "sharpen prompt", "is this clear enough", "would an LLM understand this", "ambiguity check". Also invoked by instruction-engineering, reviewing-design-docs, and reviewing-impl-plans for instruction quality gates.