HN 표시: Tokf – 자세한 빌드 출력에서 ​​LLM 컨텍스트 낭비를 중지합니다.

hackernews | | 🔬 연구
#claude #cli #llm #openai #review #개발도구 #최적화 #컨텍스트
원문 출처: hackernews · Genesis Park에서 요약 및 분석

요약

AI 코딩 도구 사용 시 빌드 및 테스트 결과에서 발생하는 불필요한 토큰을 줄이기 위해, 본문의 저자는 Rust로 작성된 CLI 도구 'tokf'를 개발했습니다. 이 도구는 TOML 필터를 사용하여 성공한 테스트나 반복되는 경고를 제거하며, make/just의 셸 플래그 활용이나 git 후크의 shim 디렉토리 설정 등을 통해 빌드 오케스트레이터와 연동되도록 설계되었습니다. 현재 저자의 워크플로우에서 하루 약 1,800회 실행되며 Lua 스크립트 확장을 지원하는 오픈 소스로 공개되었습니다.

본문

tokf.net — reduce LLM context consumption from CLI commands by 60–90%. Commands like git push , cargo test , and docker build produce verbose output packed with progress bars, compile noise, and boilerplate. tokf intercepts that output, applies a TOML filter, and emits only what matters — so your AI agent sees a clean signal instead of hundreds of wasted tokens. cargo test — 61 lines → 1 line: | Without tokf | With tokf | |---|---| | | git push — 8 lines → 1 line: | Without tokf | With tokf | |---|---| | | brew install mpecan/tokf/tokf # or: cargo install tokf tokf setup # detect your AI tools and install hooks That's it. Every command your AI agent runs is now automatically filtered. Run tokf gain to see how many tokens you've saved, or tokf setup --refresh to re-run detection. brew install mpecan/tokf/tokf cargo install tokf git clone https://github.com/mpecan/tokf cd tokf cargo build --release # binary at target/release/tokf tokf run git push origin main tokf looks up a filter for git push , runs the command, and applies the filter. The filter logic lives in plain TOML files — no recompilation required. Anyone can author, share, or override a filter. If you use an AI coding tool, install the hook so every command is filtered automatically — no tokf run prefix needed: # Claude Code (recommended: --global so it works in every project) tokf hook install --global # OpenCode tokf hook install --tool opencode --global # OpenAI Codex CLI tokf hook install --tool codex --global Drop --global to install for the current project only. See Claude Code hook for details on each tool, the --path flag, and optional extras like the filter-authoring skill. tokf run git push origin main tokf run cargo test tokf run docker build . tokf apply filters/git/push.toml tests/fixtures/git_push_success.txt --exit-code 0 tokf verify # run all test suites tokf verify git/push # run a specific suite tokf verify --list # list available suites and case counts tokf verify --json # output results as JSON tokf verify --require-all # fail if any filter has no test suite tokf verify --list --require-all # show coverage per filter tokf verify --scope project # only project-local filters (.tokf/filters/) tokf verify --scope global # only user-level filters (~/.config/tokf/filters/) tokf verify --scope stdlib # only built-in stdlib (filters/ in CWD) tokf verify --safety # run safety checks (prompt injection, shell injection, hidden unicode) tokf verify git/push --safety # safety check a specific filter tokf automatically wraps make and just so that each recipe line is individually filtered: make check # each recipe line (cargo test, cargo clippy, ...) is filtered just test # same — each recipe runs through tokf See Rewrite configuration for details and customization. tokf ls # list all filters tokf which "cargo test" # which filter would match tokf show git/push # print the TOML source tokf eject cargo/build # copy to .tokf/filters/ (project-local) tokf eject cargo/build --global # copy to ~/.config/tokf/filters/ (user-level) This copies the filter TOML and its test suite to your config directory, where it shadows the built-in. Edit the ejected copy freely — tokf's priority system ensures your version is used instead of the original. | Flag | Description | |---|---| --timing | Print how long filtering took | --verbose | Show which filter was matched (also explains skipped rewrites) | --no-filter | Pass output through without filtering | --no-cache | Bypass the filter discovery cache | --no-mask-exit-code | Disable exit-code masking. By default tokf exits 0 and prepends Error: Exit code N on failure | --preserve-color | Preserve ANSI color codes in filtered output (env: TOKF_PRESERVE_COLOR=1 ). See Color passthrough below | --baseline-pipe | Pipe command for fair baseline accounting (injected by rewrite) | --prefer-less | Compare filtered vs piped output and use whichever is smaller (requires --baseline-pipe ) | By default, filters with strip_ansi = true permanently remove ANSI escape codes. The --preserve-color flag changes this: tokf strips ANSI internally for pattern matching (skip, keep, dedup) but restores the original colored lines in the final output. When --preserve-color is active it overrides strip_ansi = true in the filter config. tokf does not force commands to emit color — you must ensure the child command outputs ANSI codes (e.g. via FORCE_COLOR=1 or --color=always ): # Node.js / Vitest / Jest FORCE_COLOR=1 tokf run --preserve-color npm test # Cargo tokf run --preserve-color cargo test -- --color=always # Or set the env var once for all invocations export TOKF_PRESERVE_COLOR=1 FORCE_COLOR=1 tokf run npm test Limitations: color passthrough applies to the skip/keep/dedup pipeline (stages 2–2.5). The match_output , parse , and lua_script stages operate on clean text and are unaffected by this flag. [[replace]] rules run on the raw text before the color split, so when --preserve-color is enabled their patterns may need to account for A

Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.

공유

관련 저널 읽기

전체 보기 →