You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(hook): use bare tokf in generated hook scripts (#208)
## Summary
- Replace hardcoded absolute binary path (`std::env::current_exe()`)
with bare `tokf` in generated hook shim and OpenCode plugin scripts
- Remove `escape_for_js_string` helper and `{{TOKF_PATH}}` template
substitution from opencode.rs (no longer needed)
- Add `--path <binary>` flag to `tokf hook install` so users can opt
into a specific binary path when bare `tokf` isn't on PATH (e.g.
Linuxbrew, `cargo install` without PATH in `/bin/sh`)
- Custom paths are shell-escaped in the hook shim and JS-escaped (via
`serde_json`) in the OpenCode plugin template
- Update tests to assert on bare `tokf` instead of quoted full paths,
plus new tests for custom path and path-with-spaces escaping
- Add "Set up automatic filtering" section to getting-started docs so
users discover `tokf hook install --global` during onboarding
- Document the `--path` flag in integrations docs
Closes#191
## Test plan
- [x] `cargo test -p tokf -- hook` — all 81 tests pass
- [x] `cargo clippy --workspace --all-targets -- -D warnings` — clean
- [x] `cargo fmt -- --check` — clean
- [x] README.md regenerated via `scripts/generate-readme.sh`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,25 @@ tokf looks up a filter for `git push`, runs the command, and applies the filter.
124
124
125
125
---
126
126
127
+
## Set up automatic filtering
128
+
129
+
If you use an AI coding tool, install the hook so every command is filtered automatically — no `tokf run` prefix needed:
130
+
131
+
```sh
132
+
# Claude Code (recommended: --global so it works in every project)
133
+
tokf hook install --global
134
+
135
+
# OpenCode
136
+
tokf hook install --tool opencode --global
137
+
138
+
# OpenAI Codex CLI
139
+
tokf hook install --tool codex --global
140
+
```
141
+
142
+
Drop `--global` to install for the current project only. See [Claude Code hook](#claude-code-hook) for details on each tool, the `--path` flag, and optional extras like the filter-authoring skill.
Once installed, every command Claude runs through the Bash tool is filtered transparently. Track cumulative savings with `tokf gain`.
711
730
731
+
### Custom binary path
732
+
733
+
By default the generated hook script calls bare `tokf`, relying on PATH at runtime. If `tokf` isn't on PATH in the hook's execution environment (common with Linuxbrew or `cargo install` when PATH is only set in interactive shell profiles), pass `--path` to embed a specific binary location:
0 commit comments