xithead 1.1.0__tar.gz

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.
xithead-1.1.0/LICENSE ADDED
@@ -0,0 +1,190 @@
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 the 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 reasonable and customary use in describing the
141
+ origin of the Work and 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 choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Headroom Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
xithead-1.1.0/PKG-INFO ADDED
@@ -0,0 +1,264 @@
1
+ Metadata-Version: 2.4
2
+ Name: xithead
3
+ Version: 1.1.0
4
+ Summary: Aggressive Claude context optimizer by Xtream-ITSolutions UG - Cut costs by 50-95%
5
+ Author-email: Xtream-ITSolutions UG <hello@xtream-itsolutions.com>
6
+ Project-URL: Homepage, https://github.com/xtream-itsolutions/headroom
7
+ Project-URL: Discord, https://discord.gg/xtream-itsolutions
8
+ Keywords: claude,anthropic,llm,token,optimization,caching,proxy,ai
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: click>=8.1.0
18
+ Provides-Extra: proxy
19
+ Requires-Dist: fastapi>=0.100.0; extra == "proxy"
20
+ Requires-Dist: uvicorn<1.0,>=0.23.0; extra == "proxy"
21
+ Requires-Dist: httpx>=0.24.0; extra == "proxy"
22
+ Provides-Extra: full
23
+ Requires-Dist: xithead[proxy]; extra == "full"
24
+ Dynamic: license-file
25
+
26
+ <div align="center">
27
+ <img src="https://cdn.xtream-itsolutions.com/u/logo.png" alt="Xtream-ITSolutions UG" width="160" />
28
+ <h1>xithead</h1>
29
+ <p><strong>Aggressive Claude Context Optimizer — bis zu 95% Token-Einsparung</strong></p>
30
+ <p>
31
+ <a href="https://pypi.org/project/xithead/"><img src="https://img.shields.io/pypi/v/xithead?color=00d4ff&label=PyPI&style=flat-square" alt="PyPI" /></a>
32
+ <a href="https://www.npmjs.com/package/xithead"><img src="https://img.shields.io/npm/v/xithead?color=e879f9&label=npm&style=flat-square" alt="npm" /></a>
33
+ <a href="https://discord.gg/xtream-itsolutions"><img src="https://img.shields.io/badge/Discord-Join-5865F2?style=flat-square&logo=discord&logoColor=white" alt="Discord" /></a>
34
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-10b981?style=flat-square" alt="License" /></a>
35
+ </p>
36
+ <p>
37
+ <a href="https://discord.gg/xtream-itsolutions">💬 Discord</a> ·
38
+ <a href="https://github.com/xtream-itsolutions/headroom/issues">🐛 Bug melden</a> ·
39
+ <a href="https://github.com/xtream-itsolutions/headroom/issues">✨ Feature anfragen</a>
40
+ </p>
41
+ </div>
42
+
43
+ ---
44
+
45
+ ## Was ist xithead?
46
+
47
+ **xithead** ist ein Claude-spezifischer Context Optimizer von **Xtream-ITSolutions UG**.
48
+ Er sitzt zwischen deiner App und der Claude API, komprimiert Prompts aggressiv und cached Antworten — du sendest weniger Tokens und zahlst deutlich weniger.
49
+
50
+ - **Drop-in Proxy** — keine Code-Änderungen nötig
51
+ - **Immer Sonnet 4.6** — das beste Modell, automatisch gepinnt
52
+ - **Ultra-Modus standardmäßig** — 50–95% Einsparung ab dem ersten Request
53
+ - **Live Dashboard** — Einsparungen in Echtzeit auf `localhost:8787/dashboard`
54
+
55
+ ---
56
+
57
+ ## Schnellstart — Windows (empfohlen)
58
+
59
+ ```powershell
60
+ # PowerShell als Administrator, einmalig:
61
+ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
62
+ iex (irm https://raw.githubusercontent.com/xtream-itsolutions/headroom/main/headroom.ps1)
63
+ ```
64
+
65
+ Danach neues Terminal öffnen und loslegen:
66
+
67
+ ```powershell
68
+ xithead # Claude starten — ultra-aggressiv, 50-95% Einsparung
69
+ xithead-proxy # Proxy + Dashboard auf http://localhost:8787/dashboard
70
+ xithead-stats # Einsparungen anzeigen
71
+ xithead-update # xithead aktualisieren
72
+ xithead-help # Alle Befehle
73
+ ```
74
+
75
+ > **VS Code:** Terminal mit `Strg+\`` öffnen, PowerShell wählen, `xithead` eingeben — fertig.
76
+
77
+ ---
78
+
79
+ ## Installation
80
+
81
+ ### Python
82
+
83
+ ```bash
84
+ pip install xithead # nur CLI + Optimizer
85
+ pip install "xithead[proxy]" # + Proxy + Dashboard (empfohlen)
86
+ ```
87
+
88
+ ### npm / Node.js
89
+
90
+ ```bash
91
+ npm install -g xithead
92
+ ```
93
+
94
+ ---
95
+
96
+ ## CLI Befehle
97
+
98
+ ```bash
99
+ xithead proxy # Proxy starten (Port 8787) + Dashboard
100
+ xithead optimize "prompt" # Prompt optimieren und Einsparung zeigen
101
+ xithead stats # Session-Statistiken
102
+ xithead cache stats # Cache-Statistiken
103
+ xithead cache clear # Cache leeren
104
+ xithead model set claude-sonnet-4-6 # Modell setzen
105
+ xithead model show # Aktuelles Modell anzeigen
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Features
111
+
112
+ | Feature | Beschreibung | Einsparung |
113
+ |---------|-------------|------------|
114
+ | 🔥 **Prompt Caching** | `cache_control`-Marker automatisch injizieren | Bis 90% auf Cache-Hits |
115
+ | 🗜️ **Context Compression** | Redundanz entfernen, Nachrichten deduplizieren | 30–60% weniger Tokens |
116
+ | 💾 **Multi-Layer Cache** | RAM + SQLite, SHA-256 Keys, TTL | Wiederholte Calls gratis |
117
+ | ✂️ **Context Trim** | Alten Context trimmen (verhindert 400-Fehler) | Spart Input-Tokens |
118
+ | 📉 **Verbosity Reduction** | System-Prompts komprimieren | 10–40% Einsparung |
119
+ | 📊 **Live Dashboard** | Token- & Kosten-Tracking in Echtzeit | Volle Transparenz |
120
+ | 🔌 **Drop-in Proxy** | Keine Code-Änderungen | Funktioniert mit jedem Client |
121
+
122
+ ---
123
+
124
+ ## Einsparungs-Beispiele
125
+
126
+ | Anwendungsfall | Original | Nach xithead | Gespart |
127
+ |----------------|----------|--------------|---------|
128
+ | Code-Review (wiederholter Kontext) | 50.000 Tokens | 4.000 Tokens | **92%** |
129
+ | Chat mit langem System-Prompt | 10.000 Tokens | 2.000 Tokens | **80%** |
130
+ | Agentischer Loop (Tool-Ergebnisse) | 100.000 Tokens | 25.000 Tokens | **75%** |
131
+ | Einfaches Q&A | 500 Tokens | 400 Tokens | ~20% |
132
+
133
+ ---
134
+
135
+ ## Python API
136
+
137
+ ```python
138
+ from xithead import optimize_for_claude
139
+
140
+ messages = [{"role": "user", "content": "Sehr langer Prompt hier..."}]
141
+ result = optimize_for_claude(messages, model="claude-sonnet-4-6")
142
+
143
+ print(f"Tokens gespart: {result.tokens_saved}")
144
+ print(f"Kosten gespart: ${result.cost_saved_usd:.4f}")
145
+ print(f"Kompression: {result.compression_ratio:.1%}")
146
+ print(f"Cache-Hit: {result.cache_hit}")
147
+
148
+ # Optimierte messages an Anthropic API übergeben:
149
+ # client.messages.create(messages=result.messages, ...)
150
+ ```
151
+
152
+ ### Konfiguration
153
+
154
+ ```python
155
+ from xithead.claude_optimizer import ClaudeOptimizer, ClaudeOptimizerConfig
156
+
157
+ config = ClaudeOptimizerConfig(
158
+ enable_prompt_caching=True,
159
+ enable_dedup=True,
160
+ enable_verbosity_reduction=True,
161
+ enable_context_trim=True,
162
+ max_context_tokens=180_000,
163
+ cache_ttl_seconds=86400,
164
+ )
165
+ optimizer = ClaudeOptimizer(config)
166
+ result = optimizer.optimize(messages, system="Du bist ein hilfreicher Assistent.", model="claude-sonnet-4-6")
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Node.js / JavaScript API
172
+
173
+ ```javascript
174
+ const { optimize, createOptimizedClient, injectCacheControl } = require('xithead');
175
+ const Anthropic = require('@anthropic-ai/sdk');
176
+
177
+ // Option 1: Manuell optimieren
178
+ const result = optimize({ messages, system, model: 'claude-sonnet-4-6' });
179
+ console.log(result.tokensSaved, result.costSavedUsd);
180
+
181
+ // Option 2: Wrapped Client (optimiert automatisch jeden Call)
182
+ const client = new Anthropic();
183
+ const xitClient = createOptimizedClient(client);
184
+ const response = await xitClient.messages.create({
185
+ model: 'claude-sonnet-4-6',
186
+ max_tokens: 1024,
187
+ messages: [{ role: 'user', content: 'Hallo!' }],
188
+ });
189
+ console.log(xitClient.getStats());
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Proxy-Modus (Zero Code Changes)
195
+
196
+ ```bash
197
+ # Proxy starten
198
+ xithead proxy --port 8787
199
+
200
+ # Dashboard öffnen
201
+ # → http://localhost:8787/dashboard
202
+
203
+ # Deinen Claude Client auf den Proxy zeigen lassen:
204
+ export ANTHROPIC_BASE_URL=http://localhost:8787
205
+ claude # oder jede andere App
206
+ ```
207
+
208
+ In PowerShell:
209
+ ```powershell
210
+ $env:ANTHROPIC_BASE_URL = "http://localhost:8787"
211
+ claude
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Wie es funktioniert
217
+
218
+ ```
219
+ Deine App → xithead Proxy → Optimierter Request → Claude API
220
+
221
+ ├─ Cache-Lookup (API-Call überspringen wenn gecacht)
222
+ ├─ Nachrichten-Deduplizierung
223
+ ├─ System-Prompt Kompression
224
+ ├─ cache_control Marker injizieren
225
+ ├─ Context-Window Trim (verhindert 400-Fehler)
226
+ └─ Token/Kosten-Tracking
227
+ ```
228
+
229
+ ---
230
+
231
+ ## Umgebungsvariablen
232
+
233
+ | Variable | Standardwert | Beschreibung |
234
+ |----------|-------------|--------------|
235
+ | `XITHEAD_MODEL` | `claude-sonnet-4-6` | Claude-Modell |
236
+ | `XITHEAD_ENABLE_CACHE_CONTROL` | `1` | Prompt-Caching aktivieren |
237
+ | `XITHEAD_ENABLE_DEDUP` | `1` | Nachrichten-Dedup aktivieren |
238
+ | `XITHEAD_ENABLE_CONTEXT_TRIM` | `1` | Context-Trim aktivieren |
239
+ | `HEADROOM_COMPRESSION_RATIO_TARGET` | `0.3` | Kompressions-Ziel (0.3 = 70%) |
240
+ | `HEADROOM_STRENGTH` | `aggressive` | Kompressions-Stärke |
241
+ | `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | `2048` | Max. Output-Tokens |
242
+
243
+ ---
244
+
245
+ ## Beitragen
246
+
247
+ Wir freuen uns über Beiträge! Öffne ein Issue oder Pull Request.
248
+
249
+ Tritt unserer Community bei: [discord.gg/xtream-itsolutions](https://discord.gg/xtream-itsolutions)
250
+
251
+ ---
252
+
253
+ ## Lizenz
254
+
255
+ Apache 2.0 — siehe [LICENSE](LICENSE).
256
+
257
+ ---
258
+
259
+ <div align="center">
260
+ <p>Made with ❤️ by <a href="https://xtream-itsolutions.com"><strong>Xtream-ITSolutions UG</strong></a></p>
261
+ <a href="https://discord.gg/xtream-itsolutions">
262
+ <img src="https://img.shields.io/badge/Discord-Community_beitreten-5865F2?style=for-the-badge&logo=discord&logoColor=white" alt="Discord" />
263
+ </a>
264
+ </div>
@@ -0,0 +1,239 @@
1
+ <div align="center">
2
+ <img src="https://cdn.xtream-itsolutions.com/u/logo.png" alt="Xtream-ITSolutions UG" width="160" />
3
+ <h1>xithead</h1>
4
+ <p><strong>Aggressive Claude Context Optimizer — bis zu 95% Token-Einsparung</strong></p>
5
+ <p>
6
+ <a href="https://pypi.org/project/xithead/"><img src="https://img.shields.io/pypi/v/xithead?color=00d4ff&label=PyPI&style=flat-square" alt="PyPI" /></a>
7
+ <a href="https://www.npmjs.com/package/xithead"><img src="https://img.shields.io/npm/v/xithead?color=e879f9&label=npm&style=flat-square" alt="npm" /></a>
8
+ <a href="https://discord.gg/xtream-itsolutions"><img src="https://img.shields.io/badge/Discord-Join-5865F2?style=flat-square&logo=discord&logoColor=white" alt="Discord" /></a>
9
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-10b981?style=flat-square" alt="License" /></a>
10
+ </p>
11
+ <p>
12
+ <a href="https://discord.gg/xtream-itsolutions">💬 Discord</a> ·
13
+ <a href="https://github.com/xtream-itsolutions/headroom/issues">🐛 Bug melden</a> ·
14
+ <a href="https://github.com/xtream-itsolutions/headroom/issues">✨ Feature anfragen</a>
15
+ </p>
16
+ </div>
17
+
18
+ ---
19
+
20
+ ## Was ist xithead?
21
+
22
+ **xithead** ist ein Claude-spezifischer Context Optimizer von **Xtream-ITSolutions UG**.
23
+ Er sitzt zwischen deiner App und der Claude API, komprimiert Prompts aggressiv und cached Antworten — du sendest weniger Tokens und zahlst deutlich weniger.
24
+
25
+ - **Drop-in Proxy** — keine Code-Änderungen nötig
26
+ - **Immer Sonnet 4.6** — das beste Modell, automatisch gepinnt
27
+ - **Ultra-Modus standardmäßig** — 50–95% Einsparung ab dem ersten Request
28
+ - **Live Dashboard** — Einsparungen in Echtzeit auf `localhost:8787/dashboard`
29
+
30
+ ---
31
+
32
+ ## Schnellstart — Windows (empfohlen)
33
+
34
+ ```powershell
35
+ # PowerShell als Administrator, einmalig:
36
+ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
37
+ iex (irm https://raw.githubusercontent.com/xtream-itsolutions/headroom/main/headroom.ps1)
38
+ ```
39
+
40
+ Danach neues Terminal öffnen und loslegen:
41
+
42
+ ```powershell
43
+ xithead # Claude starten — ultra-aggressiv, 50-95% Einsparung
44
+ xithead-proxy # Proxy + Dashboard auf http://localhost:8787/dashboard
45
+ xithead-stats # Einsparungen anzeigen
46
+ xithead-update # xithead aktualisieren
47
+ xithead-help # Alle Befehle
48
+ ```
49
+
50
+ > **VS Code:** Terminal mit `Strg+\`` öffnen, PowerShell wählen, `xithead` eingeben — fertig.
51
+
52
+ ---
53
+
54
+ ## Installation
55
+
56
+ ### Python
57
+
58
+ ```bash
59
+ pip install xithead # nur CLI + Optimizer
60
+ pip install "xithead[proxy]" # + Proxy + Dashboard (empfohlen)
61
+ ```
62
+
63
+ ### npm / Node.js
64
+
65
+ ```bash
66
+ npm install -g xithead
67
+ ```
68
+
69
+ ---
70
+
71
+ ## CLI Befehle
72
+
73
+ ```bash
74
+ xithead proxy # Proxy starten (Port 8787) + Dashboard
75
+ xithead optimize "prompt" # Prompt optimieren und Einsparung zeigen
76
+ xithead stats # Session-Statistiken
77
+ xithead cache stats # Cache-Statistiken
78
+ xithead cache clear # Cache leeren
79
+ xithead model set claude-sonnet-4-6 # Modell setzen
80
+ xithead model show # Aktuelles Modell anzeigen
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Features
86
+
87
+ | Feature | Beschreibung | Einsparung |
88
+ |---------|-------------|------------|
89
+ | 🔥 **Prompt Caching** | `cache_control`-Marker automatisch injizieren | Bis 90% auf Cache-Hits |
90
+ | 🗜️ **Context Compression** | Redundanz entfernen, Nachrichten deduplizieren | 30–60% weniger Tokens |
91
+ | 💾 **Multi-Layer Cache** | RAM + SQLite, SHA-256 Keys, TTL | Wiederholte Calls gratis |
92
+ | ✂️ **Context Trim** | Alten Context trimmen (verhindert 400-Fehler) | Spart Input-Tokens |
93
+ | 📉 **Verbosity Reduction** | System-Prompts komprimieren | 10–40% Einsparung |
94
+ | 📊 **Live Dashboard** | Token- & Kosten-Tracking in Echtzeit | Volle Transparenz |
95
+ | 🔌 **Drop-in Proxy** | Keine Code-Änderungen | Funktioniert mit jedem Client |
96
+
97
+ ---
98
+
99
+ ## Einsparungs-Beispiele
100
+
101
+ | Anwendungsfall | Original | Nach xithead | Gespart |
102
+ |----------------|----------|--------------|---------|
103
+ | Code-Review (wiederholter Kontext) | 50.000 Tokens | 4.000 Tokens | **92%** |
104
+ | Chat mit langem System-Prompt | 10.000 Tokens | 2.000 Tokens | **80%** |
105
+ | Agentischer Loop (Tool-Ergebnisse) | 100.000 Tokens | 25.000 Tokens | **75%** |
106
+ | Einfaches Q&A | 500 Tokens | 400 Tokens | ~20% |
107
+
108
+ ---
109
+
110
+ ## Python API
111
+
112
+ ```python
113
+ from xithead import optimize_for_claude
114
+
115
+ messages = [{"role": "user", "content": "Sehr langer Prompt hier..."}]
116
+ result = optimize_for_claude(messages, model="claude-sonnet-4-6")
117
+
118
+ print(f"Tokens gespart: {result.tokens_saved}")
119
+ print(f"Kosten gespart: ${result.cost_saved_usd:.4f}")
120
+ print(f"Kompression: {result.compression_ratio:.1%}")
121
+ print(f"Cache-Hit: {result.cache_hit}")
122
+
123
+ # Optimierte messages an Anthropic API übergeben:
124
+ # client.messages.create(messages=result.messages, ...)
125
+ ```
126
+
127
+ ### Konfiguration
128
+
129
+ ```python
130
+ from xithead.claude_optimizer import ClaudeOptimizer, ClaudeOptimizerConfig
131
+
132
+ config = ClaudeOptimizerConfig(
133
+ enable_prompt_caching=True,
134
+ enable_dedup=True,
135
+ enable_verbosity_reduction=True,
136
+ enable_context_trim=True,
137
+ max_context_tokens=180_000,
138
+ cache_ttl_seconds=86400,
139
+ )
140
+ optimizer = ClaudeOptimizer(config)
141
+ result = optimizer.optimize(messages, system="Du bist ein hilfreicher Assistent.", model="claude-sonnet-4-6")
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Node.js / JavaScript API
147
+
148
+ ```javascript
149
+ const { optimize, createOptimizedClient, injectCacheControl } = require('xithead');
150
+ const Anthropic = require('@anthropic-ai/sdk');
151
+
152
+ // Option 1: Manuell optimieren
153
+ const result = optimize({ messages, system, model: 'claude-sonnet-4-6' });
154
+ console.log(result.tokensSaved, result.costSavedUsd);
155
+
156
+ // Option 2: Wrapped Client (optimiert automatisch jeden Call)
157
+ const client = new Anthropic();
158
+ const xitClient = createOptimizedClient(client);
159
+ const response = await xitClient.messages.create({
160
+ model: 'claude-sonnet-4-6',
161
+ max_tokens: 1024,
162
+ messages: [{ role: 'user', content: 'Hallo!' }],
163
+ });
164
+ console.log(xitClient.getStats());
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Proxy-Modus (Zero Code Changes)
170
+
171
+ ```bash
172
+ # Proxy starten
173
+ xithead proxy --port 8787
174
+
175
+ # Dashboard öffnen
176
+ # → http://localhost:8787/dashboard
177
+
178
+ # Deinen Claude Client auf den Proxy zeigen lassen:
179
+ export ANTHROPIC_BASE_URL=http://localhost:8787
180
+ claude # oder jede andere App
181
+ ```
182
+
183
+ In PowerShell:
184
+ ```powershell
185
+ $env:ANTHROPIC_BASE_URL = "http://localhost:8787"
186
+ claude
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Wie es funktioniert
192
+
193
+ ```
194
+ Deine App → xithead Proxy → Optimierter Request → Claude API
195
+
196
+ ├─ Cache-Lookup (API-Call überspringen wenn gecacht)
197
+ ├─ Nachrichten-Deduplizierung
198
+ ├─ System-Prompt Kompression
199
+ ├─ cache_control Marker injizieren
200
+ ├─ Context-Window Trim (verhindert 400-Fehler)
201
+ └─ Token/Kosten-Tracking
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Umgebungsvariablen
207
+
208
+ | Variable | Standardwert | Beschreibung |
209
+ |----------|-------------|--------------|
210
+ | `XITHEAD_MODEL` | `claude-sonnet-4-6` | Claude-Modell |
211
+ | `XITHEAD_ENABLE_CACHE_CONTROL` | `1` | Prompt-Caching aktivieren |
212
+ | `XITHEAD_ENABLE_DEDUP` | `1` | Nachrichten-Dedup aktivieren |
213
+ | `XITHEAD_ENABLE_CONTEXT_TRIM` | `1` | Context-Trim aktivieren |
214
+ | `HEADROOM_COMPRESSION_RATIO_TARGET` | `0.3` | Kompressions-Ziel (0.3 = 70%) |
215
+ | `HEADROOM_STRENGTH` | `aggressive` | Kompressions-Stärke |
216
+ | `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | `2048` | Max. Output-Tokens |
217
+
218
+ ---
219
+
220
+ ## Beitragen
221
+
222
+ Wir freuen uns über Beiträge! Öffne ein Issue oder Pull Request.
223
+
224
+ Tritt unserer Community bei: [discord.gg/xtream-itsolutions](https://discord.gg/xtream-itsolutions)
225
+
226
+ ---
227
+
228
+ ## Lizenz
229
+
230
+ Apache 2.0 — siehe [LICENSE](LICENSE).
231
+
232
+ ---
233
+
234
+ <div align="center">
235
+ <p>Made with ❤️ by <a href="https://xtream-itsolutions.com"><strong>Xtream-ITSolutions UG</strong></a></p>
236
+ <a href="https://discord.gg/xtream-itsolutions">
237
+ <img src="https://img.shields.io/badge/Discord-Community_beitreten-5865F2?style=for-the-badge&logo=discord&logoColor=white" alt="Discord" />
238
+ </a>
239
+ </div>