# Compress Context

> Compress a given file (CLAUDE.md, skill file, prompt file) into token-efficient symbolic notation. Rewrites the file in-place and maintains a symbols.md legend. Use when asked to compress, reduce tokens, shorten prompts, or make context more efficient.

- Skill: `rs2pydev/compress-context` (Agent Skill)
- Install (CLI): `npx skillmds@latest add rs2pydev/compress-context`
- Raw SKILL.md: https://api.skillmd.com/api/skills/rs2pydev/compress-context/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: rs2pydev (https://skillmd.com/u/rs2pydev)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/rs2pydev/compress-context

---


# compress-context

Compress a natural language file into token-efficient symbolic notation. Rewrites the file in-place and generates/updates a `symbols.md` legend alongside it.

## Instructions

You are compressing the file at `$ARGUMENTS` using the symbolic notation system below. The goal is to reduce input token count by 30-50% while maintaining full semantic clarity for LLMs.

### Step 1: Read the Target File

Read the file provided as the argument. Identify which sections are:
- Natural language prose (COMPRESS THESE)
- Code blocks (NEVER COMPRESS)
- File paths, function names, identifiers (KEEP LITERAL)
- Headings and structural markers (KEEP AS-IS)

### Step 2: Apply Compression Rules

Transform natural language using these rules, in order:

#### Phase A: Remove Filler

Delete words that carry zero semantic weight:
- please, just, simply, basically, actually
- "go ahead and", "be sure to", "I would like you to"
- "in order to" -> "to"
- "due to the fact that" -> "because"
- "it is important to note that" -> "note:"

#### Phase B: Structural Transformations

| NLP Pattern | Symbolic Form |
|-------------|--------------|
| "make sure that X" / "ensure that X" | `ensure: X` |
| "do not X" / "never X" / "must not X" | `x X` |
| "if X then Y" / "when X, do Y" | `X? -> Y` |
| "for each X in Y, check Z" | `* X @ Y: Z` |
| "X should be at least N" | `X >= N` |
| "X should be at most N" | `X <= N` |
| "set X to Y" / "configure X as Y" | `X = Y` |
| "X reads from Y" / "X gets value from Y" | `X <- Y` |
| "after X, then Y" | `X; Y` |
| "either X or Y" | `X \| Y` |
| "both X and Y" | `X + Y` |
| "X returns Y" / "X produces Y" | `X -> Y` |
| "optionally X" / "X if available" | `[X]` |
| "one of X, Y, Z" | `{X, Y, Z}` |
| "first X, then Y, finally Z" | `X; Y; Z` |

#### Phase C: Flow Operators

| Symbol | Replaces |
|--------|----------|
| `->` | "leads to", "then", "results in", "produces" |
| `=>` | "implies", "therefore" |
| `>>` | "pipe to", "pass output to" |
| `;` | "then", "followed by", "next" (sequential, no causal link) |
| `\|` | "or", "alternatively" |
| `+` | "and", "also", "together with" |

#### Phase D: Abbreviations

| Full Word | Abbreviation |
|-----------|-------------|
| function | fn |
| class | cls |
| module | mod |
| package | pkg |
| variable | var |
| argument | arg |
| parameter | param |
| string | str |
| integer | int |
| boolean | bool |
| dictionary | dict |
| error | err |
| exception | exc |
| message | msg |
| request | req |
| response | resp |
| configuration | config |
| environment | env |
| directory | dir |
| database | db |
| authentication | auth |
| implementation | impl |
| dependencies | deps |
| documentation | docs |
| specification | spec |
| version | ver |
| maximum | max |
| minimum | min |
| without | w/o |
| with | w/ |
| approximately | ~ |

#### Phase E: Structural Patterns

Convert prose paragraphs into structured key-value or scoped blocks:

```
# Verbose paragraph about configuration
"The project uses Python 3.11, FastAPI for the backend, and React 19 with
TypeScript for the frontend. Tests use pytest with async auto mode."

# Compressed
stack: py3.11 + FastAPI | react19 + ts
test: pytest(asyncio=auto)
```

```
# Verbose list of requirements
"Every function must have type annotations. No function should exceed 30 lines.
Test coverage must be at least 80%. No bare except clauses allowed."

# Compressed
gates:
  [checkmark] fn type annotations
  x fn LOC > 30
  [checkmark] coverage >= 80%
  x bare except
```

### Step 3: Write Compressed File

Overwrite the original file with the compressed version. Preserve:
- All code blocks (unchanged)
- All file paths and identifiers (unchanged)
- Heading hierarchy (unchanged)
- Blank lines between sections (structure)

### Step 4: Generate/Update symbols.md

Create or update a `symbols.md` file in the SAME directory as the compressed file. This legend maps every symbol used in the compressed file to its natural language meaning.

Format of `symbols.md`:

```markdown
# Symbol Legend

Notation reference for compressed files in this directory.

## Operators
| Symbol | Meaning |
|--------|---------|
| `->` | then / produces / leads to |
| ...  | ... |

## Abbreviations Used
| Short | Full |
|-------|------|
| `fn` | function |
| ... | ... |

## Domain-Specific
| Term | Meaning |
|------|---------|
| ... | ... |
```

Only include symbols and abbreviations that ACTUALLY appear in the compressed file. Do not include the full rule set - only what was used.

### Step 5: Report

After compression, output:

```
-- Compression Report --
  File:       <path>
  Original:   <N> words / <N> chars
  Compressed: <N> words / <N> chars
  Reduction:  ~<N>% fewer tokens (estimated)
  Legend:      <path>/symbols.md (created/updated)
```

### Constraints

- NEVER compress inside fenced code blocks (``` ... ```)
- NEVER compress file paths, URLs, function names, or variable names
- NEVER compress headings (lines starting with #)
- NEVER change the semantic meaning - compression must be lossless in intent
- If a compression is ambiguous (could be misread), keep the original verbose form
- Preserve all markdown structure (lists, tables, blockquotes)
- Do not compress content that is already symbolic/abbreviated

