Basic AI harness in Go.
- CLI prompt interface
- streaming output with
-stream - automatically saved TUI sessions with
/sessions,/new, and CLI memory with-memory - local cross-session recall with text search, calendar-day filters and source references
- config via
.env - provider override via
OPENAI_BASE_URL - multiple OpenAI-compatible providers in
hanoi.json[c], with CLI and TUI model selection - GitHub Copilot provider with OAuth2 device login in the CLI and TUI
- works as a simple OpenAI-compatible harness
- includes OpenAI-style tool calling with a local
bashtool - parallel
tasksubagents with live task status in the TUI - context-window, session-token and configured-price cost display in the TUI
- optional API logging with
-log <file> - live Hanoi Trace timeline in the TUI and optional structured JSONL export with
-trace <file> - MCP tools from local and remote servers, with OpenCode-compatible config and
/mcpsmanagement - local and global Agent Skills with an interactive
/skillspicker - tag-based
-versionoutput and GitHub Actions builds for Linux, macOS, and Windows
Warning: Hanoi intentionally lets the model execute local commands via
bash -lcwithout per-command user approval. It intentionally provides no application-level file-access permission gate or workspace confinement. These are features for a trusted, operator-controlled Cyber Gym, not a secure sandbox for untrusted model output.
Bash commands run with the privileges of the user running Hanoi and inherit its process environment. A model can therefore read, create, modify or delete any file that this user can access, run programs and use available network access. Tool results are sent back to the selected model provider; commands can expose credentials, environment variables and private file contents. A compromised provider or prompt injection in repository files, logs or other tool output can turn this intended capability into unintended actions or data disclosure.
No Hanoi-level file-access restrictions does not mean OS permissions are removed. Normal operating-system permissions still apply. Hanoi also uses restrictive permissions for some files it creates, such as saved tool results; these protect those stored files, but do not restrict what Bash can access. The tool working directory is only a starting directory, not a filesystem boundary: commands can use absolute paths or change directories.
WSL alone is not a security sandbox. Depending on its configuration, WSL can
access Windows files through mounted drives (such as /mnt/c) and invoke Windows
programs through interoperability. Running Hanoi in WSL does not by itself
isolate the Windows host, credentials or other reachable systems.
For Cyber Gym exercises:
- Use a disposable, isolated VM or a carefully restricted container, with an unprivileged user and only the required test files and network targets exposed.
- Do not expose host home directories, production credentials, SSH agents, privileged sockets or sensitive environment variables to the exercise.
- If using WSL, explicitly review Windows drive mounts and interoperability; do not rely on the default setup as the isolation boundary.
- Use test credentials, snapshots/backups and an explicitly authorized target scope. Assume model-driven commands can destroy data available to that user.
- Review project configuration before launching Hanoi: enabled local MCP servers can also start programs with the user's privileges.
Isolation and authorization must be enforced outside Hanoi. Prompt instructions, working-directory choices and command timeouts are not security boundaries.
Hanoi uses one Go module with focused internal packages:
main.go CLI entry point
version.go Build-time version (main.version)
internal/
app/ Application wiring, agent loop, API client, MCP and TUI
config/ Provider settings and OpenCode-compatible config loading
doctor/ Local runtime and writable-storage checks
skills/ Agent Skills discovery, YAML metadata and instruction loading
tools/ Bash execution, process cancellation and tool-result storage
trace/ Lifecycle events, run correlation and JSONL recording
Tests live alongside the package they cover; end-to-end agent/tool and TUI tests
are in internal/app. The tools and trace packages are independent of the TUI,
provider configuration and MCP implementation.
For GitHub Copilot, log in once and start the TUI:
hanoi.exe -auth github-copilot
hanoi.exe -tuiThe saved Copilot login is used automatically when no other provider or OpenAI
environment settings are selected. In the TUI, /models discovers available
Copilot models; use ↑/↓ and Enter to activate one. hanoi.exe -models
lists them directly in the terminal. See Windows: install or update Hanoi
for installation, and GitHub Copilot (OAuth2) for details.
When running from source, replace hanoi.exe with go run ..
For an OpenAI API key, create a .env file:
OPENAI_API_KEY=your_key_here
OPENAI_MODEL=gpt-4o-mini
OPENAI_BASE_URL=https://api.openai.com/v1/chat/completionsEnvironment variables still work too.
In the TUI, the task tool lets the model delegate independent investigations.
Task calls returned in the same model response run concurrently (up to four),
and the header shows each task's status. Subagents have separate conversations,
share the working directory and cannot start further subagents. Stopping a turn
also cancels its subagents.
Task counts occupy one line in the TUI; press Ctrl+S to open the scrollable
task list (or Esc to close it). Failed tasks show the underlying error there,
including an explicit message when a subagent reaches its five-minute limit.
The TUI shows the last main-agent input token count against the configured
contextWindow, plus accumulated input/output tokens including subagents.
For configured models, set contextWindow and cost.input/cost.output in
hanoi.json as shown in hanoi.json.example; costs are USD per million tokens.
Usage comes from provider responses and is saved with the session. A ? means
the provider omitted usage or the model's context window/pricing is unknown;
cost is shown only when all recorded usage has configured pricing. The context
count is the previous request's reported input, not a prediction for the next.
If the provider explicitly rejects a model request for exceeding its context limit, Hanoi asks the model to summarize older, complete conversation turns without tools, then retries the request (at most three compactions). The latest user request and any pending tool call/results stay together; the saved session history is not rewritten. If even the current request or the summary cannot fit, Hanoi reports the error. Other API errors do not trigger compaction. This also applies to subagents, within their five-minute task timeout.
OpenAI gpt-6-astra and gpt-6.1-sol require the Responses API for function
calling. Hanoi automatically uses /v1/responses for these models on
api.openai.com, including when OPENAI_BASE_URL is the usual Chat Completions
URL. Reasoning remains enabled; Bash/MCP tools, streaming and tool follow-up
rounds are supported. Other compatible providers can opt in by setting their
base URL to the full /responses endpoint. Responses requests use store: false
and pass encrypted reasoning items back within the current tool loop.
If a Chat Completions provider explicitly rejects function tools combined with
reasoning and instructs Hanoi to set reasoning_effort to none, Hanoi retries
that request once with reasoning_effort: "none". Bash and MCP tools remain
enabled. The retry is shown in the TUI status and API log; other API errors are
returned normally. This applies to streaming and non-streaming requests, including
environment-only configuration.
Hanoi's built-in tool runs commands using bash -lc. Bash must be installed
and bash.exe must be available on PATH, including when starting Hanoi from
PowerShell or Command Prompt. PowerShell alone does not provide Bash.
Install Git for Windows, which includes Git Bash. You can also install it from PowerShell using WinGet:
winget install --id Git.Git -e --source wingetAfter installation, start Hanoi from Git Bash, or add the Git Bash executable
directory to your PowerShell session's PATH (adjust for your installation):
Test-Path "C:\Program Files\Git\bin\bash.exe"
$env:Path = "C:\Program Files\Git\bin;$env:Path"
Get-Command bash
.\hanoi.exe -tuiThe PATH change above applies only to the current PowerShell session. To make
it persistent, add C:\Program Files\Git\bin to your user Path in Windows
Environment Variables and open a new terminal. Run /doctor in Hanoi to verify
that Bash is detected. If it reports executable not found in PATH, Bash is
not yet accessible to the Hanoi process.
Do not confuse Git Bash with Windows' bash.exe launcher. In Command
Prompt, check which executable a plain bash command starts:
where bashC:\Windows\System32\bash.exe is a WSL launcher, not Git Bash. A result
under Microsoft\WindowsApps is also not the Git for Windows installation.
To explicitly start Git Bash from Command Prompt, use:
"C:\Program Files\Git\bin\bash.exe" --login -iThen, in that Git Bash session, log in to Copilot and start the Windows executable from its directory:
./hanoi.exe -auth github-copilot
./hanoi.exe -tuiFor OpenAI API-key authentication, set the key instead:
export OPENAI_API_KEY="your_key_here"
./hanoi.exe -tuiGit Bash normally reports MINGW64_NT-... or a similar Windows name for
uname -s; Linux indicates a Linux environment. Starting a Windows executable
from WSL can require explicit environment forwarding, even after export, and
can otherwise cause OPENAI_API_KEY is not set. The Git Bash commands above
pass the exported key directly to the Windows executable. OPENAI_MODEL and
OPENAI_BASE_URL are optional; their defaults are gpt-4o-mini and
https://api.openai.com/v1/chat/completions.
After installing Git for Windows as described above, open Git Bash and create a directory for the executable:
mkdir -p ~/binAdd it to PATH once, then reload your shell settings:
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcDownload the latest Windows x64 release:
curl -fL -o ~/bin/hanoi.exe https://github.com/eumel8/hanoi/releases/latest/download/hanoi-windows-amd64.exeOn Windows ARM64, use hanoi-windows-arm64.exe in the URL instead.
Available versions and their binaries are listed on the
releases page.
Make the file executable in Git Bash and check the installed version:
chmod +x ~/bin/hanoi.exe
hanoi.exe -versionThe output is hanoi v<installed-version>. To update, close running Hanoi
instances and repeat the download command, which replaces ~/bin/hanoi.exe.
OAuth credentials are stored separately and remain available after updating.
Model discovery requires a build that includes the discovery feature; check the
release notes if your version does not recognize -models.
Log in once with your GitHub Copilot account, then discover models and start:
hanoi.exe -auth github-copilot
hanoi.exe -models
hanoi.exe -tuiFollow the GitHub URL and enter the code shown by the login command. Subsequent
starts need only hanoi.exe -tui. In the TUI, /models loads the account's
available compatible models; select one with ↑/↓ and Enter, or press r
to refresh the list. /doctor checks that the Bash tool is ready.
To select a model explicitly, for example when other provider settings exist:
hanoi.exe -tui -model github-copilot/gpt-4.1The commands above use Git Bash. In PowerShell, an executable in the current
directory is started with .\hanoi.exe; the Git Bash executable directory must
also be on PATH for Hanoi's Bash tool.
Single prompt:
go run . "Sag hallo auf Deutsch"Streaming:
go run . -stream "Erzähl einen kurzen Witz"Conversation memory:
go run . -memory chat1 "Mein Name ist Eva"
go run . -memory chat1 "Wie heiße ich?"TUI chat mode:
go run . -tui
go run . -tui -memory chat1Inside TUI:
EntersendsAlt+Enterinserts a newlineEsc Esc(twice consecutively within one second) stops the current model request and active Bash/MCP tool call, and skips remaining tools and follow-up requests. The session stays open; the prompt and any text already received remain in the conversation. Wait forStopped.before sending the next prompt. Bash process trees are terminated; MCP calls receive cancellation (remote servers must cooperate). Work already performed by tools is not undone.↑/↓recalls earlier prompts and slash commands at the first/last input line;Alt+↑/Alt+↓recalls them from anywhere, preserving the current draft (session history, seeded from saved user messages when using-memory)Ctrl+↑/Ctrl+↓scrolls three lines per press (including repeated presses);PgUp/PgDownscrolls a page andCtrl+Home/Ctrl+Endjumps to the beginning/end, with a scrollbar showing the current position- mouse reporting is off by default, allowing normal terminal text selection
and copying (including in Windows Terminal/WSL).
Ctrl+Gtoggles mouse-wheel scrolling; toggle it off again to select text normally - assistant responses stream live in the TUI
- scrolling up pauses automatic following until you return to the bottom
- Markdown headings, lists, tables, and syntax-highlighted code blocks render live, with wrapping adjusted to the terminal width and colors for light or dark backgrounds
/exitor/quitends the session/clearresets the current conversation/new [name]saves the current conversation and starts a fresh session/sessionsopens saved conversations (newest first);/sessions <name>resumes one directly/savewrites memory to disk/model <provider/model>switches provider and model (/model <name>switches within the active provider)/providers,/models, or/modelopens the provider/model picker and discovers Copilot models;rrefreshes the list/connect github-copilotlogs in to GitHub Copilot;/logout github-copilotremoves its local login/system <text>saves the system prompt for the active session and the workspace;/systemwithout text clears both (project instructions remain active)/mcpsopens MCP server management/skillslists available skills; select with↑/↓andEnter, or use/skills <name>directly/traceorCtrl+Ttoggles the live trace timeline, including while a response is running;Escreturns to chat and restores its scroll position/doctorchecks the local runtime, storage, active model, configuration/log paths, and the current MCP connection/tool catalog;/doctor provideralso tests the model endpoint/helpshows commands
Hanoi inherits the terminal's default foreground and background for ordinary text, hints, the top status/header and the input area. The status/header is highlighted with bold text only, so it remains readable with custom terminal palettes even if background detection is inaccurate. Hanoi does not paint a separate input-line background. Accent colors and Markdown highlighting adapt to light or dark backgrounds, and Markdown uses the terminal's detected color capabilities.
The default -theme auto uses COLORFGBG when available, otherwise the terminal
background detected by Lip Gloss. Under Linux/WSL that detection uses terminal
queries; it is not a read of Windows Terminal's settings file. Native Windows
executables cannot detect the background through the current library and default
to dark unless COLORFGBG is available. If detection does not match your terminal,
select the theme explicitly:
hanoi -tui -theme light
hanoi -tui -theme darkThese flags select accent/highlighting styles; your terminal still controls the default text and background colors. Restart Hanoi after changing the terminal theme.
Enabled MCP servers connect and discover tools concurrently at startup, rather
than adding their individual delays together. Startup still waits for all servers
to finish or time out so the first prompt receives the complete available tool
catalog. /mcps shows connection errors; -log api.log records connection events.
An empty conversation initializes Markdown rendering only when text is needed.
The current terminal library can also wait up to five seconds for an unsupported
background query before Hanoi's startup code runs; -theme cannot bypass this
library initialization delay.
Hanoi has no built-in default system prompt. In the TUI, set one for subsequent
messages with /system <text>, for example:
/system Answer concisely and in German.
The command clears the input, confirms the change and displays the active prompt
in the header. It saves the text to .hanoi/system.md in the launch directory,
using private permissions and a temporary-file/rename write. You can also edit
this plain UTF-8 Markdown file yourself (at most 1 MiB); restart Hanoi to load it.
The .hanoi/ directory is already excluded from Git in this repository.
This file provides the default prompt for CLI requests, new TUI sessions and
older sessions without a saved system prompt. A session's saved prompt takes
precedence over the workspace default and is restored when the session is resumed.
/system without text empties the file and clears the active session's prompt;
other saved sessions retain their prompts. An explicitly cleared session stays
cleared even if a different workspace default is set later. /new uses the current
workspace default. The prompt file is separate from hanoi.json[c], so saving it
does not rewrite provider/MCP settings or JSONC comments.
For project-wide rules, add a standard Markdown AGENTS.md
file to your project. At startup, Hanoi searches the launch directory and then
its parents, loading only the nearest AGENTS.md. A nearer file takes precedence;
other ancestor files and files in child directories are not loaded. An empty
nearest file provides no rules. Files must be UTF-8 and at most 1 MiB;
unreadable or invalid files cause a startup error instead of silently ignoring rules.
The file content, absolute path and base directory are combined with the manual
/system prompt into one system message at the beginning of every CLI and TUI
model request, including streaming and tool follow-ups. Project instructions
come first, followed by the manual prompt. This also supports providers that
accept only one leading system message. The TUI header shows the loaded path.
Clearing the manual prompt leaves AGENTS.md active. Project instructions
stay active across session changes and are not copied into session files.
Restart Hanoi to load changes to AGENTS.md. Its contents are included in API
requests and in the API log when -log is enabled.
The repository includes a generic Kubernetes operations AGENTS.md:
verify the target context, diagnose before changing, protect secrets, prefer
GitOps-compatible changes and verify the outcome. Copy and adapt it to your own
operations workspace. These are model instructions, not a tool permission
enforcement mechanism.
Store reusable instructions in the Agent Skills format:
~/.hanoi/skills/<name>/SKILL.md Global skills for every workspace
./.hanoi/skills/<name>/SKILL.md Skills for the launch directory
Hanoi combines both locations, sorted by name. A workspace skill overrides a global skill with the same name. Each skill lives in its own directory, with YAML frontmatter and Markdown instructions:
---
name: code-review
description: Review code changes for correctness and maintainability.
---
Read the current diff, explain any bugs found, and suggest focused improvements.The name must match the directory name and contain at most 64 lowercase letters,
digits and single hyphens, with no leading or trailing hyphen. The description
must contain 1–1024 characters. YAML multiline descriptions are supported;
additional metadata fields are accepted. SKILL.md must be UTF-8, no larger than
1 MiB, and contain nonempty instructions after the frontmatter.
In the TUI, /skills opens the list with names, descriptions and file paths:
↑/↓andEnter: load the selected skill and send its instructions to the modelr: refresh the list; it is also refreshed each time/skillsopensEsc: return to chat without loading a skill/skills code-review: load and send a skill directly
The skill is sent as a user message in the current conversation, retaining the
system prompt and using normal streaming, tool calling and session persistence.
Its absolute file path and base directory accompany the instructions, so the
model can resolve relative references such as references/guide.md or
scripts/check.sh through the Bash tool. Additional files and scripts are not
loaded or executed by the picker itself. Invalid skills are reported in the
picker while valid entries remain available. No skill is loaded automatically.
Use /doctor in the TUI for a scrollable report. It checks whether Bash is in
PATH, verifies that the tool working directory and result storage are writable,
and displays the selected provider/model, configuration file, API log and trace
paths. Missing tool directories are created and temporary write probes are
removed. MCP diagnostics use the current connection state and list available
tool names; they do not reconnect servers or invoke tools.
/doctor provider additionally sends one small, tool-free chat request to the
active model, using the configured authentication and headers with a 20-second
timeout. This is a real model request and may incur provider charges. Success
requires a usable chat response, rather than just a reachable HTTP endpoint.
Credentials, raw provider error bodies and OAuth login URLs are omitted from
the report. Local-only /doctor makes no network requests.
Results use OK, FAIL, WARN, SKIP and INFO labels. Scroll as in chat and
press Esc to return. Diagnostic results do not enter the model conversation or
saved chat memory.
Trace shows the execution of each new turn: user input, provider/model requests, response duration and tool-call count, Bash/MCP calls and arguments, execution duration, Bash exit codes, errors/timeouts, and tool-result sizes passed back to the model. Both streaming and non-streaming requests use the same event format. Tool errors remain visible even when the model recovers and completes the turn.
go run . -tui -trace trace.jsonl
go run . -trace trace.jsonl "Inspect the current workspace"
go run . -stream -trace trace.jsonl "Inspect the current workspace"The file is append-only JSONL (one event per line), created with mode 0600.
Each event has a timestamp, run ID, turn number, sequence number and model
reference. Event types are turn.started, model.started, model.completed,
tool.started, tool.completed, tool.result, and turn.completed.
Durations are in milliseconds; output sizes are bytes before truncation and
result sizes are bytes after preparation for the next model request.
Sequence and turn numbers restart with each process; run IDs correlate events
across appended sessions. A completed turn means the model finished, not that
its claims were independently verified.
The TUI retains the latest 2,000 events for the current session; the file keeps
all events. Saved conversation history does not reconstruct earlier traces.
Trace includes prompts, tool arguments and errors, but omits credentials from
request headers and does not record complete model responses or tool output.
Use -log api.log for the existing full API-payload logging when needed.
Build:
go build
./hanoi -version
./hanoi -tui -memory chat1hanoi -version prints the embedded version and exits without loading .env,
requiring an API key, or connecting to MCP servers. For example, a build from tag
v1.2.3 prints hanoi v1.2.3. A plain go build without version injection prints
hanoi dev.
To embed the current Git version in a local build (Bash):
go build -trimpath -ldflags "-X main.version=$(git describe --tags --always --dirty)" -o hanoi ..github/workflows/build.yml runs on branch/tag pushes, pull requests, and manual
dispatches. It runs race-enabled tests and go vet on Linux, then builds:
| Platform | Architectures | Binaries |
|---|---|---|
| Linux | amd64, arm64 | hanoi-linux-amd64, hanoi-linux-arm64 |
| macOS | amd64, arm64 | hanoi-darwin-amd64, hanoi-darwin-arm64 |
| Windows | amd64, arm64 | hanoi-windows-amd64.exe, hanoi-windows-arm64.exe |
Builds use the Go version specified in go.mod, with CGO disabled. Each binary
and its .sha256 checksum are available as workflow artifacts. Tag pushes embed
the exact tag and publish the files to a GitHub Release. Other builds use
git describe --tags --always --dirty, for example v1.2.3-4-gabcdef0.
To trigger a release after pushing the workflow:
git tag v1.2.3
git push origin v1.2.3Downloaded Linux/macOS binaries may need chmod +x before running. The built-in
bash tool requires Bash at runtime, including on Windows (for example from Git
for Windows).
Hanoi reads the mcp section of a config following
the OpenCode schema. It searches the current
workspace for hanoi.json, hanoi.jsonc, opencode.json, then opencode.jsonc
and uses the first file found. JSONC comments and trailing commas are supported.
You can select a file explicitly with -config path/to/config.json.
The same file can configure provider and model as described below.
Other OpenCode settings are ignored.
Start by copying hanoi.json.example to hanoi.json. Its example servers are
disabled initially and can be enabled through /mcps after configuration.
Current schema format:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"timeout": { "startup": 10000, "catalog": 5000, "execution": 60000 },
"servers": {
"filesystem": {
"type": "local",
"command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "."],
"disabled": false
}
}
}
}Local servers use MCP stdio. command is an executable/argument array, not a shell
string. Optional cwd resolves relative to the workspace, and environment
overrides inherited environment variables. The filesystem example requires
Node.js and npx.
Remote servers use "type": "remote", "url": "https://host/mcp", and optional
headers or OAuth authentication. Hanoi tries Streamable HTTP, then legacy SSE.
Use {env:VARIABLE} in commands, paths, environment values, URLs, or headers
to reference environment variables (including variables loaded from .env).
Set "oauth": false when using a static Authorization header. codemode: true
is not implemented; use direct MCP tools instead.
The legacy OpenCode format is also accepted:
{
"mcp": {
"filesystem": {
"type": "local",
"command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "."],
"enabled": true,
"timeout": 10000
}
}
}Timeouts are milliseconds. Per-server timeout objects override the global
mcp.timeout values. A legacy integer applies to startup, catalog, and execution.
Hanoi's defaults are 5000 ms for startup/catalog and 60000 ms for execution.
protocol supports legacy (default), auto, and 2026-07-28.
./hanoi -tui -config hanoi.json -log debug.logType /mcps to open the server list with connection status, tool counts, and errors:
↑/↓: select a serverEnter: enable/connect or disable/disconnect the selected serverr: reconnect and refresh the selected server's toolst: inspect tool names and descriptionsa: authenticate with OAuth;l: log outCtrl+R: reload the config and connectionsEsc: return to the chat
Commands are also available directly from the chat input:
/mcps list
/mcps enable filesystem
/mcps disable filesystem
/mcps reconnect filesystem
/mcps tools filesystem
/mcps reload
/mcps auth remote-oauth-example
/mcps logout remote-oauth-example
Enable/disable changes apply to the current process. Edit disabled (or legacy
enabled) in the config to persist the startup state. Reloading applies the
file's settings; a config syntax error preserves existing connections.
Connected servers' tools are automatically advertised alongside bash in CLI,
streaming, and TUI chat requests. Tools receive stable, namespaced API names to
avoid collisions. MCP results, including structured content and tool errors,
are sent back to the model. Startup failures are visible in /mcps and do not
prevent other servers from being used. Connections and local processes are closed
when Hanoi exits. With -log, MCP connection events, local stderr, tool calls,
and results are logged as well as the model API traffic.
For a remote MCP server requiring OAuth, omit oauth or set it to {}:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"my-service": {
"type": "remote",
"url": "https://your-service.example/mcp",
"oauth": {}
}
}
}
}An unauthorized server shows needs_auth in /mcps. Select it and press
Enter or a, or run /mcps auth my-service. Hanoi discovers the OAuth
authorization server, dynamically registers a public client if needed, opens
the browser, and completes the Authorization Code flow with PKCE. After login,
Hanoi connects the MCP server and discovers its tools. OAuth works with both
Streamable HTTP and legacy SSE.
The login URL is also shown in /mcps if the browser cannot be opened. Login
waits up to three minutes and can be cancelled with Esc. The callback defaults
to http://127.0.0.1:19876/mcp/oauth/callback; the browser must be able to reach
that loopback address (use port forwarding when running Hanoi over SSH).
If the authorization provider needs an existing client registration, configure:
"oauth": {
"client_id": "{env:MCP_CLIENT_ID}",
"client_secret": "{env:MCP_CLIENT_SECRET}",
"scope": "read write",
"callback_port": 19876
}client_secret is optional for public clients. redirect_uri can specify a
different loopback HTTP callback URL and takes precedence over callback_port;
register that exact URI with your provider. auth_server_metadata_url optionally
overrides the discovery document location. Legacy OpenCode clientId,
clientSecret, callbackPort, and redirectUri names are accepted too.
Tokens and refresh configuration are stored under
$XDG_CONFIG_HOME/hanoi/mcp-oauth/ (normally ~/.config/hanoi/mcp-oauth/ on Linux).
The directory uses 0700, token files use 0600, and updates are atomic.
Sessions are scoped to the configured server URL and OAuth settings. Subsequent
starts reuse the login and refresh tokens automatically. If refresh fails or the
session expires, use /mcps auth my-service again. Tokens, client secrets,
authorization codes, and token endpoint responses are not written to the debug
log by the OAuth implementation.
/mcps logout my-service disconnects the server and deletes its local OAuth
session. It does not revoke authorization at the provider. Disable the server
separately if you also want to remove it from startup connections.
Enable logging when debugging requests or tool-call follow-ups:
./hanoi -log hanoi.log "Nutze bash und zeige das aktuelle Verzeichnis"
./hanoi -tui -log hanoi.logThe log appends UTC timestamps, request JSON, HTTP status codes, and response
body chunks (including streaming responses and API error bodies). Response chunks
are quoted to preserve newlines. Authorization headers are not logged. Prompts,
conversation history, and tool output are included and can contain sensitive data.
New log files are created with owner-only read/write permissions (0600).
Logging is disabled unless -log is supplied.
Configure multiple providers using the
OpenCode custom-provider format.
Providers share the same JSON/JSONC file as MCP servers (-config also applies to
providers). For example:
{
"$schema": "https://opencode.ai/config.json",
"model": "openai/gpt-4o-mini",
"provider": {
"openai": {
"npm": "@ai-sdk/openai-compatible",
"name": "OpenAI",
"options": {
"baseURL": "https://api.openai.com/v1",
"apiKey": "{env:OPENAI_API_KEY}"
},
"models": {
"gpt-4o-mini": { "name": "GPT-4o mini" }
}
},
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": { "baseURL": "http://localhost:11434/v1" },
"models": {
"qwen3-coder": { "name": "Qwen3 Coder" }
}
}
}
}model selects the startup provider/model. Override it for a single run:
go run . -model ollama/qwen3-coder "Hello"
go run . -tui -config hanoi.jsonIn the TUI, /providers or /models opens a sorted list with provider/model
display names and the active selection. Use ↑/↓ and Enter to switch, or
Esc to close. /model ollama/qwen3-coder switches directly. Switching applies
to subsequent requests and keeps the conversation; edit model in the file to
persist a default. If exactly one model is configured, it is selected automatically;
otherwise model or -model is required.
- Provider IDs are the keys of
provider; model keys must match a configured model. A model's optionalidoverrides the model ID sent to the API. Model IDs can contain slashes, for examplegateway/vendor/model. options.baseURLis an API base URL; Hanoi appends/chat/completions. A full Chat Completions endpoint is also accepted, including query parameters. Theopenaiprovider defaults tohttps://api.openai.com/v1.options.apiKeysets Bearer authentication. Omit it for unauthenticated local servers. Theopenaiprovider falls back toOPENAI_API_KEYwhen omitted.options.headersadds custom request headers and can override Authorization. Keys and header values support{env:VARIABLE}, including.envvariables. Only the selected provider's variables are resolved, so an unused provider's missing credentials do not prevent startup.- Hanoi uses OpenAI Chat Completions for all providers.
npmmay be omitted,@ai-sdk/openai-compatible, or@ai-sdk/openai; it is a compatibility marker, not an installed adapter. Native Anthropic, Bedrock, and other API protocols, and OpenCode's credential store are not supported. GitHub Copilot has built-in OAuth support as described below.
Log in with GitHub's OAuth2 Device Authorization flow, using the same public OAuth client as OpenCode:
go run . -auth github-copilot
go run . -model github-copilot/gpt-4.1 "Hello"
go run . -tui -model github-copilot/gpt-4.1Hanoi displays a GitHub verification URL and a one-time code and opens the
browser. Enter the code and authorize access. No API key, client secret, or
localhost callback is required. Ctrl+C cancels CLI login. The GitHub account
must have Copilot access; model availability depends on the account and plan.
With a saved Copilot login and no other provider or OpenAI environment settings,
hanoi.exe -tui defaults to github-copilot/gpt-4.1. To choose a different
startup model or use Copilot alongside other providers, set the top-level model
in hanoi.json (use a model ID from /models or hanoi.exe -models):
{
"model": "github-copilot/gpt-4.1",
"provider": {
"github-copilot": {
"name": "GitHub Copilot",
"models": {
"gpt-4.1": { "name": "GPT-4.1" },
"gpt-5-mini": { "name": "GPT-5 mini" },
"gpt-6.1-sol": { "name": "GPT-6.1 Sol" }
}
}
}
}The provider section is optional when using -model github-copilot/<model> or
a top-level Copilot model. /models, /providers, and /model automatically
load the available models from Copilot using your saved login. Discovery also
runs after a successful TUI login. Use ↑/↓ and Enter to select a model;
the list scrolls to keep the selection visible. Press r to refresh it.
List available models from the CLI without sending a chat request:
hanoi.exe -models
go run . -modelsDiscovery displays enabled chat models with a supported Chat Completions or
Responses endpoint, excluding models that explicitly disable tool calling.
It uses the account-specific API endpoint and preserves configured aliases and
display names for available models. The remote catalog supplies the correct
API route. No project configuration is rewritten. If discovery fails, the
existing list remains available and an error is shown; press r to retry.
Before discovery, the built-in picker offers gpt-4.1 and gpt-5-mini.
You can still select model IDs directly with /model github-copilot/<model>.
Without catalog metadata, Copilot uses the following routing: GPT-5 and
newer (except gpt-5-mini), Grok, and MAI Code are routed to /responses;
other models use /chat/completions. Models that require native Anthropic
Messages are not supported by this integration.
In the TUI use /connect github-copilot, or press a in /providers. The code
and URL remain visible while waiting; Esc cancels. After connecting, select a
Copilot model. /doctor provider uses the saved OAuth session too. Requests
include Copilot's API version, intent and initiator headers, distinguishing user
prompts from agent/tool follow-up requests. Hanoi uses the account-specific API
endpoint reported by GitHub, falling back to https://api.githubcopilot.com.
An explicit options.baseURL overrides this endpoint. A full /chat/completions
or /responses URL also overrides automatic model routing.
The GitHub OAuth token is stored separately from project configuration under
os.UserConfigDir()/hanoi/provider-oauth/github-copilot.json (normally
~/.config/hanoi/provider-oauth/github-copilot.json on Linux). The directory uses
0700, the file uses 0600, and writes are atomic. Later requests reuse the
saved login; OAuth responses and credentials are not written to the API log.
If GitHub expires or revokes the token, log in again. Hanoi does not read or
modify OpenCode's credentials. This flow currently supports GitHub.com accounts.
go run . -logout github-copilotAlternatively use /logout github-copilot or press l in /providers. Logout
deletes the local session; it does not revoke the authorization on GitHub.
Without a provider section, the original OPENAI_API_KEY, OPENAI_MODEL, and
OPENAI_BASE_URL settings still work. OPENAI_BASE_URL continues to mean the
full endpoint URL in this mode. For example:
OPENAI_API_KEY=... OPENAI_MODEL=... OPENAI_BASE_URL=https://host/v1/chat/completions go run . "Hello"Security: Model-selected commands run without per-command approval or Hanoi-level file-access restrictions. Read Security and Cyber Gym usage before enabling access to sensitive files or systems.
hanoi now sends an OpenAI-compatible bash tool with each request. If the model decides to call it, the command is executed locally via bash -lc, and the tool result is sent back to the model as a follow-up tool message.
Tool calling works in normal CLI mode, with -stream, and in the TUI. Streamed
tool-call fragments are assembled before execution, including multiple calls in
one response. The model's answer after tool execution appears in the chat;
the raw tool results can be inspected in the follow-up request in the API log.
Bash commands run in /tmp/hanoi by default (os.TempDir()/hanoi on other
platforms or when TMPDIR is set). The directory is created with 0700
permissions. Configuration and conversation memory still use the launch directory.
Bash commands have a 30-second timeout. On Linux and macOS, a timeout stops the
whole command process group, including pipelines. The TUI status distinguishes
waiting for the model, receiving a response, and running a tool. Tool start/end
times are recorded with -log. The Bash tool description includes the working
directory and saved-results directory for follow-up questions.
Tool results larger than 32 KiB are saved in full under /tmp/hanoi/tool-results/
with owner-only file permissions (0600). The model receives a limited preview,
an explicit truncation notice, and the absolute file path so it can use bash to filter
or aggregate the full result. This applies to both MCP and Bash tools. Saved
results remain available after exit; remove them when no longer needed.
Bash output spills to a file as soon as the capture exceeds 32 KiB, keeping
only a bounded preview in memory while the command is still running. Noisy
commands remain subject to the same timeout and cancellation behavior.
The TUI also bounds status/error lines and strips terminal control sequences
from displayed content. Large responses use plain text beyond 8 KiB instead
of repeatedly parsing Markdown, with a 32 KiB display preview. Completed full
responses remain available in the session file; the preview limit only affects
display. Esc Esc stops the current request/tool and Ctrl+C exits.
Example prompt:
go run . "Nutze das bash tool und gib mir die Dateien im aktuellen Ordner aus"The TUI automatically saves conversations in the current workspace's .hanoi/
directory. You can start with hanoi.exe -tui without choosing a memory name.
An unnamed conversation receives a unique timestamp-based session ID when you
send its first message. User messages are saved before the model request;
completed responses and partial responses stopped with Esc Esc are saved too.
Empty startup conversations are not written unless you explicitly use /new
or /save.
/sessions: open the session picker, sorted by most recently saved. Entries show the first user message as a title, session ID, last update and message count.↑/↓,Enter: select and resume a conversation.Esccloses the picker;nstarts a new session./sessions <name>: resume a saved session directly./new [name]: save the current conversation and start a fresh session. Omit the name for an automatic ID. Existing sessions are never overwritten by/new./save: save the current session explicitly./clear: empty the active session, including its saved conversation. Use/newwhen you want to keep the previous conversation.
Switching restores conversation messages, the saved manual system prompt and prompt-recall history, and resets the session trace view. The selected provider/model stays active. Stop an in-progress response before switching sessions. A failed save or unreadable destination leaves the current conversation open.
Existing -memory chat1 files appear in /sessions and remain compatible with
CLI usage:
hanoi.exe -tui -memory chat1
hanoi.exe -memory chat1 "Continue this conversation"CLI prompts are persisted only when -memory is supplied. Session names must be
plain filenames without path separators. Files use a versioned JSON object with
version, created_at, updated_at and messages. New user and assistant
messages have RFC3339 timestamp values. Creation/update times describe the archive,
not the time of every event. Legacy JSON message arrays remain readable and are
converted on their next save; their undated messages stay undated. Older Hanoi
versions cannot read newly saved versioned files. Saves use temporary files with
0600 permissions and rename them
into place. New .hanoi/ directories are created with 0700. Conversations
include prompt and response content, and are local to the launch directory.
Storage location:
.hanoi/Ask naturally, for example: "Was haben wir gestern gemacht?" or "Find our earlier discussion about the CRA issue." The model can use two built-in, read-only tools:
memory_search: search user/assistant text across saved sessions in this workspace. Search is case-insensitive; all whitespace-separated query terms must appear in the same message. An empty query lists activity newest first. Filter byday(today,yesterday,day_before_yesterday, orYYYY-MM-DD), or by inclusivefrom/ exclusiveuntiltimestamps. Calendar dates use the machine's local timezone, including daylight-saving transitions. Results include session names, zero-based message indices, timestamps and short excerpts.memory_read: load original text by session and message offset, with message pagination and character-offset continuation for long messages.
Both tools return bounded JSON pages with next_offset when more results exist.
For a complete daily review, continue through every page. Undated legacy messages
are excluded from date-filtered searches and counted explicitly; unfiltered search
can still find them with time_unknown: true. Unreadable/unsupported sessions are
listed in skipped_sessions rather than silently making a review look complete.
The tools read the current .hanoi/*.json files directly, without a separate
database, embeddings, extra model calls or an MCP server. /clear and deleting a
session file therefore remove it from subsequent recall immediately. Only saved
conversations are available; CLI calls without -memory are not archived. Recall
does not inject all old sessions into each prompt, and does not search other
workspaces. Stored assistant statements describe past conversation, not proof
that a command succeeded or the current environment still matches. System prompts
and raw tool payloads are not exposed by the recall tools; historical text never
grants permission for a new action.
