mpecan/tokf/tokf-filter
Claude Code and agent skill by mpecan/tokf
- community
- ext:[{"type":"template","description":"Custom templates for code generation"}]
Checking that the SKILL.md file is still in the repository.
This skill should be used when the user asks to "create a filter", "write a tokf filter", "add a filter for <tool>", "how do I filter output", or needs guidance on tokf filter step types, templates, pipes, or placement conventions.
Install
npx vskill@latest install mpecan/tokf/tokf-filterSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
tokf Filter Authoring
You are an expert at writing tokf filter files. tokf is a config-driven CLI that compresses command output before it reaches an LLM context. Filters are TOML files that define how to process a command's output.
When the user asks you to create or modify a filter, follow this guide exactly. Produce valid, idiomatic TOML that matches the schema described below.
Section 1 — What a Filter File Is
A filter file is a TOML file that describes:
- Which command(s) it applies to (
command) - How to transform the raw output (steps, applied in a fixed order)
- What to emit on success vs. failure
Filters live in three places, searched in priority order:
.tokf/filters/— project-local (repo-level overrides)~/.config/tokf/filters/— user-level overrides- Built-in library (embedded in the tokf binary)
First match wins. Use tokf which "cargo test" to see which filter would activate for a given command.
Section 2 — Processing Order
Steps execute in this fixed order — do not rearrange them:
- `match_output` — whole-output substring checks; if matched, short-circuits the entire pipeline and emits immediately
- `[[replace]]` — per-line regex transforms applied to every line, in array order
- `strip_ansi` / `trim_lines` — per-line cleanup (ANSI stripping, whitespace trimming)
- `skip` / `keep` — line-level filtering (drop or retain lines by regex)
- `dedup` / `dedup_window` — collapse duplicate consecutive lines
- `lua_script` — Luau escape hatch; runs after dedup, before JSON/section/parse
- `[json]` — JSON extraction via
JSONPath; when configured, replaces section/parse/chunk - `[[section]]` OR `[parse]` — structured extraction (these are mutually exclusive; section is a state machine, parse is a declarative grouper). Skipped when
[json]is configured. - `[[chunk]]` — block-based structured extraction with per-block aggregation, grouping, and tree output (runs on raw output, alongside sections). Skipped when
[json]is configured. - Exit-code branch —
[on_success]or[on_failure]depending on exit code - `[fallback]` — if neither
on_successnoron_failureproduced output - `strip_empty_lines` / `collapse_empty_lines` — post-processing cleanup on the final output
Within [on_success] and [on_failure], fields are processed as:
head/tail→ trim linesskip/extract→ further filteraggregate→ reduce collected sectionsoutput→ final template render
Section 3 — Top-Level Fields Reference
| Field | Type | Default | Description | |
|---|---|---|---|---|
command | string or array of strings | required | Command pattern(s) to match. Supports * wildcard. | |
run | string | (same as command) | Override the actual command executed. Use {args} to forward arguments. | |
match_output | array of tables | [] | Whole-output checks. Short-circuit on first match. | |
[[replace]] | array of tables | [] | Per-line regex replacements, in order. | |
skip | array of strings (regex) | [] | Drop lines matching any regex. | |
keep | array of strings (regex) | [] | Retain only lines matching any regex. (Inverse of skip.) | |
dedup | bool | false | Collapse consecutive identical lines. | |
dedup_window | integer | 0 (off) | Dedup within a sliding window of N lines. | |
strip_ansi | bool | false | Strip ANSI escape sequences before skip/keep. | |
trim_lines | bool | false | Trim leading/trailing whitespace from each line. | |
lua_script | table | (absent) | Luau escape hatch. | |
[json] | table | (absent) | JSON extraction via JSONPath. When configured, replaces [[section]]/[parse]/[[chunk]]. | |
[[section]] | array of tables | [] | State-machine section collectors. | |
[[chunk]] | array of tables | [] | Block-based structured extraction with per-block aggregation and grouping. | |
[parse] | table | (absent) | Declarative structured parser (branch + group). | |
[on_success] | table | (absent) | Output branch for exit code 0. | |
[on_failure] | table | (absent) | Output branch for non-zero exit. | |
[output] | table | (absent) | Top-level output template (used by [parse]). | |
[fallback] | table | (absent) | Fallback when no branch matched. | |
strip_empty_lines | bool | false | Remove all blank lines from the final output. | |
collapse_empty_lines | bool | false | Collapse consecutive blank lines into one. | |
show_history_hint | bool | false | Append a hint line after filtered output pointing to the full output in history. | |
[[variant]] | array of tables | [] | Context-aware delegation to specialized child filters. |
Section 4 — Step Types
4.1 match_output — Whole-Output Short-Circuit
Check the entire raw output for a substring. If matched, emit a fixed string and stop — no further processing.
contains: literal substring to search for (case-sensitive)output: string to emit if matched{line_containing}template variable: the first line that contains the substring
When to use: for well-known one-liner outcomes that make the rest of filtering irrelevant (e.g., "already up to date", "nothing to push", "authentication failed").
4.2 [[replace]] — Per-Line Regex Transforms
Applied to every line, in array order, before skip/keep. Use to reformat noisy lines.
pattern: Rust regex (RE2 syntax, no lookaheads)output: template with{1},{2}, … for capture groups;{0}is the full match- If the pattern doesn't match a line, that line passes through unchanged
- Invalid patterns are silently skipped at runtime
When to use: when a line contains useful information but in a verbose format — reformat it rather than dropping it.
4.3 skip / keep — Line Filtering
skip drops lines matching any regex. keep retains only lines matching any regex. They compose:
- Both are arrays of regex strings
- Applied after
[[replace]] skipis checked first, thenkeep- A line must pass both: not skipped, and (if keep is non-empty) matching keep
When to use: skip for removing known noise patterns; keep for allow-listing (e.g., keep only lines that start with error or warning).
Also available inside [on_success] and [on_failure] for branch-level filtering.
4.4 dedup / dedup_window — Deduplication
dedup = true: removes consecutive duplicate lines (likeuniq)dedup_window = N: deduplicates within a sliding window of N lines (catches near-consecutive repeats)- They are independent; you can use both
When to use: for commands that emit repetitive progress lines (e.g., npm install printing the same package multiple times, spinner frames, repeated warnings).
4.5 lua_script — Luau Escape Hatch
For logic that pure TOML cannot express: numeric math, multi-line lookahead, conditional branching.
Or load the script from an external file:
The file path resolves relative to the current working directory. Exactly one of source or file must be set.
Globals available:
output(string): the full output after skip/keep/dedupexit_code(integer): the command's exit codeargs(table of strings): the arguments passed to the command
Return semantics:
- Return a string → replaces output, skips remaining TOML pipeline
- Return
nil→ fall through to[[section]]/[parse]/[on_success]/[on_failure]
Sandbox: io, os, and package are blocked. No filesystem or network access. Standard math/string/table libraries are available.
When to use: only when no TOML step can express the logic. Most filters do not need this. Consider it after exhausting match_output, skip/keep, [[replace]], [[section]], and [parse].
4.6 [json] — JSON Extraction via JSONPath
For commands that produce JSON output (e.g. kubectl get pods -o json, gh api, docker inspect). Extracts values using JSONPath (RFC 9535) queries and produces template variables and structured collections.
`[[json.extract]]` fields:
| Field | Type | Required | Description | |
|---|---|---|---|---|
path | string | yes | JSONPath expression (RFC 9535), e.g. "$.items[*]", "$.version" | |
as | string | yes | Variable name to bind the result to | |
fields | array of tables | no | Sub-field extraction for each matched object |
`[[json.extract.fields]]` fields:
| Field | Type | Required | Description | |
|---|---|---|---|---|
field | string | yes | Dot-separated path within each object (e.g. "metadata.name", "containers.0.name"). Not JSONPath — uses simple dot-notation. Supports numeric array indices. | |
as | string | yes | Variable name for the extracted value |
Result mapping:
- Single scalar →
vars["as_name"] = string_value(no count, no chunk) - Array →
ChunkData::Flatcollection +{as_name_count}variable - Objects without `fields` → top-level scalars auto-flattened into chunk items
- Objects with `fields` → named fields extracted per item
Pipeline behavior: when [json] is configured, [[section]], [parse], and [[chunk]] are skipped. JSON replaces line-based structural processing. Extracted vars and chunks flow into [on_success]/[on_failure] template rendering.
Error handling: invalid JSON input → extraction skipped, pipeline falls back to raw output (templates are not rendered). Invalid JSONPath → rule silently skipped, other rules still run. Empty array with fields → emits {as_name_count} = "0".
When to use: when the command produces structured JSON output and you need to extract specific fields. Prefer this over [parse] + skip/keep for JSON-native commands.
4.7 [[section]] — State-Machine Section Collector
The most powerful step. Defines a state machine that collects lines into named variables as it scans top-to-bottom.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingcrates/tokf-cli/skills/tokf-filter/SKILL.md
Popularity
- Repository stars
- 179
- Repository forks
- 20
- 7-day trend score
- 26
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 10 Jun 2026, 4 months ago.
Extension points
templateCustom templates for code generation
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
[](https://verified-skill.com/skills/mpecan/tokf/tokf-filter)