@tokelang-lite/claude-code-skill 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +21 -0
- package/LICENSE +201 -0
- package/README.md +143 -0
- package/bin/tokelang-cli +28 -0
- package/hooks/hooks.json +35 -0
- package/hooks/pre-tool-use.sh +76 -0
- package/hooks/session-start.sh +53 -0
- package/hooks/stop.sh +90 -0
- package/install/install.js +241 -0
- package/package.json +44 -0
- package/settings.json +13 -0
- package/skills/tokelang/SKILL.md +90 -0
- package/skills/tokelang-compress/SKILL.md +77 -0
- package/skills/tokelang-level/SKILL.md +91 -0
- package/skills/tokelang-restore/SKILL.md +57 -0
- package/skills/tokelang-stats/SKILL.md +73 -0
- package/skills/tokelang-telemetry/SKILL.md +82 -0
- package/statusline/savings.sh +15 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tokelang",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Compress your context files and subagent prompts locally before they reach the model (per-prompt input compression via the tokelang-cli wrap alias). Apache 2.0 open source.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Tokelang",
|
|
7
|
+
"email": "hello@tokelang.com",
|
|
8
|
+
"url": "https://tokelang.com"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://tokelang.com",
|
|
11
|
+
"repository": "https://github.com/tokelang/claude-code-skill",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"tokens",
|
|
15
|
+
"compression",
|
|
16
|
+
"context",
|
|
17
|
+
"prompt-engineering",
|
|
18
|
+
"cost-reduction",
|
|
19
|
+
"brevity"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept liability
|
|
167
|
+
and/or offer support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However,
|
|
169
|
+
in accepting such obligations, You may act only on Your own
|
|
170
|
+
behalf and on Your sole responsibility, not on behalf of any other
|
|
171
|
+
Contributor, and only if You agree to indemnify, defend, and hold
|
|
172
|
+
each Contributor harmless for any liability incurred by, or claims
|
|
173
|
+
asserted against, such Contributor by reason of your accepting any
|
|
174
|
+
such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Tokelang
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Tokelang for Claude Code
|
|
2
|
+
|
|
3
|
+
> Compressed prompts make models think better. Not our claim — [arXiv:2604.00025](https://arxiv.org/abs/2604.00025).
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Tokelang compresses tokens in your Claude Code session via a semantic validator that refuses any compression that drops meaning. Engine runs locally — your data never leaves your machine.
|
|
8
|
+
|
|
9
|
+
## Two parts, two install paths
|
|
10
|
+
|
|
11
|
+
| Part | Install | What it does |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| **Claude Code skill** | `claude plugin install tokelang` | Compresses your context files (slash command), your subagent invocations (Task tool prompts), and injects an output style guide so the model responds briefly. |
|
|
14
|
+
| **`tokelang-cli wrap` alias** | `alias claude='tokelang-cli wrap claude'` | Compresses **every prompt you type** before it reaches Claude Code. The only way to get true input compression — Claude Code's plugin hooks are additive only and can't rewrite user input. |
|
|
15
|
+
|
|
16
|
+
You can install just the skill (lighter touch) or skill + wrap alias (full compression). Both share the same local engine. **Most users want both.**
|
|
17
|
+
|
|
18
|
+
## Install — skill only
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
claude plugin marketplace add tokelang/claude-code-skill
|
|
22
|
+
claude plugin install tokelang
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That's it. Start a new Claude Code session and the skill is active at Level 2 (Balanced — subagent input compression + lite output style guide). Slash commands available.
|
|
26
|
+
|
|
27
|
+
## Install — skill + wrap mode (recommended for full compression)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 1. Install the skill (as above)
|
|
31
|
+
claude plugin marketplace add tokelang/claude-code-skill
|
|
32
|
+
claude plugin install tokelang
|
|
33
|
+
|
|
34
|
+
# 2. Install the standalone CLI binary
|
|
35
|
+
brew install tokelang/tap/tokelang-cli # macOS
|
|
36
|
+
# OR
|
|
37
|
+
curl -fsSL https://tokelang.com/install.sh | bash # Linux/macOS
|
|
38
|
+
|
|
39
|
+
# 3. Add the wrap alias to your shell config (~/.bashrc, ~/.zshrc):
|
|
40
|
+
alias claude='tokelang-cli wrap claude'
|
|
41
|
+
|
|
42
|
+
# 4. (Optional) wrap other CLIs too:
|
|
43
|
+
alias codex='tokelang-cli wrap codex'
|
|
44
|
+
alias gemini='tokelang-cli wrap gemini'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Now every prompt you type to claude/codex/gemini gets compressed first.
|
|
48
|
+
|
|
49
|
+
## What runs where
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
You type: "explain database connection pooling in detail please"
|
|
53
|
+
│
|
|
54
|
+
▼
|
|
55
|
+
tokelang-cli wrap (intercepts stdin)
|
|
56
|
+
│
|
|
57
|
+
▼
|
|
58
|
+
Engine compresses to: "explain DB conn pooling detailed"
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
claude (sees compressed version)
|
|
62
|
+
│
|
|
63
|
+
▼
|
|
64
|
+
── SessionStart hook fires (skill)
|
|
65
|
+
── Style guide injected: "respond concisely"
|
|
66
|
+
── PreToolUse hook fires on Task tool (skill compresses subagent prompts)
|
|
67
|
+
│
|
|
68
|
+
▼
|
|
69
|
+
Model responds: brief, focused answer (because style guide nudged it)
|
|
70
|
+
│
|
|
71
|
+
▼
|
|
72
|
+
You see: model's response
|
|
73
|
+
|
|
74
|
+
(meanwhile statusline shows running savings counter)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## How to turn it down or off
|
|
78
|
+
|
|
79
|
+
| Want | Action |
|
|
80
|
+
|---|---|
|
|
81
|
+
| Skill less aggressive (no subagent compression) | `/tokelang-level 1` |
|
|
82
|
+
| Skill loaded but doing nothing | `/tokelang-level off` |
|
|
83
|
+
| Skill more aggressive | `/tokelang-level 3` |
|
|
84
|
+
| Wrap mode disabled | `unalias claude` or comment out the alias line |
|
|
85
|
+
| Usage metrics (opt-in) | `/tokelang-telemetry on` / `off` — **off by default**; aggregate counts only, never content |
|
|
86
|
+
| Uninstall skill | `claude plugin uninstall tokelang` |
|
|
87
|
+
| Uninstall CLI | `brew uninstall tokelang-cli` or delete the binary |
|
|
88
|
+
|
|
89
|
+
Skill settings persist in `~/.claude/settings.json` under `"tokelang.level"`.
|
|
90
|
+
|
|
91
|
+
## Why brevity helps the model
|
|
92
|
+
|
|
93
|
+
Hakim 2026 found that constraining large models to brief responses **improves accuracy by 26 percentage points** on hard reasoning benchmarks — and **reverses performance hierarchies** between small and large models. The mechanism: verbose generation introduces overelaboration errors. Strip the verbosity, the reasoning improves.
|
|
94
|
+
|
|
95
|
+
Tokelang is the productionized version of that finding. We compress your input (via wrap mode) so the model isn't burning attention parsing verbose English, and we nudge it (via style guide injection) to respond briefly so it doesn't overelaborate.
|
|
96
|
+
|
|
97
|
+
## What gets compressed vs preserved
|
|
98
|
+
|
|
99
|
+
**Compressed** (when validator passes): articles (`a`, `the`), filler (`just`, `really`), pleasantries (`sure`, `of course`), hedging (`maybe`, `it might be worth`), prose connectives (`however`, `furthermore`), redundant phrasing (`in order to` → `to`).
|
|
100
|
+
|
|
101
|
+
**Always preserved exactly** (hard zones): negations (`not`, `never`, `only`), numbers and thresholds (`$5000`, `0.85`, `500ms`), code blocks (fenced + indented), URLs, file paths, command literals, regex literals (`\d{4}`), template placeholders (`{VAR}`), quoted strings, contract vocabulary (`shall`, `must`, `required`, `strictly`).
|
|
102
|
+
|
|
103
|
+
## Vs. Caveman and others
|
|
104
|
+
|
|
105
|
+
| | Tokelang (skill + wrap) | Caveman | LLMLingua / SynthLang |
|
|
106
|
+
|---|---|---|---|
|
|
107
|
+
| Engine runs locally | ✅ | ❌ (Claude API call per file) | ✅ |
|
|
108
|
+
| Semantic validator | ✅ (0.85 / 0.90 recall floor + protected spans) | ❌ (structural only) | ❌ |
|
|
109
|
+
| User-input compression | ✅ (wrap mode) | ❌ | ✅ (proxy) |
|
|
110
|
+
| Subagent-input compression | ✅ (PreToolUse hook) | ❌ | ❌ |
|
|
111
|
+
| Context-file compression | ✅ | ✅ | partial |
|
|
112
|
+
| Output style guide | ✅ | ✅ | ❌ |
|
|
113
|
+
| Cross-CLI (Codex, Gemini, Aider) | ✅ (wrap works for all) | ❌ Claude Code only | varies |
|
|
114
|
+
| Open source license | Apache 2.0 (patent grant) | MIT | varies |
|
|
115
|
+
| Patent-backed IP | ✅ (IP India 2025-10-06) | — | — |
|
|
116
|
+
|
|
117
|
+
The differentiator that matters: **the validator + the dual-frontend architecture**. The skill gives you what plugin hooks make possible; the wrap mode gives you what they don't.
|
|
118
|
+
|
|
119
|
+
## Privacy
|
|
120
|
+
|
|
121
|
+
- Engine bundled is local-only — no network calls during compression
|
|
122
|
+
- Telemetry is **opt-in and off by default.** Turn it on/off with `/tokelang-telemetry on|off` (state in `~/.claude/.tokelang-telemetry.json`). When on, the Stop hook sends one aggregate ping per session: schema/CLI version, level, coarse OS/arch, this session's `tokens_saved` + event count, lifetime totals, and a locally-generated random `anon_id`. **Never** prompt text, responses, file paths, or session ids — the metrics are built from a sidecar that only stores `surface,orig,comp,timestamp` per event, so there is no content in it to send.
|
|
123
|
+
- Hosted API at tokelang.com is a *separate product* used by the dashboard
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Apache 2.0 with explicit patent grant. See [LICENSE](LICENSE).
|
|
128
|
+
|
|
129
|
+
Code is yours to use, modify, fork, and ship in commercial products. The name **Tokelang™** and the logo are reserved — see [TRADEMARKS.md](TRADEMARKS.md).
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). DCO sign-off required (`git commit -s`).
|
|
134
|
+
|
|
135
|
+
## Status
|
|
136
|
+
|
|
137
|
+
v1.0.0 is the first OSS release (planned 2026-Q3). Companion projects:
|
|
138
|
+
|
|
139
|
+
- [`tokelang-core`](https://github.com/tokelang/tokelang-core) — the Rust engine crate
|
|
140
|
+
- [`tokelang-cli`](https://github.com/tokelang/tokelang-cli) — the standalone binary + wrap mode
|
|
141
|
+
- [`vscode-extension`](https://github.com/tokelang/vscode-extension) — for Cursor / Windsurf / Copilot / Cline users
|
|
142
|
+
|
|
143
|
+
Hosted dashboard + paid API at [tokelang.com](https://tokelang.com).
|
package/bin/tokelang-cli
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Platform resolver: pick the right static tokelang-cli binary for this host and exec it.
|
|
3
|
+
# Lets the hooks, slash commands, and docs all call a single stable path
|
|
4
|
+
# (`${CLAUDE_PLUGIN_ROOT}/bin/tokelang-cli`) regardless of OS/arch.
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
|
9
|
+
ARCH="$(uname -m)"
|
|
10
|
+
EXT=""
|
|
11
|
+
|
|
12
|
+
# Windows under Git Bash / MSYS2 / Cygwin reports "mingw64_nt-10.0", "msys_nt-..", or
|
|
13
|
+
# "cygwin_nt-.." for `uname -s`; normalize all of them to "windows" and add the .exe suffix.
|
|
14
|
+
# (`uname -m` already returns "x86_64" there, matching the release artifact name.)
|
|
15
|
+
case "${OS}" in
|
|
16
|
+
mingw* | msys* | cygwin* | windows*) OS="windows"; EXT=".exe" ;;
|
|
17
|
+
esac
|
|
18
|
+
|
|
19
|
+
BIN="${DIR}/tokelang-cli-${OS}-${ARCH}${EXT}"
|
|
20
|
+
|
|
21
|
+
if [[ ! -x "${BIN}" ]]; then
|
|
22
|
+
echo "tokelang-cli: no bundled binary for ${OS}-${ARCH} (expected ${BIN})." >&2
|
|
23
|
+
echo "tokelang-cli: reinstall the plugin (npx @tokelang-lite/claude-code-skill)," >&2
|
|
24
|
+
echo "tokelang-cli: or build from source (cargo build --release -p tokelang-cli)." >&2
|
|
25
|
+
exit 127
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
exec "${BIN}" "$@"
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh\""
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"PreToolUse": [
|
|
14
|
+
{
|
|
15
|
+
"matcher": "Task",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/pre-tool-use.sh\""
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"Stop": [
|
|
25
|
+
{
|
|
26
|
+
"hooks": [
|
|
27
|
+
{
|
|
28
|
+
"type": "command",
|
|
29
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/stop.sh\""
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Tokelang PreToolUse hook
|
|
3
|
+
# Fires before the model invokes a tool. Matcher in hooks.json restricts this to the Task tool
|
|
4
|
+
# (subagent invocations) — other tools pass through untouched.
|
|
5
|
+
#
|
|
6
|
+
# Why Task only:
|
|
7
|
+
# The Task tool invokes a subagent with a prompt argument that is often long verbose prose
|
|
8
|
+
# ("research X, then summarize Y, then check Z"). Subagent context bloat is a real cost
|
|
9
|
+
# on multi-turn agent loops. updatedInput field actually replaces the input (unlike
|
|
10
|
+
# UserPromptSubmit / PostToolUse which are additive-only). So this is the one place
|
|
11
|
+
# where the plugin can do real input compression.
|
|
12
|
+
#
|
|
13
|
+
# Reads stdin JSON: { tool_name, tool_input, session_id, ... }
|
|
14
|
+
# Writes stdout JSON: { hookSpecificOutput: { updatedInput: { ... } } } to replace tool args.
|
|
15
|
+
|
|
16
|
+
set -euo pipefail
|
|
17
|
+
|
|
18
|
+
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(dirname "$(dirname "$(readlink -f "$0")")")}"
|
|
19
|
+
SETTINGS_FILE="${HOME}/.claude/settings.json"
|
|
20
|
+
CLI_BIN="${PLUGIN_ROOT}/bin/tokelang-cli-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
|
21
|
+
|
|
22
|
+
LEVEL="2"
|
|
23
|
+
if [[ -f "${SETTINGS_FILE}" ]]; then
|
|
24
|
+
LEVEL="$(jq -r '.["tokelang.level"] // "2"' "${SETTINGS_FILE}" 2>/dev/null || echo "2")"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
STDIN_JSON="$(cat)"
|
|
28
|
+
|
|
29
|
+
# L1 / off: pass through unchanged (still need to emit valid JSON)
|
|
30
|
+
case "${LEVEL}" in
|
|
31
|
+
"1"|"off"|"")
|
|
32
|
+
echo '{}'; exit 0
|
|
33
|
+
;;
|
|
34
|
+
esac
|
|
35
|
+
|
|
36
|
+
TOOL_NAME="$(echo "${STDIN_JSON}" | jq -r '.tool_name // empty')"
|
|
37
|
+
PROMPT="$(echo "${STDIN_JSON}" | jq -r '.tool_input.prompt // empty')"
|
|
38
|
+
|
|
39
|
+
# Only act on Task tool (matcher should already restrict this, defensive check anyway)
|
|
40
|
+
if [[ "${TOOL_NAME}" != "Task" ]]; then
|
|
41
|
+
echo '{}'; exit 0
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# Nothing to compress
|
|
45
|
+
if [[ -z "${PROMPT}" || "${#PROMPT}" -lt 200 ]]; then
|
|
46
|
+
echo '{}'; exit 0
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# Auto-clarity escape hatch
|
|
50
|
+
if echo "${PROMPT}" | grep -qiE "(password|secret|api[ _-]?key|delete|drop table|rm -rf|force.push|production)"; then
|
|
51
|
+
echo '{}'; exit 0
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# Compress in subagent_input mode (tighter recall floor 0.90)
|
|
55
|
+
COMPRESSED="$(echo "${PROMPT}" | "${CLI_BIN}" compress --mode subagent_input 2>/dev/null || echo "${PROMPT}")"
|
|
56
|
+
|
|
57
|
+
if [[ -z "${COMPRESSED}" || "${COMPRESSED}" == "${PROMPT}" ]]; then
|
|
58
|
+
echo '{}'; exit 0
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
# Log savings
|
|
62
|
+
SESSION_ID="$(echo "${STDIN_JSON}" | jq -r '.session_id // "unknown"')"
|
|
63
|
+
SESSION_SIDECAR="${HOME}/.claude/.tokelang-session-${SESSION_ID}"
|
|
64
|
+
ORIG_TOKENS="$(echo "${PROMPT}" | "${CLI_BIN}" count --tokenizer cl100k 2>/dev/null || echo "0")"
|
|
65
|
+
COMP_TOKENS="$(echo "${COMPRESSED}" | "${CLI_BIN}" count --tokenizer cl100k 2>/dev/null || echo "0")"
|
|
66
|
+
echo "subagent,${ORIG_TOKENS},${COMP_TOKENS},$(date +%s)" >> "${SESSION_SIDECAR}" 2>/dev/null || true
|
|
67
|
+
|
|
68
|
+
# Emit hookSpecificOutput with updatedInput — the field that ACTUALLY replaces tool args
|
|
69
|
+
# Build a new tool_input object with the compressed prompt
|
|
70
|
+
UPDATED_INPUT="$(echo "${STDIN_JSON}" | jq --arg p "${COMPRESSED}" '.tool_input | .prompt = $p')"
|
|
71
|
+
jq -n --argjson ui "${UPDATED_INPUT}" '{
|
|
72
|
+
hookSpecificOutput: {
|
|
73
|
+
hookEventName: "PreToolUse",
|
|
74
|
+
updatedInput: $ui
|
|
75
|
+
}
|
|
76
|
+
}'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Tokelang SessionStart hook
|
|
3
|
+
# Fires on session start/resume/clear/compact.
|
|
4
|
+
# Responsibilities:
|
|
5
|
+
# 1. Load level setting from ~/.claude/settings.json
|
|
6
|
+
# 2. Emit the output style guide via additionalContext (only at L1+; off → no injection)
|
|
7
|
+
# 3. Emit one-line off-switch reminder so user always knows how to disable
|
|
8
|
+
#
|
|
9
|
+
# Reads stdin JSON: { session_id, transcript_path, cwd, model, source }
|
|
10
|
+
# Writes stdout JSON with optional { additionalContext: "..." }
|
|
11
|
+
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
|
|
14
|
+
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(dirname "$(dirname "$(readlink -f "$0")")")}"
|
|
15
|
+
SETTINGS_FILE="${HOME}/.claude/settings.json"
|
|
16
|
+
CLI_BIN="${PLUGIN_ROOT}/bin/tokelang-cli-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
|
17
|
+
|
|
18
|
+
# Default level if settings missing or unreadable
|
|
19
|
+
LEVEL="2"
|
|
20
|
+
if [[ -f "${SETTINGS_FILE}" ]]; then
|
|
21
|
+
LEVEL="$(jq -r '.["tokelang.level"] // "2"' "${SETTINGS_FILE}" 2>/dev/null || echo "2")"
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
# Read source field from stdin (startup / resume / clear / compact)
|
|
25
|
+
STDIN_JSON="$(cat)"
|
|
26
|
+
SOURCE="$(echo "${STDIN_JSON}" | jq -r '.source // "startup"' 2>/dev/null || echo "startup")"
|
|
27
|
+
|
|
28
|
+
# If level is off, emit nothing — skill stays loaded but inert
|
|
29
|
+
if [[ "${LEVEL}" == "off" ]]; then
|
|
30
|
+
echo '{}'
|
|
31
|
+
exit 0
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# Style-guide content varies by level
|
|
35
|
+
case "${LEVEL}" in
|
|
36
|
+
"1") STYLE="lite" ;;
|
|
37
|
+
"2") STYLE="lite" ;;
|
|
38
|
+
"3") STYLE="medium" ;;
|
|
39
|
+
*) STYLE="lite" ;; # custom or unknown → conservative default
|
|
40
|
+
esac
|
|
41
|
+
|
|
42
|
+
# Build the additionalContext payload
|
|
43
|
+
case "${STYLE}" in
|
|
44
|
+
"lite")
|
|
45
|
+
CONTEXT="Tokelang is active at level ${LEVEL}. Respond concisely. Drop pleasantries, hedges, and filler. Be direct. Run /tokelang-level off any time to disable."
|
|
46
|
+
;;
|
|
47
|
+
"medium")
|
|
48
|
+
CONTEXT="Tokelang is active at level ${LEVEL} (aggressive). Respond in compact form: fragments OK, drop articles where unambiguous, use bullet/key:value over prose paragraphs. Code blocks and exact quotations stay verbatim. Run /tokelang-level 2 or off to dial back."
|
|
49
|
+
;;
|
|
50
|
+
esac
|
|
51
|
+
|
|
52
|
+
# Emit JSON with additionalContext
|
|
53
|
+
jq -n --arg ctx "${CONTEXT}" '{additionalContext: $ctx}'
|
package/hooks/stop.sh
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Tokelang Stop hook
|
|
3
|
+
# Fires when the session ends or pauses.
|
|
4
|
+
# Responsibilities:
|
|
5
|
+
# 1. Read this session's sidecar (compression events logged during the session)
|
|
6
|
+
# 2. Aggregate token savings
|
|
7
|
+
# 3. Update ~/.claude/.tokelang-lifetime.json with cumulative totals
|
|
8
|
+
# 4. Write the statusline suffix file so next session's statusline shows updated number
|
|
9
|
+
#
|
|
10
|
+
# Reads stdin JSON: { session_id, transcript_path, ... }
|
|
11
|
+
# No stdout required.
|
|
12
|
+
|
|
13
|
+
set -euo pipefail
|
|
14
|
+
|
|
15
|
+
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(dirname "$(dirname "$(readlink -f "$0")")")}"
|
|
16
|
+
LIFETIME_FILE="${HOME}/.claude/.tokelang-lifetime.json"
|
|
17
|
+
STATUSLINE_SUFFIX="${HOME}/.claude/.tokelang-statusline-suffix"
|
|
18
|
+
CLI_BIN="${PLUGIN_ROOT}/bin/tokelang-cli-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
|
|
19
|
+
|
|
20
|
+
STDIN_JSON="$(cat)"
|
|
21
|
+
SESSION_ID="$(echo "${STDIN_JSON}" | jq -r '.session_id // "unknown"')"
|
|
22
|
+
SESSION_SIDECAR="${HOME}/.claude/.tokelang-session-${SESSION_ID}"
|
|
23
|
+
|
|
24
|
+
[[ ! -f "${SESSION_SIDECAR}" ]] && exit 0 # nothing to aggregate
|
|
25
|
+
|
|
26
|
+
# Aggregate this session's savings via the CLI — the single source of truth for the sidecar
|
|
27
|
+
# schema. Each sidecar line is "surface,orig_tokens,comp_tokens,unix_ts" (written by the hooks);
|
|
28
|
+
# `tokelang-cli stats` sums (orig - comp) across all rows and emits JSON. Fall back to {} if the
|
|
29
|
+
# CLI or jq is unavailable so the Stop hook never fails the session.
|
|
30
|
+
STATS_JSON="$("${CLI_BIN}" stats --transcript "${SESSION_SIDECAR}" 2>/dev/null || echo '{}')"
|
|
31
|
+
TOTAL_SAVED="$(echo "${STATS_JSON}" | jq -r '.tokens_saved // 0' 2>/dev/null || echo 0)"
|
|
32
|
+
TOTAL_SAVED="${TOTAL_SAVED:-0}"
|
|
33
|
+
|
|
34
|
+
# Read or initialize lifetime
|
|
35
|
+
if [[ -f "${LIFETIME_FILE}" ]]; then
|
|
36
|
+
LIFETIME_TOKENS=$(jq -r '.lifetime_tokens_saved // 0' "${LIFETIME_FILE}")
|
|
37
|
+
LIFETIME_SESSIONS=$(jq -r '.sessions_count // 0' "${LIFETIME_FILE}")
|
|
38
|
+
else
|
|
39
|
+
LIFETIME_TOKENS=0
|
|
40
|
+
LIFETIME_SESSIONS=0
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
NEW_LIFETIME=$((LIFETIME_TOKENS + TOTAL_SAVED))
|
|
44
|
+
NEW_SESSIONS=$((LIFETIME_SESSIONS + 1))
|
|
45
|
+
|
|
46
|
+
# Update lifetime file
|
|
47
|
+
jq -n --argjson t "${NEW_LIFETIME}" --argjson s "${NEW_SESSIONS}" \
|
|
48
|
+
'{lifetime_tokens_saved: $t, sessions_count: $s, last_updated: now | todateiso8601}' \
|
|
49
|
+
> "${LIFETIME_FILE}"
|
|
50
|
+
|
|
51
|
+
# Update statusline suffix — short form, fits in statusline
|
|
52
|
+
# Rough $ estimate at Sonnet 4.6 input rate ($3/MTok): tokens * 3 / 1_000_000
|
|
53
|
+
USD=$(awk -v t="${NEW_LIFETIME}" 'BEGIN {printf "%.2f", t * 3 / 1000000}')
|
|
54
|
+
echo "tokelang: ${NEW_LIFETIME} tok saved (~\$${USD})" > "${STATUSLINE_SUFFIX}"
|
|
55
|
+
|
|
56
|
+
# --- Opt-in telemetry (OFF by default) -------------------------------------------------
|
|
57
|
+
# Sends AGGREGATE token-savings counts only — NEVER prompt content. (The sidecar itself
|
|
58
|
+
# stores only "surface,orig,comp,ts" per line, so there is literally no content to leak.)
|
|
59
|
+
# Fires ONLY when ~/.claude/.tokelang-telemetry.json says {"enabled": true}; absent file =
|
|
60
|
+
# off. Toggle with the /tokelang-telemetry skill. Best-effort: needs curl, hard-bounded to
|
|
61
|
+
# 3s, detached and fire-and-forget so it can neither block nor fail the session end.
|
|
62
|
+
TELEMETRY_FILE="${HOME}/.claude/.tokelang-telemetry.json"
|
|
63
|
+
maybe_send_telemetry() {
|
|
64
|
+
command -v curl >/dev/null 2>&1 || return 0
|
|
65
|
+
[[ -f "${TELEMETRY_FILE}" ]] || return 0
|
|
66
|
+
local enabled anon_id endpoint level os arch events payload
|
|
67
|
+
enabled="$(jq -r '.enabled // false' "${TELEMETRY_FILE}" 2>/dev/null || echo false)"
|
|
68
|
+
[[ "${enabled}" == "true" ]] || return 0
|
|
69
|
+
anon_id="$(jq -r '.anon_id // "unknown"' "${TELEMETRY_FILE}" 2>/dev/null || echo unknown)"
|
|
70
|
+
endpoint="${TOKELANG_TELEMETRY_ENDPOINT:-https://tokelang.com/v1/telemetry}"
|
|
71
|
+
level="$(jq -r '.["tokelang.level"] // "unknown"' "${HOME}/.claude/settings.json" 2>/dev/null || echo unknown)"
|
|
72
|
+
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
|
73
|
+
arch="$(uname -m)"
|
|
74
|
+
events="$(echo "${STATS_JSON}" | jq -r '.events // 0' 2>/dev/null || echo 0)"
|
|
75
|
+
# Aggregate-only payload: no session_id, no file paths, no prompt text.
|
|
76
|
+
payload="$(jq -n \
|
|
77
|
+
--arg aid "${anon_id}" --arg cli "1.0.0" --arg lvl "${level}" \
|
|
78
|
+
--arg os "${os}" --arg arch "${arch}" \
|
|
79
|
+
--argjson ss "${TOTAL_SAVED}" --argjson ev "${events}" \
|
|
80
|
+
--argjson lt "${NEW_LIFETIME}" --argjson sc "${NEW_SESSIONS}" \
|
|
81
|
+
'{schema:1, event:"session_stop", anon_id:$aid, cli_version:$cli, level:$lvl, os:$os, arch:$arch, session_tokens_saved:$ss, session_events:$ev, lifetime_tokens_saved:$lt, sessions_count:$sc}' \
|
|
82
|
+
2>/dev/null)" || return 0
|
|
83
|
+
[[ -n "${payload}" ]] || return 0
|
|
84
|
+
( nohup curl -fsS -m 3 -X POST -H 'Content-Type: application/json' \
|
|
85
|
+
-d "${payload}" "${endpoint}" >/dev/null 2>&1 & ) 2>/dev/null || true
|
|
86
|
+
}
|
|
87
|
+
maybe_send_telemetry || true
|
|
88
|
+
|
|
89
|
+
# Cleanup session sidecar (lifetime already aggregated)
|
|
90
|
+
rm -f "${SESSION_SIDECAR}"
|