# Lua configuration & scripts

Extend Harness with local configuration, named actions, and the same API available to the CLI.

Canonical page: https://thebestterminal.com/docs/lua-configuration

Harness 2.3.2 · Documentation reviewed 2026-10-13

## Where configuration runs

Harness reads Lua 5.1 configuration from ~/.config/harness/init.lua. HARNESS_CONFIG overrides the path. Lua executes in the CLI, not inside HarnessDaemon; there is no automatic file watcher.

> **Treat configuration as executable code**
>
> Lua includes io, os, and require. Only run configuration or scripts you trust. A theme file and a Lua program do not have the same security implications.

## Check before you reload

**Terminal**

```shell
harness-cli config check
harness-cli config reload
# Check another file without replacing the default path:
harness-cli config check --file /absolute/path/to/init.lua
```

check reports the file path, whether it exists, and counts for bindings, removals, modes, and actions. A syntax error exits 1. A reload with a syntax error keeps the previous keymap; it does not partially replace it. Remote config reload is deliberately refused.

## Use the API from Lua

Every JSON API method has a Lua counterpart. harness.pane.split{ direction = "horizontal" } uses the same executor as harness.call("pane.split", { direction = "horizontal" }). Calls return a result table or nil, an error message, and an exit code.

**inspect.lua**

```lua
local pane, message, status = harness.pane.view({})
if not pane then
  error(message or ("Harness call failed: " .. tostring(status)))
end
print("Connected to the current pane")
```

**Terminal**

```shell
harness-cli do /absolute/path/to/inspect.lua
```

Use api list and api describe to discover the available methods and arguments. The script’s daemon context, including --host, determines where the call runs.

## Configuration versus long-running scripts

Bindings, modes, actions, and host definitions belong in configuration. Event subscriptions and waits belong in scripts or actions: harness.on in the config file is warned about and ignored.

Scripts can run from a file, inline with do -e, or from stdin with do -. --args supplies JSON as harness.args. A script registering event handlers stays running until harness.stop or interruption.

**Inspect effective bindings and available actions**

```shell
harness-cli keymap --json
harness-cli actions --json
```

Use the release-pinned Lua section of the command reference for the full signatures of bind, unbind, mode, action, host, queue, and invoke. Check the effective keymap after changing configuration so a new binding does not unexpectedly shadow a familiar shortcut.

## Source references

- [docs/COMMANDS.md](https://github.com/robzilla1738/harness-terminal/blob/2f843e5625086fbd33e58a724c632e47bfe66d1d/docs/COMMANDS.md)

- [README.md](https://github.com/robzilla1738/harness-terminal/blob/2f843e5625086fbd33e58a724c632e47bfe66d1d/README.md)

## Related guides

- https://thebestterminal.com/docs/automation-and-api

- https://thebestterminal.com/docs/keyboard-shortcuts

- https://thebestterminal.com/docs/security-and-scrollback

