@sunilaleti/hx 0.0.0-stage → 0.3.0-beta.1
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/CHANGELOG.md +1088 -0
- package/README.md +1317 -2
- package/dist/hx.js +91258 -0
- package/dist/hx.js.map +7 -0
- package/package.json +55 -4
package/README.md
CHANGED
|
@@ -1,3 +1,1318 @@
|
|
|
1
|
-
#
|
|
1
|
+
# HX
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An agent harness for the terminal. Python core, its own terminal renderer,
|
|
4
|
+
OpenRouter for models.
|
|
5
|
+
|
|
6
|
+
HX runs in your project directory, reads and edits your code, runs commands in
|
|
7
|
+
a sandboxed shell, and shows you what every turn costs.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install --global @sunilaleti/hx@next
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
HX runs on [Node.js](https://nodejs.org/) 22.15 or newer, on macOS and Linux.
|
|
18
|
+
Update with `hx upgrade`. The `@next` tag is the beta channel while the
|
|
19
|
+
TypeScript build is being tested; a beta upgrades to the next beta.
|
|
20
|
+
|
|
21
|
+
### `@sunilaleti/hx` on npm, `hx` in your terminal
|
|
22
|
+
|
|
23
|
+
The package is published as **`@sunilaleti/hx`**. The command it installs is
|
|
24
|
+
**`hx`**, and that is what you type - the longer name never appears again
|
|
25
|
+
after install. The plain name `hx` on npm belongs to another package.
|
|
26
|
+
|
|
27
|
+
| | Name |
|
|
28
|
+
|---|---|
|
|
29
|
+
| npm package | `@sunilaleti/hx` |
|
|
30
|
+
| Command | `hx` |
|
|
31
|
+
| Config directory | `~/.hx` |
|
|
32
|
+
|
|
33
|
+
If the command isn't found after installing, add npm's global bin directory
|
|
34
|
+
to your `PATH`:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
export PATH="$(npm prefix --global)/bin:$PATH"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The Python build, `hx-cli` on PyPI, keeps working on the same `~/.hx`:
|
|
41
|
+
sessions, sign-ins and settings carry over in both directions. Install one or
|
|
42
|
+
the other - both put a command named `hx` on your `PATH`.
|
|
43
|
+
|
|
44
|
+
### Credentials
|
|
45
|
+
|
|
46
|
+
HX reaches models over four routes. Which one serves a turn is decided by the
|
|
47
|
+
model id alone, so "what paid for that" is always answerable by reading it:
|
|
48
|
+
|
|
49
|
+
| Model id | Route | Billing |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `anthropic/claude-sonnet-4.5`, `openai/gpt-5`, … | OpenRouter | per token, API key |
|
|
52
|
+
| `openai-codex/gpt-5.6-terra` | ChatGPT Plus/Pro | your subscription |
|
|
53
|
+
| `devin/swe-1-6`, `devin/claude-opus-5`, … | Devin | your subscription |
|
|
54
|
+
| `claude-code/claude-sonnet-5`, `claude-code/claude-opus-4-8`, … | Claude Pro/Max, via Claude Code | your subscription |
|
|
55
|
+
|
|
56
|
+
Credentials live in `~/.hx/auth.json`, mode 0600, one entry per route - except
|
|
57
|
+
Claude Code's, which stays with Claude Code.
|
|
58
|
+
|
|
59
|
+
**OpenRouter.** On first run HX asks for a key. Get one at
|
|
60
|
+
<https://openrouter.ai/keys>. Change it later with `/configure` in the TUI, or:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
hx auth # which routes have a credential, and where from
|
|
64
|
+
hx auth set # paste a new OpenRouter key (hidden input)
|
|
65
|
+
hx auth clear # remove the saved key
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Resolution order is `HX_OPENROUTER_API_KEY`, then `OPENROUTER_API_KEY`, then
|
|
69
|
+
the saved file. The environment wins, and both `/configure` and `hx auth` say
|
|
70
|
+
so — otherwise saving a key while a variable is set looks like a no-op.
|
|
71
|
+
|
|
72
|
+
**ChatGPT Plus/Pro.** Sign in over OAuth and run Codex models against your
|
|
73
|
+
subscription instead of paying per token
|
|
74
|
+
([OpenAI endorses this for OSS harnesses](https://developers.openai.com/community/codex-for-oss)):
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
hx auth login openai-codex # or /login inside the TUI
|
|
78
|
+
hx --model openai-codex/gpt-5.6-terra
|
|
79
|
+
hx auth logout openai-codex
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The browser opens to `auth.openai.com` and redirects to a loopback listener on
|
|
83
|
+
port 1455. Over SSH that redirect cannot reach your machine, so paste the final
|
|
84
|
+
URL into the prompt instead — or set `HX_LOGIN_DEVICE_CODE=1` for the
|
|
85
|
+
device-code flow. Access tokens are refreshed automatically; `/model` only
|
|
86
|
+
offers routes you are actually signed in to.
|
|
87
|
+
|
|
88
|
+
`hx auth` names the account's plan next to the login, because "which account is
|
|
89
|
+
this and what is it paying for" is otherwise a JWT to decode by hand:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
hx auth
|
|
93
|
+
# openrouter key sk-or-…8abd ~/.hx/auth.json
|
|
94
|
+
# openai-codex signed in (plus) ~/.hx/auth.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Codex is documented as requiring a paid ChatGPT plan, and HX says so when the
|
|
98
|
+
login is on a free one. It does not refuse to try: the plan on the credential
|
|
99
|
+
has been observed deciding nothing — the backend refuses every Codex model on a
|
|
100
|
+
`plus` account with the same error it gives a `free` one — so the switch is
|
|
101
|
+
allowed and the backend's own answer is what reports the problem.
|
|
102
|
+
|
|
103
|
+
**If every Codex model is refused**, the error says so in those terms: it is
|
|
104
|
+
the account that is being refused, not the model, and a different model id will
|
|
105
|
+
not help. Check that the subscription is active and Codex is enabled for the
|
|
106
|
+
account at <https://chatgpt.com/codex>, and that the official Codex CLI can
|
|
107
|
+
reach it at all.
|
|
108
|
+
|
|
109
|
+
**Which Codex models you get** is decided by your ChatGPT account, not by HX.
|
|
110
|
+
Signing in fetches the account's own list from the Codex backend, and `/model`
|
|
111
|
+
offers exactly that; ctrl+r in `/model` asks again. Entitlement is per model -
|
|
112
|
+
the same `plus` account can run `gpt-5.6-sol` and be refused `gpt-5.3-codex` —
|
|
113
|
+
so a model the picker does not list is one the subscription does not cover.
|
|
114
|
+
|
|
115
|
+
**How hard they think** comes from the same fetch. Each Codex model publishes
|
|
116
|
+
its own reasoning levels and its own default — GPT-6 Astra starts at `low`,
|
|
117
|
+
GPT-5.6 Terra at `medium` — and HX asks for the model's default rather than one
|
|
118
|
+
fixed depth. `/effort` changes it:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
/effort # pick from the levels this model offers
|
|
122
|
+
/effort high # none | minimal | low | medium | high | xhigh | max | ultra
|
|
123
|
+
/effort default # back to the model's own default
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
It takes effect on the next turn, is saved to `~/.hx/settings.json` for later
|
|
127
|
+
sessions, and shows on the status bar next to the model — `gpt-5.6-terra (sub)
|
|
128
|
+
· high`. Levels differ per model, so a choice is clamped to what the current
|
|
129
|
+
one offers: `max` runs at `xhigh` on GPT-5.5 rather than being refused, and the
|
|
130
|
+
bar shows what is actually happening. Set it by hand instead with:
|
|
131
|
+
|
|
132
|
+
```jsonc
|
|
133
|
+
// ~/.hx/settings.json
|
|
134
|
+
{ "models": { "reasoning_effort": "high" } }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
When the model list cannot be fetched (no network, an old cache), HX falls back
|
|
138
|
+
to the models it last shipped. To add an id the backend does not advertise:
|
|
139
|
+
|
|
140
|
+
```jsonc
|
|
141
|
+
// ~/.hx/settings.json
|
|
142
|
+
{ "models": { "codex_models": ["gpt-5.6-terra"] } }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
They join the `/model` picker on the next start. HX cannot ask how large an
|
|
146
|
+
unknown model's context window is, so it assumes a conservative 200k — that
|
|
147
|
+
costs an accurate context gauge, not the use of the model.
|
|
148
|
+
|
|
149
|
+
**Devin.** Sign in with the same browser flow the official `devin` CLI uses,
|
|
150
|
+
and run every model your Devin plan includes - SWE-1.6, and whatever frontier
|
|
151
|
+
models the plan offers - against the subscription:
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
hx auth login devin # or /login inside the TUI
|
|
155
|
+
hx --model devin/swe-1-6
|
|
156
|
+
hx auth logout devin
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Devin Enterprise** signs in the same way: on the page that opens, choose
|
|
160
|
+
"Log in with Devin for Enterprise", enter your company, and finish through its
|
|
161
|
+
identity provider. Your admin has to grant the "Use Devin CLI" permission first.
|
|
162
|
+
Usage counts toward the organization's allocation, and an enterprise tenant
|
|
163
|
+
served from its own API server is followed there for both turns and the model
|
|
164
|
+
list.
|
|
165
|
+
|
|
166
|
+
The browser opens to `app.devin.ai` and redirects to a loopback listener on
|
|
167
|
+
`127.0.0.1:59653`. Over SSH, paste the final redirect URL into the prompt
|
|
168
|
+
instead. A Devin login does not refresh: when it expires, HX says so and asks
|
|
169
|
+
you to sign in again. On a machine with no browser at all, a session token in
|
|
170
|
+
`HX_DEVIN_API_KEY` or `DEVIN_API_KEY` is used when nothing is saved.
|
|
171
|
+
|
|
172
|
+
Signing in fetches the account's own model list, and `/model` offers exactly
|
|
173
|
+
that; ctrl+r in `/model` asks again. Devin publishes each reasoning depth as a
|
|
174
|
+
model of its own - Claude Opus 5 High, Claude Opus 5 Max - and HX folds each
|
|
175
|
+
family into one model, so `/effort` picks the depth on Devin exactly as it does
|
|
176
|
+
on Codex. A fast lane or a 1M-context lane stays a separate model, since it
|
|
177
|
+
changes what a turn costs or how much fits. Router models such as
|
|
178
|
+
`devin/adaptive` are resolved to a concrete model on every turn by Devin itself.
|
|
179
|
+
If the list cannot be fetched, `devin/swe-1-6` and `devin/swe-1-6-fast` stand in.
|
|
180
|
+
|
|
181
|
+
**Claude Pro/Max.** HX runs Claude models on your Claude subscription through
|
|
182
|
+
the official [Claude Code](https://claude.com/claude-code) CLI, the way the
|
|
183
|
+
Claude Agent SDK does. Install Claude Code, then:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
hx auth login claude-code # Claude Code's own sign-in; or /login inside HX
|
|
187
|
+
hx --model claude-code/claude-sonnet-5
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
HX holds no Claude token. The login is Claude Code's, kept and refreshed where
|
|
191
|
+
Claude Code keeps it, so `hx auth logout claude-code` only tells you to run
|
|
192
|
+
`claude auth logout` - which signs out every Claude Code on the machine. A
|
|
193
|
+
headless machine can use a token from `claude setup-token` in
|
|
194
|
+
`CLAUDE_CODE_OAUTH_TOKEN`. A Console login (`claude auth login --console`) bills
|
|
195
|
+
per token and is refused: this route is the subscription.
|
|
196
|
+
|
|
197
|
+
How a turn works: HX starts `claude -p` with every one of Claude Code's own
|
|
198
|
+
tools switched off and serves HX's tools to it as an MCP server. The model's
|
|
199
|
+
tool calls are run, permission-checked and drawn by HX exactly as on every
|
|
200
|
+
other route; Claude Code holds each call open until HX answers it, however long
|
|
201
|
+
an approval takes. The system prompt is Claude Code's, with your AGENTS.md
|
|
202
|
+
files, skills index and `--append-system-prompt` text added. One Claude Code
|
|
203
|
+
process serves a conversation for as long as it can, so the prompt cache
|
|
204
|
+
carries from turn to turn; after an interrupt, a steer while a tool runs, a
|
|
205
|
+
compaction, `/model`, `/effort` or a resumed session, HX starts a new one on a
|
|
206
|
+
session rebuilt from its own transcript. That costs a second or so and a
|
|
207
|
+
partly cold cache, not the conversation.
|
|
208
|
+
|
|
209
|
+
Claude Code is started isolated from your Claude Code setup: no CLAUDE.md, no
|
|
210
|
+
hooks, no plugins or MCP servers from `~/.claude`, no auto-memory, no
|
|
211
|
+
auto-compaction (HX compacts its own transcript), and nothing saved to Claude
|
|
212
|
+
Code's session list. Variables that would move it off the subscription -
|
|
213
|
+
`ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL`, `CLAUDE_CODE_USE_BEDROCK` and the
|
|
214
|
+
rest - are removed from its environment; its TLS settings are kept (see
|
|
215
|
+
*Behind a TLS-inspecting proxy* below). `HX_CLAUDE_CODE_PATH` points HX at a
|
|
216
|
+
`claude` other than the one on `PATH`.
|
|
217
|
+
|
|
218
|
+
`/model` offers the models Claude Code lists for the account, each with the
|
|
219
|
+
efforts it accepts for `/effort`; ctrl+r in `/model` asks again. A model Claude
|
|
220
|
+
Code runs at its long context keeps `[1m]` in its id
|
|
221
|
+
(`claude-code/claude-fable-5-1[1m]`), exactly as Claude Code's own `/model` runs
|
|
222
|
+
it. Claude Code lists no context sizes, so a model starts at the window it was
|
|
223
|
+
measured serving on every plan - 1M for Opus 5.5, Sonnet 5.5, Sonnet 5 and Opus
|
|
224
|
+
4.7, otherwise 200k - and from its first turn uses the window Claude Code
|
|
225
|
+
reports for your account. When a usage limit is reached, HX says which one and
|
|
226
|
+
when it resets; when a model or its 1M context needs usage credits your plan
|
|
227
|
+
has off, HX says that instead, and what to pick without them.
|
|
228
|
+
|
|
229
|
+
**Web search.** Optional, and the one credential that is not a model route.
|
|
230
|
+
It powers two tools:
|
|
231
|
+
|
|
232
|
+
| Tool | Does |
|
|
233
|
+
|---|---|
|
|
234
|
+
| `WebSearch` | search the web, returning ranked results with a snippet each |
|
|
235
|
+
| `WebFetch` | read up to 5 URLs, returned as markdown |
|
|
236
|
+
|
|
237
|
+
[Tavily](https://app.tavily.com) bills per search rather than per token, so it
|
|
238
|
+
works identically on every route - including the subscription ones,
|
|
239
|
+
where a provider-native search tool is not on offer.
|
|
240
|
+
|
|
241
|
+
Get a key at <https://app.tavily.com> — the free tier is 1000 searches a month
|
|
242
|
+
and takes no card — then save it:
|
|
243
|
+
|
|
244
|
+
```sh
|
|
245
|
+
hx auth set tavily # paste the key, hidden input, saved to ~/.hx/auth.json
|
|
246
|
+
hx auth # confirm: `tavily key tvly-a…f3d9 …/auth.json`
|
|
247
|
+
hx auth clear tavily # remove it again
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Or keep it in the environment instead, which wins only when nothing is saved:
|
|
251
|
+
|
|
252
|
+
```sh
|
|
253
|
+
export TAVILY_API_KEY=tvly-... # HX_TAVILY_API_KEY is read first
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Without a key, HX works exactly as before** — `WebSearch` and `WebFetch` are
|
|
257
|
+
simply not registered, and `hx auth` says so:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
tavily not configured WebSearch and WebFetch are off
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
There is no nag, no failing tool and no startup warning. Leaving them out is
|
|
264
|
+
deliberate: an advertised tool that always fails still costs cached-prefix
|
|
265
|
+
tokens every turn, and a model told "no key" just calls it again. Adding a key
|
|
266
|
+
turns both on from the next `hx`; no other setting changes.
|
|
267
|
+
|
|
268
|
+
Credits are reported per call and per session at the foot of every result —
|
|
269
|
+
`[Tavily: 1 credit, 4 this session]`. A search costs 1 credit, `search_depth:
|
|
270
|
+
"advanced"` costs 2, and fetching costs 1 per 5 URLs. Tavily's docs describe a
|
|
271
|
+
`usage` field for this, but the live API does not send one, so HX prices every
|
|
272
|
+
call from those published rates and marks the figure `~1` rather than passing
|
|
273
|
+
an estimate off as measured. Check `app.tavily.com` for the authoritative
|
|
274
|
+
number.
|
|
275
|
+
|
|
276
|
+
Credits are *not* in the status bar's cost, which prices tokens: `/cost`
|
|
277
|
+
under-reports a session that searched.
|
|
278
|
+
|
|
279
|
+
**Behind a TLS-inspecting proxy.** HX verifies certificates against the
|
|
280
|
+
operating system's trust store, so a corporate CA the machine already trusts
|
|
281
|
+
needs no setup. When the CA lives only in a file, name it:
|
|
282
|
+
|
|
283
|
+
```sh
|
|
284
|
+
export HX_CA_BUNDLE=/path/to/corp-ca.pem # SSL_CERT_FILE and REQUESTS_CA_BUNDLE also work
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`HX_SSL_NO_VERIFY=1` turns verification off entirely; it prints a warning at
|
|
288
|
+
startup every session, because it is not a fix. A TLS failure is reported in
|
|
289
|
+
one line - `/model` and the startup notice both name the certificate problem
|
|
290
|
+
rather than reporting an empty catalogue with no cause. A file that holds no
|
|
291
|
+
certificates is ignored, with a startup notice that says so.
|
|
292
|
+
|
|
293
|
+
"Unsupported certificate purpose" (or "unsuitable") is different: the CA is
|
|
294
|
+
trusted, but the proxy signs with a certificate that is not valid for servers,
|
|
295
|
+
so no CA setting fixes it. The network has to fix that certificate or exempt
|
|
296
|
+
the service from inspection; until then only `HX_SSL_NO_VERIFY=1` gets through.
|
|
297
|
+
|
|
298
|
+
The same settings cover the `claude-code` route, whose requests Claude Code
|
|
299
|
+
makes with its own TLS stack: HX passes `HX_CA_BUNDLE` on to it as
|
|
300
|
+
`NODE_EXTRA_CA_CERTS` (unless you already set that yourself), and
|
|
301
|
+
`HX_SSL_NO_VERIFY` as `NODE_TLS_REJECT_UNAUTHORIZED=0`. Claude Code reads the
|
|
302
|
+
OS trust store on its own, and its own TLS settings reach it untouched:
|
|
303
|
+
`CLAUDE_CODE_CERT_STORE`, and `CLAUDE_CODE_CLIENT_CERT`,
|
|
304
|
+
`CLAUDE_CODE_CLIENT_KEY` and `CLAUDE_CODE_CLIENT_KEY_PASSPHRASE` for a network
|
|
305
|
+
that requires a client certificate.
|
|
306
|
+
|
|
307
|
+
HX never sends a Claude subscription token to the API itself - Anthropic
|
|
308
|
+
accepts those only from Claude Code, and HX will not impersonate it. The
|
|
309
|
+
`claude-code` route runs the real Claude Code instead.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Running it
|
|
314
|
+
|
|
315
|
+
```sh
|
|
316
|
+
hx # interactive TUI in the current directory
|
|
317
|
+
hx -p "explain this repo" # headless: streams to stdout, tool activity to stderr
|
|
318
|
+
hx -p "why?" --image s.png # attach an image to a headless prompt; repeatable
|
|
319
|
+
hx resume # resume the last session here
|
|
320
|
+
hx resume <session-id> # resume a specific one, in the directory it was recorded in
|
|
321
|
+
hx prompt # print the system prompt this directory would use
|
|
322
|
+
hx trace # write the last session here to an HTML page
|
|
323
|
+
hx trace out.html # the same, to a path you choose
|
|
324
|
+
hx trace <id> out.html # a specific session, to a path you choose
|
|
325
|
+
hx --model openai/gpt-5 # override the model for one run
|
|
326
|
+
hx --mode plan # start read-only
|
|
327
|
+
hx --cwd ../other-project # run against a different directory
|
|
328
|
+
hx --no-sandbox # disable OS sandboxing (rules still apply)
|
|
329
|
+
hx --system-prompt @p.md # replace the system prompt for one run
|
|
330
|
+
hx --append-system-prompt "Always run the tests" # add to it; repeatable
|
|
331
|
+
hx mcp list|add|remove # manage MCP servers
|
|
332
|
+
hx mcp login <server> # sign in to a remote MCP server in the browser
|
|
333
|
+
hx mcp logout <server> # forget a remote MCP server's sign-in
|
|
334
|
+
hx auth [set|clear] # manage the OpenRouter key
|
|
335
|
+
hx auth login [provider] # sign in (openrouter, openai-codex, devin, claude-code)
|
|
336
|
+
hx auth logout <provider> # forget a stored credential
|
|
337
|
+
hx docs [section] # the manual; no argument lists its sections
|
|
338
|
+
hx changelog [version] # what shipped in each version
|
|
339
|
+
hx upgrade # update to the latest release
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Print mode is the scriptable one: stdout carries only the assistant's text, so
|
|
343
|
+
it pipes cleanly.
|
|
344
|
+
|
|
345
|
+
### The docs ship with the binary
|
|
346
|
+
|
|
347
|
+
`README.md` and [`CHANGELOG.md`](CHANGELOG.md) are included in the wheel, so
|
|
348
|
+
the installed tool can print the manual and the release record for the version
|
|
349
|
+
you are actually running:
|
|
350
|
+
|
|
351
|
+
```sh
|
|
352
|
+
hx docs # the section titles
|
|
353
|
+
hx docs credentials # one section, printed whole
|
|
354
|
+
hx docs --all # the entire manual
|
|
355
|
+
hx changelog # every release, newest first
|
|
356
|
+
hx changelog 0.1.5 # one release
|
|
357
|
+
hx changelog unreleased # what has landed since the last tag
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
The system prompt points a session at these two commands, so "how do I set the
|
|
361
|
+
API key?" or "what changed in the last release?" is answered from the shipped
|
|
362
|
+
documentation rather than from the model's recollection of some other version.
|
|
363
|
+
The call still goes through the permission engine like any other command;
|
|
364
|
+
allowlist it if you would rather not be asked:
|
|
365
|
+
|
|
366
|
+
```jsonc
|
|
367
|
+
{ "permissions": { "allow": ["Bash(hx docs:*)", "Bash(hx changelog:*)"] } }
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
`CHANGELOG.md` lists what each version added, and a release cannot skip it:
|
|
371
|
+
`tests/e2e/test_cli.py` fails when `__version__` has no section (see
|
|
372
|
+
[Releasing](#releasing)).
|
|
373
|
+
|
|
374
|
+
### Keys
|
|
375
|
+
|
|
376
|
+
Every key below is defined once, in `src/hx/keys.py`. `/help`, the hints line
|
|
377
|
+
under the prompt and this table all read from that registry, and any of them can
|
|
378
|
+
be rebound (see [Keybindings](#keybindings)).
|
|
379
|
+
|
|
380
|
+
| Key | Does |
|
|
381
|
+
|---|---|
|
|
382
|
+
| `enter` | send |
|
|
383
|
+
| `shift+enter` | newline (also `ctrl+j`; in a terminal that cannot send `shift+enter`, end the line with `\` and press `enter`) |
|
|
384
|
+
| `esc` | interrupt the current turn |
|
|
385
|
+
| `ctrl+c` | copy the selected text; with nothing selected, clear the prompt (twice on an empty prompt exits) |
|
|
386
|
+
| `ctrl+d` | exit, when the prompt is empty |
|
|
387
|
+
| `shift+tab` | cycle permission mode |
|
|
388
|
+
| `ctrl+p` | command palette |
|
|
389
|
+
| `ctrl+l` | model picker; inside it, `ctrl+r` fetches the catalogue again |
|
|
390
|
+
| `ctrl+o` | expand tool output (also `ctrl+r`) |
|
|
391
|
+
| `ctrl+t` | show the current plan |
|
|
392
|
+
| `ctrl+x` | copy the selected message to the clipboard |
|
|
393
|
+
| `ctrl+up` | previous message |
|
|
394
|
+
| `ctrl+down` | next message |
|
|
395
|
+
| `pgup` | scroll the transcript up (fullscreen; otherwise your terminal scrolls) |
|
|
396
|
+
| `pgdn` | scroll the transcript down (fullscreen; otherwise your terminal scrolls) |
|
|
397
|
+
| `ctrl+home` | jump to the start: the viewport in fullscreen, the first message otherwise |
|
|
398
|
+
| `ctrl+end` | jump back to the newest output |
|
|
399
|
+
| `ctrl+v` | attach the image on the clipboard (see [Images](#images)) |
|
|
400
|
+
| `@path` | complete a file path |
|
|
401
|
+
| `!command` | run a shell command directly, no model turn |
|
|
402
|
+
|
|
403
|
+
`!` still goes through the permission engine and the sandbox — it skips the
|
|
404
|
+
model, not the safety layers.
|
|
405
|
+
|
|
406
|
+
The prompt is a readline-style editor: `ctrl+a`/`ctrl+e` for line start and end,
|
|
407
|
+
`ctrl+b`/`ctrl+f` by character, `alt+b`/`alt+f` by word, `ctrl+w` and `alt+d` to
|
|
408
|
+
kill a word, `ctrl+u` and `ctrl+k` to kill to the start or end of a line, then
|
|
409
|
+
`ctrl+y` to yank it back and `alt+y` to walk further down the kill ring.
|
|
410
|
+
`ctrl+z` undoes and `ctrl+shift+z` redoes (`ctrl+_` undoes too). `cmd+z` and
|
|
411
|
+
`cmd+shift+z` work in a terminal that passes cmd through to the program, such
|
|
412
|
+
as kitty or WezTerm; Apple's Terminal, iTerm2 and Ghostty keep cmd+z for their
|
|
413
|
+
own Edit menu. A terminal without the kitty protocol or modifyOtherKeys sends
|
|
414
|
+
`ctrl+shift+z` as `ctrl+z`, so there it undoes. Suspending to the background
|
|
415
|
+
has no key by default - bind `app.suspend` in `keybindings.json` (for example
|
|
416
|
+
to `"ctrl+g"`) to get it back.
|
|
417
|
+
|
|
418
|
+
Typing `/` or `@` opens a completion list above the prompt; `tab` cycles it,
|
|
419
|
+
`enter` accepts, `esc` dismisses.
|
|
420
|
+
|
|
421
|
+
#### Copying
|
|
422
|
+
|
|
423
|
+
`ctrl+x` copies the message the cursor is on, and `/copy` copies the last reply.
|
|
424
|
+
HX writes through the platform's own clipboard tool first (`pbcopy`, `wl-copy`,
|
|
425
|
+
`xclip`, `xsel`) and falls back to OSC 52, which is also always sent over SSH so
|
|
426
|
+
the text lands on the machine you are actually sitting at.
|
|
427
|
+
|
|
428
|
+
Drag-select in the transcript and `ctrl+c` copies the selection — assistant
|
|
429
|
+
prose and tool output included. With nothing selected, `ctrl+c` keeps its usual
|
|
430
|
+
meaning and clears the prompt. See [Selecting and copying
|
|
431
|
+
text](#selecting-and-copying-text) for the terminal's own selection.
|
|
432
|
+
|
|
433
|
+
HX does not emit OSC 133 prompt markers yet, so shell-integration features that
|
|
434
|
+
jump between prompts will not see HX's messages.
|
|
435
|
+
|
|
436
|
+
#### Images
|
|
437
|
+
|
|
438
|
+
Give the model a picture three ways, and each lands in the prompt as a token
|
|
439
|
+
such as `[Image #1]`:
|
|
440
|
+
|
|
441
|
+
- **`ctrl+v`** attaches whatever image is on the clipboard: a screenshot copied
|
|
442
|
+
with `cmd+ctrl+shift+4`, an image copied in a browser, or an image file
|
|
443
|
+
copied in Finder or a file manager. Terminals whose own paste sends nothing
|
|
444
|
+
when the clipboard holds a picture are caught too - an empty paste is read as
|
|
445
|
+
a request for the image.
|
|
446
|
+
- **Drag an image file** into the terminal. The terminal pastes its path, and a
|
|
447
|
+
paste that is nothing but paths to image files attaches them instead of
|
|
448
|
+
inserting the text. Quoted, backslash-escaped and `file://` paths all work.
|
|
449
|
+
- **Mention it.** `look at @docs/mockup.png` sends the path as text, and the
|
|
450
|
+
model opens it with `Read`, which returns images as images.
|
|
451
|
+
|
|
452
|
+
The token is the attachment: move it and the text refers to the picture in a
|
|
453
|
+
different place, delete it (one `backspace` takes the whole token) and the
|
|
454
|
+
image is not sent. Sent messages list their images underneath, with size and
|
|
455
|
+
weight. Numbers run for the whole session, so a message recalled from history
|
|
456
|
+
or restored by a rewind still carries its pictures.
|
|
457
|
+
|
|
458
|
+
PNG, JPEG, GIF, WebP, BMP and TIFF are accepted. An image within every route's
|
|
459
|
+
limits goes byte for byte; a larger one is scaled to 2000 px on its long side
|
|
460
|
+
and re-encoded to stay under 5 MB, which is what a retina screenshot usually
|
|
461
|
+
needs. Images an MCP tool returns - a browser screenshot, say - are handled the
|
|
462
|
+
same way rather than dropped.
|
|
463
|
+
|
|
464
|
+
Whether a model can see images comes from the catalogue: OpenRouter's input
|
|
465
|
+
modalities, the Codex catalogue, and Devin's model config. The `/model` picker
|
|
466
|
+
marks the ones that can with `images`. A model that cannot
|
|
467
|
+
is warned about when you attach, and is sent a line saying an image was left
|
|
468
|
+
out, rather than a request that fails. The transcript keeps the image either
|
|
469
|
+
way, so `/model` to one that can see it and ask again.
|
|
470
|
+
|
|
471
|
+
Over SSH the clipboard you copied into is on your own machine, so `ctrl+v`
|
|
472
|
+
says so; copy the file over and drag or paste its path instead.
|
|
473
|
+
|
|
474
|
+
#### Keybindings
|
|
475
|
+
|
|
476
|
+
Any key can be rebound in `~/.hx/keybindings.json`, keyed by the action ids in
|
|
477
|
+
`src/hx/keys.py`:
|
|
478
|
+
|
|
479
|
+
```json
|
|
480
|
+
{
|
|
481
|
+
"app.tools.expand": "ctrl+r",
|
|
482
|
+
"app.message.copy": ["ctrl+x", "alt+c"]
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
Modifiers are `ctrl`, `alt` (or `option`), `shift` and `cmd` (or `super`);
|
|
487
|
+
a `cmd` key only arrives from a terminal that passes cmd through. Conflicts and
|
|
488
|
+
unknown action names are reported as a notice at startup rather than being
|
|
489
|
+
silently resolved.
|
|
490
|
+
|
|
491
|
+
### Commands
|
|
492
|
+
|
|
493
|
+
| Command | Does |
|
|
494
|
+
|---|---|
|
|
495
|
+
| `/model [query]` | pick a model; shows context window, price per Mtok, cache support. `ctrl+r` in the picker re-fetches the catalogue |
|
|
496
|
+
| `/effort [level]` | how hard a reasoning model thinks, from the levels it offers |
|
|
497
|
+
| `/configure` | session settings and the API key |
|
|
498
|
+
| `/login [provider]` | sign in to a model route |
|
|
499
|
+
| `/logout <provider>` | forget a stored credential |
|
|
500
|
+
| `/mode [name]` | `plan`, `default`, `acceptEdits`, `bypass` |
|
|
501
|
+
| `/permissions` | active rules and what is enforcing them |
|
|
502
|
+
| `/context` | what is filling the context window |
|
|
503
|
+
| `/cost` | tokens, cache savings, spend |
|
|
504
|
+
| `/compact [focus]` | summarise older turns now |
|
|
505
|
+
| `/clear` | fresh session, same directory |
|
|
506
|
+
| `/resume` | switch to another session - this directory's first, then the rest |
|
|
507
|
+
| `/rewind` | go back to an earlier prompt, restoring the files HX changed |
|
|
508
|
+
| `/title [text]` | show or set this session's name |
|
|
509
|
+
| `/prompt` | the system prompt this session is running with |
|
|
510
|
+
| `/todos` | show the current plan |
|
|
511
|
+
| `/skills` | installed skills |
|
|
512
|
+
| `/agents` | subagent types |
|
|
513
|
+
| `/mcp [login\|logout\|reconnect <server>]` | server status, and signing in to remote servers |
|
|
514
|
+
| `/hooks` | configured hooks, and any that were refused |
|
|
515
|
+
| `/theme [name]` | `dark`, `light`, `ansi`, or any theme in `~/.hx/themes` |
|
|
516
|
+
| `/queue [steer <n>\|clear]` | messages waiting for the turn to end, and what to do with them |
|
|
517
|
+
| `/copy` | copy the last reply to the clipboard |
|
|
518
|
+
| `/trace [path]` | write the whole session to a self-contained HTML page |
|
|
519
|
+
| `/fullscreen [on\|off]` | take the whole window, with the prompt pinned to the bottom |
|
|
520
|
+
| `/mouse [on\|off]` | mouse reporting, and with it your terminal's own text selection |
|
|
521
|
+
| `/init` | generate an `AGENTS.md` for the project |
|
|
522
|
+
| `/help` | list commands and keys |
|
|
523
|
+
| `/quit` | exit (also `/exit`, `/q`) |
|
|
524
|
+
|
|
525
|
+
### The two screens
|
|
526
|
+
|
|
527
|
+
By default HX draws into your terminal's own scrollback. Finished output belongs
|
|
528
|
+
to the terminal while the session runs: it scrolls it, selects it, copies it and
|
|
529
|
+
pipes it. Nothing is repainted above the fold, so a long session costs the same
|
|
530
|
+
to draw as a short one.
|
|
531
|
+
|
|
532
|
+
The prompt and the status bar still open on the bottom row of the window: a
|
|
533
|
+
conversation too short to fill the screen is padded above them rather than
|
|
534
|
+
below, so the dock stays where you last saw it instead of creeping down the
|
|
535
|
+
screen a block at a time. The padding is gone by the time the terminal starts
|
|
536
|
+
scrolling.
|
|
537
|
+
|
|
538
|
+
Leaving takes the whole interface off the screen: the banner, the conversation
|
|
539
|
+
and the dock are erased and your shell prompt comes back on the row HX started
|
|
540
|
+
on, the terminal as it was found. The erase stops at the top of the window -
|
|
541
|
+
lines that had already scrolled above it stay in your scrollback, because the
|
|
542
|
+
only sequence that reaches them takes everything the terminal remembers,
|
|
543
|
+
including what was there before HX ran. `/clear` is the command that asks for
|
|
544
|
+
that.
|
|
545
|
+
|
|
546
|
+
`/fullscreen` switches to the alternate screen instead - the whole window, the
|
|
547
|
+
prompt pinned to the bottom row, the transcript scrolling above it with `pgup`,
|
|
548
|
+
`pgdn`, `ctrl+home` and `ctrl+end`. The trade is the thing the default was
|
|
549
|
+
chosen for: the alternate screen is not scrollback, so your terminal cannot
|
|
550
|
+
scroll or select it, and it is gone when HX exits. `/fullscreen off` gives it
|
|
551
|
+
back, and either way the choice is written to `tui.fullscreen` for the next
|
|
552
|
+
session. Quitting from fullscreen leaves the same clean terminal as quitting
|
|
553
|
+
from the default screen: the alternate screen goes, and so does the frame HX
|
|
554
|
+
had drawn underneath it before the switch.
|
|
555
|
+
|
|
556
|
+
`/clear` wipes the screen and the scrollback above it. Terminals that do not
|
|
557
|
+
implement scrollback erasure - macOS Terminal.app is the one people hit - clear
|
|
558
|
+
the screen only, and the old conversation stays above it until you clear it the
|
|
559
|
+
terminal's own way (`cmd+k`).
|
|
560
|
+
|
|
561
|
+
### Selecting and copying text
|
|
562
|
+
|
|
563
|
+
Drag to select and `ctrl+c` to copy. HX copies through `pbcopy`, `wl-copy` or
|
|
564
|
+
`xclip` first and falls back to OSC 52, so it works in terminals that ignore
|
|
565
|
+
OSC 52 - macOS Terminal ignores it outright, and iTerm2 ships with it off. The
|
|
566
|
+
notice says which mechanism took the text, so a copy that did nothing says so.
|
|
567
|
+
|
|
568
|
+
While HX is running, the terminal reports mouse events to it, which means the
|
|
569
|
+
terminal's *own* click-and-drag selection is unavailable. Two ways around that:
|
|
570
|
+
|
|
571
|
+
* Hold `alt`/`option` while dragging. Most terminals - macOS Terminal, iTerm2,
|
|
572
|
+
GNOME Terminal - take that as "this drag is mine", and you get the native
|
|
573
|
+
selection without changing anything.
|
|
574
|
+
* `/mouse off` turns mouse reporting off for the session. Native selection comes
|
|
575
|
+
back everywhere, and HX stops seeing scroll and clicks until `/mouse on`.
|
|
576
|
+
|
|
577
|
+
### Steering a running turn
|
|
578
|
+
|
|
579
|
+
Type while HX is working and `enter` queues the message: it runs when the turn
|
|
580
|
+
ends, which is what you want for "and then do this".
|
|
581
|
+
|
|
582
|
+
`alt+enter` steers instead. The message goes into the turn that is running now -
|
|
583
|
+
the model call is cut off mid-stream and the next one starts from what you just
|
|
584
|
+
said. Tools already running are left to finish first, because cancelling a
|
|
585
|
+
half-written file is worse than waiting a second for it.
|
|
586
|
+
|
|
587
|
+
With nothing typed, `alt+enter` steers the message at the front of the queue, so
|
|
588
|
+
a correction you already queued does not have to be typed twice. `/queue` lists
|
|
589
|
+
what is waiting; `/queue steer 2` sends one of them now.
|
|
590
|
+
|
|
591
|
+
Set `tui.enterWhileBusy` to `"steer"` to swap the two keys around.
|
|
592
|
+
|
|
593
|
+
### The status bar
|
|
594
|
+
|
|
595
|
+
Two lines: working directory and permission mode above; token counts, cache
|
|
596
|
+
read/write with hit rate, spend, last-turn latency, context gauge and model
|
|
597
|
+
below. The cache and cost fields are the point of it — a hit rate that
|
|
598
|
+
collapses after an edit is the visible symptom of a broken prefix.
|
|
599
|
+
|
|
600
|
+
On a subscription there is no per-token price. Once the route reports its
|
|
601
|
+
usage windows, a line above the stats shows them instead:
|
|
602
|
+
|
|
603
|
+
```
|
|
604
|
+
5h 16% (renews 06:30 am) | 7d 14% (renews Mon Oct 26 04:00 am)
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
That is 16% of the five-hour window and 14% of the week spent, and when each
|
|
608
|
+
renews. A window turns yellow at 75% and red at 90%, and drops to 0% by itself
|
|
609
|
+
when it renews. ChatGPT and Claude Code report both windows on every answer.
|
|
610
|
+
A Claude Code older than the field HX reads reports a percentage only near a
|
|
611
|
+
limit, so until then its window shows only when it renews:
|
|
612
|
+
`5h (renews 06:30 am)`. Before the first answer there is
|
|
613
|
+
no usage line and the cost field says `sub`, because nothing has been
|
|
614
|
+
reported yet. `/cost` lists the same windows. Devin reports no usage.
|
|
615
|
+
|
|
616
|
+
On a narrow terminal the usage line gives up detail in steps: the clock time
|
|
617
|
+
of a renewal days away, then the renewals, then every window but the one
|
|
618
|
+
nearest its limit. The stats line drops whole fields, least important first:
|
|
619
|
+
the latency, the token counts, the cache. The context gauge stays.
|
|
620
|
+
|
|
621
|
+
---
|
|
622
|
+
|
|
623
|
+
## Configuration
|
|
624
|
+
|
|
625
|
+
Settings are JSON, merged lowest to highest:
|
|
626
|
+
|
|
627
|
+
```
|
|
628
|
+
defaults < ~/.hx/settings.json < ./.hx/settings.json < ~/.hx/projects/<project>/settings.local.json < HX_* env < CLI flags
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
Permission rule lists and `prompt.append` are unioned across layers, so a
|
|
632
|
+
project can add a deny rule — or a line to the system prompt — without
|
|
633
|
+
discarding yours. Everything else is replaced.
|
|
634
|
+
|
|
635
|
+
`./.hx/settings.json` is the project's shared file, yours to check in, and
|
|
636
|
+
nothing writes to it but you — HX only ever reads it. Versions before the local
|
|
637
|
+
layer existed did append grants there; those are lifted out into the file below
|
|
638
|
+
on the next run, once, and a rule you put back by hand afterwards stays put.
|
|
639
|
+
Only `allow` moves: a project's `deny` and `ask` are the guardrails it shares,
|
|
640
|
+
and HX never wrote them.
|
|
641
|
+
|
|
642
|
+
Anything HX decides on your behalf - an "always allow" grant, for one - goes in
|
|
643
|
+
`~/.hx/projects/<project>/settings.local.json` instead. Still per project,
|
|
644
|
+
because a grant is: allowing `pytest` in one repo should not allow it
|
|
645
|
+
everywhere. But under your home rather than in the checkout, so HX never leaves
|
|
646
|
+
a file in your repository for you to find in a diff. If an older version
|
|
647
|
+
already wrote `./.hx/settings.local.json`, it is moved there on the next run,
|
|
648
|
+
along with the `.hx/.gitignore` it added to hide it.
|
|
649
|
+
|
|
650
|
+
```jsonc
|
|
651
|
+
{
|
|
652
|
+
"theme": "dark", // dark | light | ansi, or a file in ~/.hx/themes
|
|
653
|
+
"quiet_startup": false, // skip the startup header
|
|
654
|
+
|
|
655
|
+
"models": {
|
|
656
|
+
"model": "anthropic/claude-sonnet-4.5",
|
|
657
|
+
"subagent_model": null, // defaults to "model"
|
|
658
|
+
"title_model": null, // model that names sessions; defaults to "model"
|
|
659
|
+
"max_tokens": 8192,
|
|
660
|
+
"temperature": null,
|
|
661
|
+
"reasoning_effort": null, // Codex route: null = the model's own default
|
|
662
|
+
"codex_models": [] // extra Codex ids, e.g. ["gpt-5.6-terra"]
|
|
663
|
+
},
|
|
664
|
+
|
|
665
|
+
"permissions": {
|
|
666
|
+
"mode": "default", // plan | default | acceptEdits | bypass
|
|
667
|
+
"allow": ["Bash(git status:*)"],
|
|
668
|
+
"ask": [],
|
|
669
|
+
"deny": ["Read(**/.env)"],
|
|
670
|
+
"sandbox": true,
|
|
671
|
+
"allow_network": false // outbound network for sandboxed commands
|
|
672
|
+
},
|
|
673
|
+
|
|
674
|
+
"context": {
|
|
675
|
+
"compact_at": 0.80, // fraction of the window that triggers compaction
|
|
676
|
+
"keep_recent_turns": 6, // turns kept verbatim across a compaction
|
|
677
|
+
"tool_output_char_cap": 25000,
|
|
678
|
+
"tool_output_line_cap": 2000,
|
|
679
|
+
"git_notices": true // late-inject the branch and outside file changes
|
|
680
|
+
},
|
|
681
|
+
|
|
682
|
+
"bash": {
|
|
683
|
+
"timeout_seconds": 120,
|
|
684
|
+
"max_timeout_seconds": 600, // ceiling; caps what the model may ask for
|
|
685
|
+
"shell": null // defaults to $SHELL
|
|
686
|
+
},
|
|
687
|
+
|
|
688
|
+
"prompt": {
|
|
689
|
+
"system": null, // replaces the built-in system prompt
|
|
690
|
+
"append": [] // added after it; unioned across layers
|
|
691
|
+
},
|
|
692
|
+
|
|
693
|
+
"tui": {
|
|
694
|
+
"enterWhileBusy": "queue", // queue | steer - what enter does mid-turn
|
|
695
|
+
"fullscreen": false // true takes the whole window (see /fullscreen)
|
|
696
|
+
},
|
|
697
|
+
|
|
698
|
+
"tools": {
|
|
699
|
+
"hashline": true // Read labels lines with content anchors Edit accepts
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
`hooks` is configured in the same files but is deliberately not part of this
|
|
705
|
+
merge: it is read per layer, and only from your own settings. See
|
|
706
|
+
[Extending it](#extending-it).
|
|
707
|
+
|
|
708
|
+
Environment overrides: `HX_MODEL`, `HX_SUBAGENT_MODEL`, `HX_MAX_TOKENS`,
|
|
709
|
+
`HX_PERMISSION_MODE`, `HX_SANDBOX`, `HX_COMPACT_AT`, `HX_GIT_NOTICES`,
|
|
710
|
+
`HX_THEME`, `HX_QUIET_STARTUP`. Also `HX_HOME` to relocate user state, `HX_TAVILY_API_KEY`
|
|
711
|
+
for web search, `HX_CA_BUNDLE` / `HX_SSL_NO_VERIFY` for TLS (see
|
|
712
|
+
[Credentials](#credentials)), and `HX_OPENROUTER_BASE_URL` to point the OpenRouter
|
|
713
|
+
route at another OpenAI-compatible endpoint - a gateway, or a recording proxy.
|
|
714
|
+
`HX_CODEX_BASE_URL` does the same for the ChatGPT route's backend.
|
|
715
|
+
`HX_MODIFIER_PROBE=0` stops HX asking macOS whether shift is held when an
|
|
716
|
+
`enter` arrives (see [Keys](#keys)).
|
|
717
|
+
|
|
718
|
+
### The system prompt
|
|
719
|
+
|
|
720
|
+
`hx prompt` prints the prompt this directory resolves to, with its source on
|
|
721
|
+
stderr so stdout stays pipeable. `/prompt` shows the same thing inside a running
|
|
722
|
+
session.
|
|
723
|
+
|
|
724
|
+
The built-in prompt is `SYSTEM_PROMPT` in `src/hx/core/context.py`. It is
|
|
725
|
+
replaced by the first of these that exists:
|
|
726
|
+
|
|
727
|
+
| Source | Scope |
|
|
728
|
+
|---|---|
|
|
729
|
+
| `--system-prompt TEXT` or `@path`, or `prompt.system` | one run |
|
|
730
|
+
| `./.hx/system-prompt.md` | this project |
|
|
731
|
+
| `~/.hx/system-prompt.md` | you, everywhere |
|
|
732
|
+
| the built-in prompt | fallback |
|
|
733
|
+
|
|
734
|
+
Appended text is added after whichever prompt won, in this order:
|
|
735
|
+
`~/.hx/system-prompt-append.md`, `./.hx/system-prompt-append.md`, then each
|
|
736
|
+
`--append-system-prompt` value (and `prompt.append`) in the order given. Nothing
|
|
737
|
+
appended is ever discarded by a later layer.
|
|
738
|
+
|
|
739
|
+
This is a different lever from `AGENTS.md`: `AGENTS.md` describes *the project* and is
|
|
740
|
+
injected as its own context section, while these files change *the agent's
|
|
741
|
+
instructions*. Both are read once at startup and frozen, because they sit above
|
|
742
|
+
the first cache breakpoint — an override edited mid-session applies on the next
|
|
743
|
+
run, and `/prompt` says so when it spots one.
|
|
744
|
+
|
|
745
|
+
### Sessions are named
|
|
746
|
+
|
|
747
|
+
After the first exchange, HX asks the model for a short name for the session and
|
|
748
|
+
writes it to `~/.hx/sessions/<id>/meta.json`, so `/resume` lists work rather
|
|
749
|
+
than timestamps. It is one small call — cap 32 output tokens, `models.title_model`
|
|
750
|
+
if you want a cheaper model for it — and it is counted in `/cost` like any other.
|
|
751
|
+
If the call fails, or you leave before it is back, the session is still named,
|
|
752
|
+
from your first message.
|
|
753
|
+
|
|
754
|
+
The live session is never renamed while it runs, and nothing is renamed on
|
|
755
|
+
`/exit`, which returns your shell at once. A session you leave with `/clear` or
|
|
756
|
+
`/resume` - including a `/resume` into another directory - is renamed in the
|
|
757
|
+
background for what it became. `/title <text>` renames it yourself, and a name
|
|
758
|
+
you chose is never replaced.
|
|
759
|
+
|
|
760
|
+
`/resume` lists every session except the one you are in: this directory's
|
|
761
|
+
first, then other directories', each row naming where it lives. A session from
|
|
762
|
+
this directory is swapped in place. One from elsewhere belongs to that
|
|
763
|
+
directory - its sandbox, permission rules, prompt and tools - so HX restarts
|
|
764
|
+
itself there with `hx resume <id>`, keeping options like `--mode` and
|
|
765
|
+
`--model`.
|
|
766
|
+
|
|
767
|
+
### Themes
|
|
768
|
+
|
|
769
|
+
A theme is a JSON file: a `vars` block of raw colours, and a `colors` block
|
|
770
|
+
mapping semantic roles onto them. Drop one in `~/.hx/themes/mine.json` and
|
|
771
|
+
`/theme mine` picks it up — no restart, no code change.
|
|
772
|
+
|
|
773
|
+
```jsonc
|
|
774
|
+
{
|
|
775
|
+
"name": "mine",
|
|
776
|
+
"dark": true,
|
|
777
|
+
"vars": { "green": "#b5bd68", "gray": "#808080" },
|
|
778
|
+
"colors": {
|
|
779
|
+
"background": "#18181e",
|
|
780
|
+
"success": "green", // a vars key, or a literal
|
|
781
|
+
"muted": "gray"
|
|
782
|
+
// ...every role; a missing one is an error, not a silent black
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
The role names are pi's, so [pi](https://github.com/earendil-works/pi) theme
|
|
788
|
+
files load here unchanged. `src/hx/tui/themes/dark.json` is the reference.
|
|
789
|
+
A few roles pi has no concept of may be left out, and borrow another role:
|
|
790
|
+
`toolArgs`, the colour of a tool call's paths and patterns, borrows `accent`;
|
|
791
|
+
`panel` and `mdCodeBlockBg` borrow `surface`; `userText` borrows `text`; and
|
|
792
|
+
`diffHunk` borrows `mdLink`. `background` and `surface` may come from pi's
|
|
793
|
+
`export` instead. pi's `toolPendingBg` is accepted and ignored.
|
|
794
|
+
|
|
795
|
+
### Where things live
|
|
796
|
+
|
|
797
|
+
| Path | What |
|
|
798
|
+
|---|---|
|
|
799
|
+
| `~/.hx/settings.json` | your settings |
|
|
800
|
+
| `~/.hx/auth.json` | API keys and logins, mode 0600 |
|
|
801
|
+
| `~/.hx/models.json` | cached model catalogue, refreshed daily |
|
|
802
|
+
| `~/.hx/themes/` | your themes, one JSON file each |
|
|
803
|
+
| `~/.hx/keybindings.json` | your key overrides |
|
|
804
|
+
| `~/.hx/system-prompt.md` | your system prompt, replacing the built-in one |
|
|
805
|
+
| `~/.hx/system-prompt-append.md` | text appended to whichever prompt is in force |
|
|
806
|
+
| `~/.hx/AGENTS.md` | your instructions, loaded into every session in every project; created empty |
|
|
807
|
+
| `~/.hx/sessions/` | transcripts, spilled tool output, subagent sessions |
|
|
808
|
+
| `~/.hx/sessions/<id>/trace.html` | where `/trace` writes, unless you name a path |
|
|
809
|
+
| `~/.hx/skills/`, `~/.hx/agents/` | your skills and agents |
|
|
810
|
+
| `~/.hx/projects/<project>/settings.local.json` | this machine's settings for one project - where "always allow" lands |
|
|
811
|
+
| `./.hx/settings.json` | project settings, checked in if you like — read by HX, never written |
|
|
812
|
+
| `./.hx/mcp.json` | project MCP servers |
|
|
813
|
+
| `./.hx/system-prompt.md`, `./.hx/system-prompt-append.md` | project prompt overrides |
|
|
814
|
+
| `./.hx/skills/`, `./.hx/agents/` | project skills and agents |
|
|
815
|
+
| `AGENTS.md` | project instructions: the repository root's, then each one down to where HX started |
|
|
816
|
+
|
|
817
|
+
`AGENTS.md` is the place for things a newcomer would get wrong: how to run the
|
|
818
|
+
tests, conventions, what not to touch. `/init` writes a first draft. It is
|
|
819
|
+
loaded once per session and frozen, so it costs one prefix, not one per turn.
|
|
820
|
+
|
|
821
|
+
`~/.hx/AGENTS.md` is the same thing for you rather than the project: how you
|
|
822
|
+
like commits written, tools you always want used, in every repository. It is
|
|
823
|
+
loaded first and the project's `AGENTS.md` after it, so where the two disagree
|
|
824
|
+
the project has the last word. The first session creates it empty, ready to
|
|
825
|
+
fill in; empty, it adds nothing. `hx prompt` and `/prompt` list each one in force.
|
|
826
|
+
|
|
827
|
+
Started below the repository root - in `services/billing`, say - HX still loads
|
|
828
|
+
the root's `AGENTS.md`, then every `AGENTS.md` on the way down to that directory,
|
|
829
|
+
the nearest last, so a package can refine the repository's rules. A submodule
|
|
830
|
+
counts as part of the repository around it. Nothing above the repository root is
|
|
831
|
+
read; outside a repository only the current directory is.
|
|
832
|
+
Subagents run under the same files as the session that started them.
|
|
833
|
+
|
|
834
|
+
---
|
|
835
|
+
|
|
836
|
+
## Safety
|
|
837
|
+
|
|
838
|
+
Two independent layers guard every tool call, and both must pass.
|
|
839
|
+
|
|
840
|
+
**Permission rules** are `Tool(specifier)` strings — `Bash(git commit:*)`,
|
|
841
|
+
`Edit(src/**)`, `Read(**/.ssh/**)`. Deny beats ask beats allow, and a deny
|
|
842
|
+
holds even in bypass mode. Shell commands are decomposed into their real
|
|
843
|
+
segments first, so an allow rule for `git status` does not carry
|
|
844
|
+
`&& rm -rf /` along with it; a command that cannot be decomposed with
|
|
845
|
+
confidence prompts rather than passing.
|
|
846
|
+
|
|
847
|
+
**An OS sandbox** wraps command execution: Seatbelt on macOS, bubblewrap on
|
|
848
|
+
Linux. The filesystem is readable, writes are confined to the project and the
|
|
849
|
+
temp dir, credential paths (`~/.ssh`, `~/.aws`, and HX's own `auth.json`) are
|
|
850
|
+
unreadable and unwritable - even inside the project, and even before they
|
|
851
|
+
exist - and outbound network is off. If neither backend is present the
|
|
852
|
+
status bar says `no-sandbox` rather than implying protection that is not there.
|
|
853
|
+
The API keys HX signs in with (`HX_OPENROUTER_API_KEY`, `OPENROUTER_API_KEY`,
|
|
854
|
+
and the Tavily and Devin keys) are removed from the environment of every
|
|
855
|
+
command it runs.
|
|
856
|
+
|
|
857
|
+
Modes cycle with shift+tab: `plan` (read-only — mutating tools are not even
|
|
858
|
+
offered to the model), `default`, `acceptEdits`, `bypass`.
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
## Context engineering
|
|
863
|
+
|
|
864
|
+
Long sessions are the normal case, so the harness is built around keeping the
|
|
865
|
+
provider's KV cache warm and the window from filling up.
|
|
866
|
+
|
|
867
|
+
**A stable prefix.** System prompt, tool schemas and project context are
|
|
868
|
+
assembled in a fixed order and never mutated mid-session. Cache breakpoints sit
|
|
869
|
+
at the end of that static block and at a rolling point before the recent turns,
|
|
870
|
+
which only advances once enough tokens have accumulated behind it.
|
|
871
|
+
|
|
872
|
+
**Late injection** carries everything that changes per turn - the todo list,
|
|
873
|
+
files that changed on disk since HX read them, the git branch and any file the
|
|
874
|
+
working tree gained or lost outside the session - on the tail of the newest
|
|
875
|
+
user message rather than in the prefix. Stale copies are stripped and
|
|
876
|
+
regenerated each turn, so six todo updates leave one copy in context, not six.
|
|
877
|
+
|
|
878
|
+
**Working-tree notices** come from one `git status --porcelain=v2 --branch -z`
|
|
879
|
+
per provider call, run without a shell and bounded by a two-second timeout. It
|
|
880
|
+
runs in a worker thread, as every injector does: a turn makes one of these per
|
|
881
|
+
tool round-trip, and on the event loop a slow repository would freeze the UI
|
|
882
|
+
each time. A file HX has already read is left to the stale-file notice, so no
|
|
883
|
+
path is reported twice; outside a repository the watcher disables itself for
|
|
884
|
+
the session. Turn it off with `"context": {"git_notices": false}`.
|
|
885
|
+
|
|
886
|
+
**Rewind** (`/rewind`) picks an earlier prompt and takes the session back to
|
|
887
|
+
it: the transcript is cut there and every file HX wrote after it is restored
|
|
888
|
+
from a content-addressed snapshot taken before each Write and Edit. A file
|
|
889
|
+
someone else changed in the meantime is reported and left alone, and shell
|
|
890
|
+
commands are outside the scheme - the report says so rather than implying the
|
|
891
|
+
tree was fully returned. The prompt that was cut comes back in the input box,
|
|
892
|
+
because a rewind is usually the first half of saying it differently. Nothing is
|
|
893
|
+
deleted from the session file: the rewind is one more append, and replaying the
|
|
894
|
+
file reproduces the state - which is also how an undone compaction gives its
|
|
895
|
+
messages back. The cost ledger is deliberately not rewound; those tokens were
|
|
896
|
+
spent.
|
|
897
|
+
|
|
898
|
+
**Compaction** fires at 80% of the window, or on `/compact [focus]`. Older
|
|
899
|
+
turns are replaced by a structured summary; the recent turns and the todo list
|
|
900
|
+
survive verbatim, and the boundary snaps to a turn edge so a tool call is never
|
|
901
|
+
severed from its results. Superseded messages are flagged, not deleted, so
|
|
902
|
+
resume replays exactly what happened.
|
|
903
|
+
|
|
904
|
+
**Output capping** keeps the head and tail of a large tool result, spills the
|
|
905
|
+
rest to the session directory, and hands the model that path to grep.
|
|
906
|
+
|
|
907
|
+
---
|
|
908
|
+
|
|
909
|
+
## Tracing a session
|
|
910
|
+
|
|
911
|
+
`/trace` writes everything that happened to one self-contained HTML file and
|
|
912
|
+
opens it in a browser:
|
|
913
|
+
|
|
914
|
+
```
|
|
915
|
+
/trace # ~/.hx/sessions/<id>/trace.html
|
|
916
|
+
/trace ~/Desktop/bug.html # somewhere you choose
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
Everything means everything. The system prompt, the project context, the skills
|
|
920
|
+
index, every tool schema as the provider received it, every prompt, every
|
|
921
|
+
reply, every thinking block, every tool call next to the result it produced,
|
|
922
|
+
the per-call token ledger, and the files HX changed. Late-injected reminders
|
|
923
|
+
and compacted turns are in there too, behind a toggle that says how many there
|
|
924
|
+
are — a trace that hides the reminders and the superseded turns is not a trace
|
|
925
|
+
of the session that ran.
|
|
926
|
+
|
|
927
|
+
Nothing is summarised and nothing is prettified. Assistant text is shown as it
|
|
928
|
+
arrived, backticks and all, because a trace exists to answer "what actually
|
|
929
|
+
went through" and a rendered version of that is a different document. Long tool
|
|
930
|
+
results are folded rather than truncated, with the character count on the fold.
|
|
931
|
+
|
|
932
|
+
**Thinking, where the provider allows it.** How much of a model's reasoning HX
|
|
933
|
+
ever sees is the provider's decision, not HX's. Anthropic's models return the
|
|
934
|
+
thinking itself. The Responses API - the OpenAI and Codex routes - returns a
|
|
935
|
+
one-line summary in plaintext and the reasoning encrypted, to be replayed on
|
|
936
|
+
the next call and read by nobody, HX included. A trace labels which of the two
|
|
937
|
+
it is holding, because a one-line thinking block is otherwise indistinguishable
|
|
938
|
+
from a trace that dropped the rest.
|
|
939
|
+
|
|
940
|
+
A running session traces as it stands right now, including the turn that just
|
|
941
|
+
landed. The page says so, because a trace of a live session is a snapshot.
|
|
942
|
+
|
|
943
|
+
**Reading it.** Long tool results are folded and the reference panels - the
|
|
944
|
+
prompt, the schemas, the ledger - start shut, so the transcript is what you
|
|
945
|
+
land on. "Expand all" opens the whole page, panels included, and turns into
|
|
946
|
+
"Collapse all". A session with no turns yet opens its panels on its own, since
|
|
947
|
+
there is nothing else to read.
|
|
948
|
+
|
|
949
|
+
**Dark or light.** The page follows your system by default and a button in the
|
|
950
|
+
corner overrides it, remembered per browser. No stylesheet is fetched to do it.
|
|
951
|
+
|
|
952
|
+
**Nothing is uploaded and nothing is fetched.** The payload, the stylesheet and
|
|
953
|
+
the script all live in the file, so it opens offline, renders the same a year
|
|
954
|
+
later, and a trace of a private repository stays as private as the directory
|
|
955
|
+
you wrote it into. The embedded payload is also the machine-readable trace: it
|
|
956
|
+
is JSON, in a `<script id="trace-data">` element, and `/trace` is the only way
|
|
957
|
+
HX will ever put your transcript anywhere but `~/.hx`.
|
|
958
|
+
|
|
959
|
+
From outside a session, on any transcript on the machine:
|
|
960
|
+
|
|
961
|
+
```sh
|
|
962
|
+
hx trace # the last session in this directory
|
|
963
|
+
hx trace 20260918-214743-b5b8f9 # one by id
|
|
964
|
+
hx trace ~/somewhere.html # the last session, to a path you choose
|
|
965
|
+
hx trace <id> ~/somewhere.html # both, to a path or a directory
|
|
966
|
+
open "$(hx trace)" # the path is all that goes to stdout
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
`hx trace` reads the transcript and runs nothing, so it works on a session that
|
|
970
|
+
ended months ago and on one another terminal has open right now.
|
|
971
|
+
|
|
972
|
+
**What a trace can be missing.** The prompt and the tool schemas are written to
|
|
973
|
+
the transcript on the session's first provider call — the first moment the tool
|
|
974
|
+
registry has settled, because MCP servers connect after the loop is built. A
|
|
975
|
+
session traced before that call, or one recorded by a version of HX older than
|
|
976
|
+
this feature, has the transcript but not the prompt, and the page leaves those
|
|
977
|
+
panels out rather than guessing. `/trace` inside a live session fills them in
|
|
978
|
+
from the loop either way.
|
|
979
|
+
|
|
980
|
+
---
|
|
981
|
+
|
|
982
|
+
## Reading and editing code
|
|
983
|
+
|
|
984
|
+
**Line anchors.** `Read` labels every line with a short content hash:
|
|
985
|
+
|
|
986
|
+
```
|
|
987
|
+
1 a3f9 def handle(request):
|
|
988
|
+
2 7c1c if request.method == "POST":
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
The anchor is a hash of the line and its two neighbours, truncated to the
|
|
992
|
+
narrowest width that is unambiguous in that file. `Edit` takes those anchors
|
|
993
|
+
instead of retyped content:
|
|
994
|
+
|
|
995
|
+
```json
|
|
996
|
+
{ "file_path": "app.py", "hashline": [{ "start": "a3f9", "end": "7c1c", "new_string": "..." }] }
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
The span is inclusive; omit `end` to replace one line, pass an empty
|
|
1000
|
+
`new_string` to delete. Anchors are recomputed from disk when the edit runs, so
|
|
1001
|
+
a file that moved under the model fails to resolve and the patch is rejected
|
|
1002
|
+
rather than applied at stale coordinates. Exact-match `old_string` still works
|
|
1003
|
+
and is unchanged; anchors are a second shape, not a replacement. Turn the whole
|
|
1004
|
+
thing off with `"tools": {"hashline": false}` and reads go back to plain
|
|
1005
|
+
`cat -n`.
|
|
1006
|
+
|
|
1007
|
+
**Images.** `Read` on a PNG, JPEG, GIF, WebP, BMP or TIFF - or on a file with
|
|
1008
|
+
no extension whose bytes are one - returns the image itself for the model to
|
|
1009
|
+
look at, normalised the way a pasted one is (see [Images](#images)).
|
|
1010
|
+
|
|
1011
|
+
**Symbols** answers structural questions with a parse tree rather than a
|
|
1012
|
+
regex — three modes, `outline` for one file's shape, `definition` for where a
|
|
1013
|
+
name is defined, `references` for where it is used:
|
|
1014
|
+
|
|
1015
|
+
```
|
|
1016
|
+
Symbols(mode="references", symbol="handle")
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
Because it matches identifier nodes, the same word in a comment or a string
|
|
1020
|
+
literal never matches. It cannot resolve types, so an unrelated symbol with the
|
|
1021
|
+
same name in another file still does; it is tighter than `Grep`, not a language
|
|
1022
|
+
server. Python, TypeScript, JavaScript, Go and Rust.
|
|
1023
|
+
|
|
1024
|
+
It needs grammars that are not installed by default, and the tool is simply not
|
|
1025
|
+
registered without them — its schema never enters the cached prefix advertising
|
|
1026
|
+
something that cannot run:
|
|
1027
|
+
|
|
1028
|
+
```sh
|
|
1029
|
+
npm install --global @vscode/tree-sitter-wasm
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
---
|
|
1033
|
+
|
|
1034
|
+
## Extending it
|
|
1035
|
+
|
|
1036
|
+
**Skills** are directories containing `SKILL.md` with YAML frontmatter:
|
|
1037
|
+
|
|
1038
|
+
```markdown
|
|
1039
|
+
---
|
|
1040
|
+
name: deploy
|
|
1041
|
+
description: Tag, build and ship a release
|
|
1042
|
+
allowed-tools: Read, Bash # optional; narrows the toolset while active
|
|
1043
|
+
---
|
|
1044
|
+
|
|
1045
|
+
1. Run the tests.
|
|
1046
|
+
2. Tag the commit.
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
Drop them in `.hx/skills/<name>/` or `~/.hx/skills/<name>/`; a project skill
|
|
1050
|
+
shadows a user one of the same name. Only the name and description enter the
|
|
1051
|
+
context — the body loads when the model calls `Skill(name)`, so a hundred
|
|
1052
|
+
installed skills cost a hundred lines, not a hundred documents.
|
|
1053
|
+
|
|
1054
|
+
**Subagents** run in their own context with their own transcript, tool
|
|
1055
|
+
allowlist and model. Only the final report returns to the parent, so a long
|
|
1056
|
+
search costs the caller one paragraph instead of every intermediate tool
|
|
1057
|
+
result. `explore`, `plan` and `general` ship built in; add your own as
|
|
1058
|
+
`.hx/agents/<name>.md`:
|
|
1059
|
+
|
|
1060
|
+
```markdown
|
|
1061
|
+
---
|
|
1062
|
+
name: reviewer
|
|
1063
|
+
description: Reviews a diff against the project's conventions
|
|
1064
|
+
tools: Read, Grep
|
|
1065
|
+
model: openai/gpt-5 # optional
|
|
1066
|
+
---
|
|
1067
|
+
|
|
1068
|
+
You review code. Be specific and cite file:line.
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
A subagent never gets the `Task` tool, so recursion is impossible by
|
|
1072
|
+
construction.
|
|
1073
|
+
|
|
1074
|
+
**MCP servers** go in `.hx/mcp.json`:
|
|
1075
|
+
|
|
1076
|
+
```json
|
|
1077
|
+
{
|
|
1078
|
+
"mcpServers": {
|
|
1079
|
+
"local": { "command": "python", "args": ["server.py"] },
|
|
1080
|
+
"remote": { "url": "https://example.com/mcp" }
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
Or `hx mcp add local python server.py`, or
|
|
1086
|
+
`hx mcp add remote --url https://example.com/mcp`. Tools arrive namespaced
|
|
1087
|
+
`mcp__<server>__<tool>` in a deterministic order. Servers connect concurrently
|
|
1088
|
+
with a per-server timeout; one that is broken or slow logs a warning and is
|
|
1089
|
+
dropped rather than taking the session with it. A server that changes its tool
|
|
1090
|
+
list mid-session (`notifications/tools/list_changed`) has the new list swapped
|
|
1091
|
+
in without a restart.
|
|
1092
|
+
|
|
1093
|
+
A remote server that asks for sign-in - Atlassian's, for one - is signed in to
|
|
1094
|
+
over OAuth, with nothing to configure:
|
|
1095
|
+
|
|
1096
|
+
```json
|
|
1097
|
+
{ "mcpServers": { "atlassian": { "url": "https://mcp.atlassian.com/v2/mcp" } } }
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
It shows as needing sign-in until you run `/mcp login atlassian` in a session
|
|
1101
|
+
or `hx mcp login atlassian` in a shell. That opens the browser, and the tools
|
|
1102
|
+
arrive as soon as you approve - no restart. HX follows the MCP authorization
|
|
1103
|
+
spec: it finds the authorization server from the server's metadata, registers
|
|
1104
|
+
itself as a client, signs in with PKCE, and keeps the token in `~/.hx/auth.json`
|
|
1105
|
+
(mode 0600), refreshing it before it expires and again if the server rejects
|
|
1106
|
+
it. Over SSH, paste the final redirect URL into the prompt instead.
|
|
1107
|
+
`/mcp logout atlassian` forgets it.
|
|
1108
|
+
|
|
1109
|
+
A server that does not offer client registration needs a client you register
|
|
1110
|
+
with it yourself, and anything else about the sign-in can be pinned the same
|
|
1111
|
+
way:
|
|
1112
|
+
|
|
1113
|
+
```json
|
|
1114
|
+
"oauth": { "clientId": "...", "clientSecret": "...", "scope": "read write", "callbackPort": 33418 }
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
To send a token of your own instead - an API key - give the server an
|
|
1118
|
+
`Authorization` header, and OAuth stays out of the way:
|
|
1119
|
+
`hx mcp add jira --url https://mcp.atlassian.com/v2/mcp --header "Authorization: Basic <base64 email:token>"`.
|
|
1120
|
+
|
|
1121
|
+
**Hooks** are shell commands HX runs at named points in a turn. Four events:
|
|
1122
|
+
`PreToolUse`, `PostToolUse`, `UserPromptSubmit` and `Stop`.
|
|
1123
|
+
|
|
1124
|
+
```json
|
|
1125
|
+
{
|
|
1126
|
+
"hooks": {
|
|
1127
|
+
"PreToolUse": [
|
|
1128
|
+
{
|
|
1129
|
+
"matcher": "Bash",
|
|
1130
|
+
"hooks": [{ "type": "command", "command": "~/.hx/guard-bash.sh", "timeout": 10 }]
|
|
1131
|
+
}
|
|
1132
|
+
],
|
|
1133
|
+
"PostToolUse": [
|
|
1134
|
+
{ "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "ruff check --quiet" }] }
|
|
1135
|
+
]
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
`matcher` is a regex matched against the whole tool name; omit it, or use `*`,
|
|
1141
|
+
to match every tool. The hook reads a JSON event on stdin — `session_id`,
|
|
1142
|
+
`cwd`, `hook_event_name`, and `tool_name`/`tool_input` where they apply — and
|
|
1143
|
+
answers with its exit code:
|
|
1144
|
+
|
|
1145
|
+
| Exit | Means |
|
|
1146
|
+
|---|---|
|
|
1147
|
+
| `0` | allow |
|
|
1148
|
+
| `2` | block. stderr becomes the reason the model is given |
|
|
1149
|
+
| anything else | the hook is broken. Reported as a notice; the action proceeds |
|
|
1150
|
+
|
|
1151
|
+
That last row is deliberate: a typo in a shell command must not be able to
|
|
1152
|
+
wedge a session. Only an explicit refusal stops anything.
|
|
1153
|
+
|
|
1154
|
+
A hook may also print JSON on stdout: `{"decision": "block", "reason": "..."}`
|
|
1155
|
+
refuses, `{"updatedInput": {...}}` rewrites a tool's arguments before the
|
|
1156
|
+
permission engine sees them, and `{"additionalContext": "..."}` adds a note for
|
|
1157
|
+
the model to read. The format matches Claude Code's, so hooks already written
|
|
1158
|
+
against that work here unchanged.
|
|
1159
|
+
|
|
1160
|
+
A worked example ships in the repository:
|
|
1161
|
+
[`examples/hooks/check.sh`](https://github.com/aletisunil/hx/blob/main/examples/hooks/check.sh)
|
|
1162
|
+
runs the checker a project already has — `ruff`, `tsc`, `go vet`, `cargo
|
|
1163
|
+
check` — against the one file the model just edited, and returns whatever it
|
|
1164
|
+
says as `additionalContext`. The model sees the errors appended to its own edit
|
|
1165
|
+
result and fixes them on the next turn, rather than discovering them at test
|
|
1166
|
+
time. It exits 0 either way: by `PostToolUse` the write has already landed, so
|
|
1167
|
+
refusing it would be an answer to something that already happened.
|
|
1168
|
+
|
|
1169
|
+
```sh
|
|
1170
|
+
curl -o ~/.hx/check.sh https://raw.githubusercontent.com/aletisunil/hx/main/examples/hooks/check.sh
|
|
1171
|
+
chmod +x ~/.hx/check.sh
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
**Where hooks may be declared is a security boundary.** They are loaded from
|
|
1175
|
+
`~/.hx/settings.json` and `~/.hx/projects/<slug>/settings.local.json` only.
|
|
1176
|
+
Hooks in a project's checked-in `.hx/settings.json` are ignored and listed by
|
|
1177
|
+
`/hooks`, because that file arrives with a clone and cloning a repository must
|
|
1178
|
+
never be enough to run commands on the machine that cloned it. To adopt a
|
|
1179
|
+
shared hook, copy it into your own settings — a deliberate act by the person
|
|
1180
|
+
who will run it. Subagents inherit the parent's hooks, so a guard cannot be
|
|
1181
|
+
bypassed by delegating through `Task`.
|
|
1182
|
+
|
|
1183
|
+
---
|
|
1184
|
+
|
|
1185
|
+
## Development
|
|
1186
|
+
|
|
1187
|
+
```sh
|
|
1188
|
+
git clone https://github.com/aletisunil/hx && cd hx
|
|
1189
|
+
uv sync --extra dev
|
|
1190
|
+
|
|
1191
|
+
uv run pytest # the suite; live tests are deselected
|
|
1192
|
+
uv run ruff check . && uv run ruff format --check .
|
|
1193
|
+
uv run mypy # strict
|
|
1194
|
+
uv run hx # run from the checkout
|
|
1195
|
+
```
|
|
1196
|
+
|
|
1197
|
+
The suite is end-to-end. Each test in `tests/e2e/` starts the installed `hx`
|
|
1198
|
+
binary - on a real pseudo-terminal for the TUI, or as a plain subprocess for
|
|
1199
|
+
print mode and the other commands - in a private `$HOME` and `$HX_HOME`, and
|
|
1200
|
+
points it at a local OpenRouter stand-in with `HX_OPENROUTER_BASE_URL`, and
|
|
1201
|
+
at a ChatGPT stand-in with `HX_CODEX_BASE_URL`.
|
|
1202
|
+
Everything between the keyboard and the socket is the shipped code; only the
|
|
1203
|
+
model's replies are scripted. The screen is read back through a VT emulator,
|
|
1204
|
+
so assertions are on the cells a terminal shows, not on the bytes HX meant to
|
|
1205
|
+
write.
|
|
1206
|
+
|
|
1207
|
+
Every run writes `e2e-report/`: `index.html` shows each test's outcome and
|
|
1208
|
+
every screen it checked, rendered in colour, and one text file per screen lets
|
|
1209
|
+
two runs be compared with `diff -r`. CI uploads it from every test job as an
|
|
1210
|
+
`e2e-report-*` artifact. Set `HX_E2E_REPORT` to write it somewhere else.
|
|
1211
|
+
|
|
1212
|
+
Tests that need the OS sandbox are skipped where there is no backend
|
|
1213
|
+
(`sandbox-exec` on macOS, `bwrap` on Linux).
|
|
1214
|
+
|
|
1215
|
+
Tests marked `live` hit a real API. The OpenRouter ones cost money:
|
|
1216
|
+
|
|
1217
|
+
```sh
|
|
1218
|
+
OPENROUTER_API_KEY=... uv run pytest -m live tests/test_live.py
|
|
1219
|
+
|
|
1220
|
+
# the Codex route draws on your ChatGPT subscription instead
|
|
1221
|
+
hx auth login openai-codex
|
|
1222
|
+
uv run pytest -m live tests/test_live_codex.py
|
|
1223
|
+
|
|
1224
|
+
# and the Devin route on your Devin subscription
|
|
1225
|
+
hx auth login devin
|
|
1226
|
+
uv run pytest -m live tests/test_live_devin.py
|
|
1227
|
+
```
|
|
1228
|
+
|
|
1229
|
+
They are the only place the wire formats, streaming, tool use and a genuine
|
|
1230
|
+
cache hit are proven against a real service; everything else runs against the
|
|
1231
|
+
stand-in.
|
|
1232
|
+
|
|
1233
|
+
### Layout
|
|
1234
|
+
|
|
1235
|
+
```
|
|
1236
|
+
src/hx/
|
|
1237
|
+
cli.py config.py paths.py frontmatter.py git.py
|
|
1238
|
+
core/ loop, context assembly, compaction, late injection, sessions, usage
|
|
1239
|
+
auth/ credential store, OAuth flows, per-route resolution
|
|
1240
|
+
providers/ OpenRouter, Codex, Devin, the model catalogue
|
|
1241
|
+
tools/ Bash, Read, Write, Edit, Glob, Grep, Symbols, TodoWrite, Task,
|
|
1242
|
+
WebSearch, WebFetch, line anchors, output capping
|
|
1243
|
+
permissions/ rule engine, shell decomposition, Seatbelt/bubblewrap
|
|
1244
|
+
hooks/ the four events, the trust boundary, subprocess execution
|
|
1245
|
+
skills/ agents/ mcp/
|
|
1246
|
+
keys.py keybinding registry: ids, defaults, descriptions, user overrides
|
|
1247
|
+
term/ the renderer: raw mode, input decoding, the differ, the screen
|
|
1248
|
+
tui/ views, commands, per-tool renderers, themes
|
|
1249
|
+
themes/ the shipped palettes, as JSON
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
The core is headless and emits events; the TUI and print mode are both just
|
|
1253
|
+
consumers. Nothing under `core/`, `tools/`, `providers/` or `permissions/`
|
|
1254
|
+
imports `tui/`.
|
|
1255
|
+
|
|
1256
|
+
---
|
|
1257
|
+
|
|
1258
|
+
## Releasing
|
|
1259
|
+
|
|
1260
|
+
For maintainers. HX publishes to PyPI as **`hx-cli`** from CI, on a tag.
|
|
1261
|
+
|
|
1262
|
+
One-time setup:
|
|
1263
|
+
|
|
1264
|
+
1. Push the repo to `github.com/<owner>/hx` and update the URLs in
|
|
1265
|
+
`pyproject.toml`.
|
|
1266
|
+
2. Create a GitHub environment named `pypi`.
|
|
1267
|
+
3. On PyPI, add a [trusted publisher](https://docs.pypi.org/trusted-publishers/)
|
|
1268
|
+
for the project: owner, repo `hx`, workflow `ci.yml`, environment `pypi`.
|
|
1269
|
+
No API token is stored anywhere.
|
|
1270
|
+
|
|
1271
|
+
Each release:
|
|
1272
|
+
|
|
1273
|
+
```sh
|
|
1274
|
+
# 1. move CHANGELOG.md's [Unreleased] entries under the new version, dated,
|
|
1275
|
+
# and leave a fresh empty [Unreleased] behind
|
|
1276
|
+
# 2. bump __version__ in src/hx/__init__.py
|
|
1277
|
+
# 3. uv run pytest tests/e2e/test_cli.py # the version must have a section
|
|
1278
|
+
git commit -am "release: X.Y.Z"
|
|
1279
|
+
git tag v$(uv run hx --version | cut -d' ' -f2) && git push origin main --tags
|
|
1280
|
+
```
|
|
1281
|
+
|
|
1282
|
+
Step 1 is not optional and is not a convention: `tests/e2e/test_cli.py` fails the
|
|
1283
|
+
whole suite when `__version__` has no `CHANGELOG.md` section, so a release that
|
|
1284
|
+
skips it cannot get past CI to the `publish` job. The file ships inside the
|
|
1285
|
+
wheel and `hx changelog` prints it, so a version with no section there reaches
|
|
1286
|
+
users as a blank release.
|
|
1287
|
+
|
|
1288
|
+
The `publish` job runs only on `refs/tags/v*` and only after lint, the test
|
|
1289
|
+
suite and an install-script run in a clean Debian container have passed. It builds with
|
|
1290
|
+
`uv build`, checks that the wheel's version matches the tag and has a `CHANGELOG.md`
|
|
1291
|
+
section, uploads via OIDC, and then creates the GitHub release with that section
|
|
1292
|
+
as its notes.
|
|
1293
|
+
|
|
1294
|
+
To check a build before tagging:
|
|
1295
|
+
|
|
1296
|
+
```sh
|
|
1297
|
+
uv build && ls dist/
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
---
|
|
1301
|
+
|
|
1302
|
+
## Status
|
|
1303
|
+
|
|
1304
|
+
Feature complete against the original plan: the agent loop, OpenRouter
|
|
1305
|
+
streaming with prefix caching and accurate cost accounting, session persistence
|
|
1306
|
+
and resume, the tool suite, the permission engine and OS sandbox, late
|
|
1307
|
+
injection, compaction, output capping, skills, subagents, MCP, and the TUI.
|
|
1308
|
+
|
|
1309
|
+
Three routes to a model: an OpenRouter API key, a ChatGPT Plus/Pro
|
|
1310
|
+
subscription over OAuth, or a Devin subscription over OAuth. The model id
|
|
1311
|
+
decides which.
|
|
1312
|
+
|
|
1313
|
+
Published to PyPI as [`hx-cli`](https://pypi.org/project/hx-cli/), released
|
|
1314
|
+
from CI on a tag.
|
|
1315
|
+
|
|
1316
|
+
The one thing still unproven in CI is a live call on any route: the `live`
|
|
1317
|
+
tests exist and cover all three wire formats, tool use, reasoning replay and a
|
|
1318
|
+
genuine cache hit, but they need a credential and are deselected by default.
|