ai-gateway
Unified AI gateway for command catalog, policy firewall, and safe execution
File Information
| Property | Value |
|---|---|
| Binary Name | ai-gateway |
| Version | 9.8.4 |
| Build Date | Not disclosed |
| Rust Version | 1.82.0 |
| File Size | 9.9MB |
| Author | Warith Al Maawali |
| License | Proprietary |
| Category | Kodachi Binary |
| Description | Unified AI gateway for command catalog, policy firewall, and safe execution |
| Git Commit | unknown |
| Metadata Generated | 2026-08-10T13:23:00Z |
| Binary Timestamp | Unknown |
| JSON Data | View Raw JSON |
SHA256 Checksum
0f8743d2d325a5447902c731babe530bf6791768e200c0ac3bdc822dca729f77
Features
| # | Feature |
|---|---|
| 1 | Embedded command catalog with 571 commands from 26 services |
| 2 | TF-IDF + substring hybrid search across all services |
| 3 | Three-tier risk classification (Passive/Active/Dangerous) |
| 4 | Policy firewall with allowlist enforcement |
| 5 | Workspace confinement and path validation |
| 6 | Failure cooldown to prevent cascading degradation |
| 7 | Per-agent identity, rate limiting, and audit trail for executions |
| 8 | Approval ticket workflow for agent-to-human authorization |
| 9 | Configurable per-operation timeouts with env var override |
| 10 | Full JSON/JSON-pretty/JSON-human output support |
Security Features
| Feature | Description |
|---|---|
| Input Validation | Argument parsing via clap; per-command validation is the consumer's responsibility |
| Rate Limiting | Not provided by cli-core |
| Authentication | Not provided by cli-core (see online-auth) |
| Encryption | Not provided by cli-core |
System Requirements
| Requirement | Value |
|---|---|
| OS | Linux (Debian-based) |
| Privileges | root/sudo for system operations |
| Dependencies | OpenSSL, libcurl |
Global Options
| Flag | Description |
|---|---|
-h, --help |
Print help information |
-v, --version |
Print version information |
-n, --info |
Display detailed information |
-e, --examples |
Show usage examples |
--json |
Output in JSON format |
-o, --output-format <FORMAT> |
Force output format (text|json) |
--json-pretty |
Pretty-print JSON output with indentation |
--json-human |
Enhanced JSON output with improved formatting (like jq) |
--json-filter <FIELD1,FIELD2> |
Return only specified JSON fields (comma-separated) |
--fields <FIELD_LIST> |
Select specific fields to include in output (comma-separated) |
--offset <NUMBER> |
Skip first N results (for pagination) |
--port <PORT> |
Set custom port number (1024-65535) |
--log-level <LEVEL> |
Set log level (error|warn|info|debug) |
--verbose |
Enable verbose output |
--quiet |
Suppress non-essential output |
--no-color |
Disable colored output |
--config <FILE> |
Use custom configuration file |
Commands
Administration
index
Rebuild the search index from the embedded registry
Usage:
ai-gateway index rebuild
Options:
rebuild: Rebuild the TF-IDF search index over the command catalog and print the service and command counts. Run this after upgrading the hook binaries.
Examples:
ai-gateway index rebuild
ai-gateway index rebuild --json
ai-gateway index rebuild --json-pretty
policy
Show the current safety policy configuration
Usage:
ai-gateway policy show
Options:
show: Display the policy firewall: risk-tier rules, the service allowlist, and whether KODACHI_PENTEST_MODE is currently enabled. Read-only.
Examples:
ai-gateway policy show
ai-gateway policy show --json
ai-gateway policy show --json-pretty
doctor
Health check that verifies all registered binaries exist and respond
Usage:
ai-gateway doctor
Options:
(no command-specific options): doctor probes every registered binary and reports whether it exists, responds, and at which version. Use the global --json, --json-pretty or --json-human to pick the output shape.
Examples:
ai-gateway doctor
ai-gateway doctor --json
ai-gateway doctor --json-pretty
approve
Issue or verify human approval tickets for agent execution
Usage:
ai-gateway approve issue <service> <command> [--agent-id <id>] [--ttl <secs>]
ai-gateway approve verify --ticket <ticket> <service> <command> [--agent-id <id>]
Options:
issue <SERVICE> <COMMAND>: Issue a signed, time-limited approval ticket for one service and command (requires KODACHI_GATEWAY_APPROVAL_SECRET)verify --ticket <TICKET> <SERVICE> <COMMAND>: Verify a ticket against the service and command it was issued for--agent-id <ID>: Agent identity the ticket is bound to--ttl <SECS>: Ticket lifetime in seconds, 1 to 3600 (issue only)
Examples:
ai-gateway approve issue health-control block-internet --agent-id nullclaw --ttl 600 --json
ai-gateway approve verify --ticket "$TICKET" health-control block-internet --agent-id nullclaw --json
Discovery
list
List all services and their commands from the embedded registry
Usage:
ai-gateway list [--service <name>] [--category <name>]
Options:
--service: Filter by service name--category: Filter by category name
Examples:
ai-gateway list
ai-gateway list --json
ai-gateway list --service tor-switch
ai-gateway list --service health-control --json
ai-gateway list --category passive
search
Search across all services and commands using TF-IDF + substring matching
Usage:
ai-gateway search <query> [--limit <N>]
Options:
--limit: Maximum number of results to return
Examples:
ai-gateway search "tor status"
ai-gateway search "dns leak" --json
ai-gateway search "network check" --limit 5
ai-gateway search "panic" --json-pretty
help
Show detailed help for a service or specific command
Usage:
ai-gateway help <service> [command]
Options:
<SERVICE>: Service name from the embedded catalog, for example tor-switch. An --agent-id value such as nullclaw is not a service and returns "Service not found".[COMMAND]: Optional command name. Omit it for the whole service spec.
Examples:
ai-gateway help tor-switch
ai-gateway help tor-switch tor-status --json
ai-gateway help health-control --json-pretty
ai-gateway help dns-leak test
ai-gateway help ip-fetch fetch --json
capabilities
Show effective capabilities for an AI agent identity
Usage:
ai-gateway capabilities [--agent-id <id>] [--agent-token <token>]
Options:
--agent-id: Agent profile (nullclaw/agentzero/openclaw/picoclaw/nanoclaw/claude-code/gpt/gemini/open-interpreter; aliases: nanclaw, "claude code", "open interpreter")--agent-token: Optional token for authenticated agent profiles
Examples:
ai-gateway capabilities --agent-id nullclaw --agent-token $KODACHI_AGENT_TOKEN_NULLCLAW --json
ai-gateway capabilities --agent-id nullclaw --agent-token $KODACHI_AGENT_TOKEN_NULLCLAW
ai-gateway capabilities --agent-id openclaw --agent-token $KODACHI_AGENT_TOKEN_OPENCLAW --json
ai-gateway capabilities --agent-id picoclaw --agent-token $KODACHI_AGENT_TOKEN_PICOCLAW --json
ai-gateway capabilities --agent-id nanoclaw --agent-token $KODACHI_AGENT_TOKEN_NANOCLAW --json
ai-gateway capabilities --agent-id nanclaw --agent-token $KODACHI_AGENT_TOKEN_NANOCLAW --json
ai-gateway capabilities --agent-id claude-code --agent-token $KODACHI_AGENT_TOKEN_CLAUDE_CODE --json
ai-gateway capabilities --agent-id "claude code" --agent-token $KODACHI_AGENT_TOKEN_CLAUDE_CODE --json
ai-gateway capabilities --agent-id gpt --agent-token $KODACHI_AGENT_TOKEN_GPT --json
ai-gateway capabilities --agent-id gemini --agent-token $KODACHI_AGENT_TOKEN_GEMINI --json
ai-gateway capabilities --agent-id open-interpreter --agent-token $KODACHI_AGENT_TOKEN_OPEN_INTERPRETER --json
ai-gateway capabilities --agent-id "open interpreter" --agent-token $KODACHI_AGENT_TOKEN_OPEN_INTERPRETER --json
ai-gateway capabilities --agent-id anonymous --json
Execution
run
Validate and execute a binary command through the safety layer
Usage:
ai-gateway run <service> --command <cmd> [--args <args>...] [--args-json <json>] [--dry-run] [--timeout <secs>] [--agent-id <id>] [--agent-token <token>] [--approval-ticket <ticket>] OR ai-gateway run --batch-json <json> --agent-id <id> --agent-token <token>
Options:
<SERVICE>: Service to invoke (required unless --batch-json is used)--command <CMD>: Command to execute (required unless --batch-json is used)--args: Command arguments (multiple)--args-json: Command arguments as JSON object/array--batch-json: Batch execution payload for trusted agents (JSON array, sequential mode only)--dry-run: Validate without executing--timeout: Execution timeout in seconds--confirm: Approval token for commands requiring confirmation--approval-ticket: Human-issued approval ticket for Active/Dangerous commands--agent-id: Agent profile (trusted profiles require token auth)--agent-token: Agent auth token for token-required profiles
Examples:
ai-gateway run health-control --command net-check --dry-run
ai-gateway run ip-fetch --command fetch --dry-run --json
ai-gateway run tor-switch --command tor-status --timeout 60 --json
ai-gateway run tor-switch --command set-exit-node --args-json '["de"]' --dry-run --json
ai-gateway run dns-leak --command test --dry-run --json-pretty
ai-gateway run tor-switch --command tor-status --agent-id claude-code --agent-token "$KODACHI_AGENT_TOKEN_CLAUDE_CODE" --dry-run --json
KODACHI_TRUSTED_BATCH_MODE=true ai-gateway run --agent-id nullclaw --agent-token "$KODACHI_AGENT_TOKEN_NULLCLAW" --batch-json '[{"service":"ip-fetch","command":"fetch","dry_run":true},{"service":"tor-switch","command":"tor-status","dry_run":true}]' --json
KODACHI_PENTEST_MODE=true ai-gateway run health-control --command wipe-file --args-json '{"file":"results/example-to-wipe.txt"}' --confirm "I understand" --dry-run --json
Operational Scenarios
Scenario-oriented workflows generated from the binary's built-in -e --json examples.
Scenario 1: Quick Start
The gateway is the one safe door into every other Kodachi binary: find a command, read its spec, preview it, then run it. ai-gateway itself never needs root, but the service it launches may.
Step 1: Find the command you want without knowing which service owns it
ai-gateway search "tor exit node" --limit 5 --json
Step 2: Read the full spec of a command before you invoke it
ai-gateway help tor-switch tor-status --json
Step 3: Preview the invocation: policy check, no execution
ai-gateway run tor-switch --command tor-status --dry-run --json
Step 4: Run it for real once the dry-run looks right
ai-gateway run tor-switch --command tor-status --json
Note
Passive commands need no confirmation and no env var. Active commands need --confirm, and Dangerous commands additionally need KODACHI_PENTEST_MODE=true.
Scenario 2: Service Discovery
Browse the embedded catalog of every Kodachi service and command. The catalog is compiled into the binary, so list works offline and without authentication.
Step 1: List every service in the catalog with its commands
ai-gateway list --json
Step 2: Narrow the catalog to one service
ai-gateway list --service tor-switch --json
Step 3: Filter by command category instead of by service
ai-gateway list --category Discovery
Note
--category (-c) matches the category name a service assigns to its own commands, so the useful values differ per service. Run 'ai-gateway list --service <name>' first to see which categories that service uses.
Step 4: Same listing in readable text instead of JSON
ai-gateway list --service health-control
Scenario 3: Command Search
Search across all services using TF-IDF + substring hybrid search engine
Step 1: Search for Tor exit node commands
ai-gateway search "tor exit node" --json
Note
Uses TF-IDF cosine similarity + substring matching
Step 2: Search with limited results
ai-gateway search "dns leak" --limit 5 --json
Step 3: Search for network check commands in text format
ai-gateway search "network check"
Step 4: Find all panic/emergency commands
ai-gateway search "panic" --json
Note
Dangerous commands are blocked unless pentest mode
Scenario 4: Service Help
Get detailed help for any service or specific command
Step 1: Full specification for tor-switch service
ai-gateway help tor-switch --json
Step 2: Help for a specific command
ai-gateway help health-control security-status --json
Step 3: Text help for dns-switch service
ai-gateway help dns-switch
Step 4: Pretty-printed JSON help for ip-fetch
ai-gateway help ip-fetch --json-pretty
Scenario 5: Safe Command Execution
Validate first, then execute when appropriate. No env var is needed for passive/active commands.
Step 1: Step 1 (validate): preview a passive command
ai-gateway run tor-switch --command tor-status --dry-run --json
Note
Always use --dry-run first for safety
Step 2: Step 2 (apply): execute passive command (no env needed)
ai-gateway run tor-switch --command tor-status --json
Note
Passive commands execute without KODACHI_PENTEST_MODE
Step 3: Active command flow (no env needed): validate with explicit confirmation
ai-gateway run tor-switch --command set-exit-node --args-json '["de"]' --confirm --dry-run --json
Note
For active commands, remove --dry-run to apply changes
Step 4: Dry-run DNS leak test with custom timeout
ai-gateway run dns-leak --command test --dry-run --timeout 60 --json
Note
Timeout can be overridden with KODACHI_TOOL_TIMEOUT_MS env var
Step 5: Dry-run ip-fetch fetch command
ai-gateway run ip-fetch --command fetch --dry-run --json
Note
Dry-run keeps examples deterministic in offline/auth-restricted environments
Step 6: Pass structured JSON arguments for agent-safe invocation
ai-gateway run tor-switch --command set-exit-node --args-json '["de"]' --dry-run --json
Note
--args-json avoids brittle shell quoting in agent pipelines
Step 7: Pass plain positional arguments straight through to the service
ai-gateway run tor-switch --command set-exit-node --args de --dry-run --json
Note
--args (-a) takes any number of values and forwards them verbatim, so everything after it is consumed as an argument until the next flag. Use --args-json instead when the values could be mistaken for gateway flags.
Step 8: Run under an agent identity so the call is rate-limited and audited
ai-gateway run health-control --command net-check --agent-id claude-code --agent-token "$KODACHI_AGENT_TOKEN_CLAUDE_CODE" --dry-run --json
Note
The token is read server-side from the env var KODACHI_AGENT_TOKEN_<AGENT_ID>, uppercased with '-' replaced by '_'. It must be EXPORTED: if it is unset, the shell expands it to nothing and clap fails with "a value is required".
Scenario 6: Safety Policy
Read the policy firewall: which services are allowlisted, how commands are classified into the Passive, Active and Dangerous risk tiers, and what each tier demands before it will run.
Step 1: Show the active safety policy as JSON
ai-gateway policy show --json
Step 2: Show the same policy as readable text
ai-gateway policy show
Step 3: Indented policy JSON, easier to read while debugging a block
ai-gateway policy show --json-pretty
Note
If a run was refused, this is the command that tells you why: check the command's tier and whether its service is on the allowlist.
Step 4: Preview a Dangerous command: it needs the env var AND an explicit confirmation token
KODACHI_PENTEST_MODE=true ai-gateway run health-control --command wipe-file --args-json '{"file":"results/example-to-wipe.txt"}' --confirm "I understand" --dry-run --json
Note
KEEP --dry-run. The example target is only illustrative. Without dry-run this really does wipe the target file, and wipe-file is irreversible. KODACHI_PENTEST_MODE=true is required only for the Dangerous tier, and --confirm must be exactly "I understand" or dangerous:<service>:<command>.
Scenario 7: Administration and Troubleshooting
Keep the search index fresh and find out why a service will not run. These are the commands to reach for when a run fails and you do not know whether the fault is policy, the index, or a missing binary.
Step 1: Rebuild the TF-IDF search index over the command catalog
ai-gateway index rebuild --json
Note
Do this after upgrading the hook binaries, otherwise search still ranks against the previous catalog.
Step 2: Probe every registered binary and report whether it is usable
ai-gateway doctor --json
Note
This is what to run when a run failed with "Binary not found": doctor shows exactly which entries have no binary behind them.
Step 3: Same health check as a readable table
ai-gateway doctor
Note
doctor executes each binary with a probe flag, so it is slower than the other commands here.
Scenario 8: Output Formats and Metadata
Every command accepts the same three JSON shapes, plus the binary's own metadata flags. Pick compact JSON for scripts, pretty for reading, and human when you want it formatted like jq.
Step 1: Compact JSON: one line, best for piping into a script
ai-gateway doctor --json
Step 2: Indented JSON for reading a result by eye
ai-gateway search "dns leak" --json-pretty
Step 3: Formatted, jq-style JSON
ai-gateway policy show --json-human
Step 4: Report what this build of the gateway can do
ai-gateway --info --json
Step 5: Print the gateway version
ai-gateway --version
Scenario 9: AI Agent Integration
The loop an AI agent runs: search for the command, read its spec, dry-run it, then execute under an agent identity. IMPORTANT: an agent name (nullclaw, agentzero, openclaw, picoclaw, nanoclaw, claude-code, gpt, gemini, open-interpreter) is a value for --agent-id, NOT a service you can 'run'. The service argument of 'run' must be a Kodachi binary from the catalog, such as tor-switch or ip-fetch. Use 'ai-gateway list' to see what is runnable.
Step 1: Step 1: the agent finds the best matching command
ai-gateway search "check tor status" --limit 1 --json
Note
ai-cmd delegates its execution to ai-gateway, so an agent that goes through the gateway gets the same safety checks either way.
Step 2: Step 2: the agent reads the machine-readable command spec
ai-gateway help tor-switch tor-status --json
Note
'help' resolves the name against the embedded service catalog. An --agent-id value such as nullclaw is not a service, so 'help nullclaw' returns "Service not found".
Step 3: Step 3: the agent validates the invocation before committing to it
ai-gateway run tor-switch --command tor-status --dry-run --json
Step 4: Step 4: the agent executes under its own identity, so the call is rate-limited and audited
ai-gateway run tor-switch --command tor-status --agent-id claude-code --agent-token "$KODACHI_AGENT_TOKEN_CLAUDE_CODE" --json
Note
Every named profile except 'anonymous' requires a token. Export KODACHI_AGENT_TOKEN_CLAUDE_CODE first: if it is unset the shell drops the word and clap fails with "a value is required".
Step 5: Ask the gateway what a given agent identity is actually allowed to do
ai-gateway capabilities --agent-id nullclaw --agent-token "$KODACHI_AGENT_TOKEN_NULLCLAW" --json
Note
This is the correct way to work with an agent name. 'run nullclaw' is not: nullclaw is an identity, and it is only a runnable service if you have separately installed a third-party binary of that name (see the External agent runtimes category).
Scenario 10: External Agent Runtimes
Kodachi does not ship any agent runtime binary. The policy allowlist reserves two optional third-party names (nullclaw, aeroclaw) and the registry discovers them at runtime, but only if you have installed a binary of that name into the hooks directory yourself. On a stock install none of them exists, so running one fails with "Binary not found". Everything below assumes you installed it.
Step 1: Check whether an external agent runtime is actually installed
ai-gateway doctor --json
Note
Do this before you write a script against nullclaw or aeroclaw. They are optional and are not part of a stock Kodachi install.
Step 2: Confirm which service names the policy firewall will even accept
ai-gateway policy show --json
Note
Being on the allowlist only means the policy will not refuse the name. The binary still has to exist on disk. Names such as agentzero, openclaw, picoclaw and nanoclaw are NOT on the allowlist: they exist only as --agent-id identities.
Step 3: List what an installed external runtime exposes
ai-gateway list --service nullclaw --json
Note
The registry discovers an external runtime by executing it with a probe flag under a 5 second timeout, so its command list comes from the binary itself, not from the compiled catalog.
Scenario 11: Agent Identity, Tokens and Approval Tickets
Every execution can carry an agent identity, which decides the highest risk tier it may reach, its rate limit, and what lands in the audit trail. Valid --agent-id values: anonymous, nullclaw, agentzero, openclaw, picoclaw, nanoclaw, claude-code, gpt, gemini, open-interpreter. TOKENS: every profile except anonymous requires one. The gateway reads it server-side from the env var KODACHI_AGENT_TOKEN_<AGENT_ID>, uppercased with '-' turned into '_', and that variable must be EXPORTED before you run these commands. If it is unset, the shell expands $KODACHI_AGENT_TOKEN_... to nothing, the word disappears from the command line, and clap fails with "a value is required".
Step 1: Set the token for an agent identity, once per shell
export KODACHI_AGENT_TOKEN_CLAUDE_CODE="<your-token>"
Note
The env var name is derived from the agent id: nullclaw becomes KODACHI_AGENT_TOKEN_NULLCLAW, open-interpreter becomes KODACHI_AGENT_TOKEN_OPEN_INTERPRETER.
Step 2: Ask what a trusted agent identity is allowed to do
ai-gateway capabilities --agent-id nullclaw --agent-token "$KODACHI_AGENT_TOKEN_NULLCLAW" --json
Step 3: Show the default capabilities of an unidentified caller
ai-gateway capabilities --agent-id anonymous --json
Note
anonymous is the only profile that needs no token, and it is the default when you omit --agent-id.
Step 4: A human issues a time-limited ticket authorizing one agent to run one command
ai-gateway approve issue health-control block-internet --agent-id nullclaw --ttl 600 --json
Note
Requires KODACHI_GATEWAY_APPROVAL_SECRET to be exported. --ttl is in seconds and must be 1 to 3600 (default 300). The ticket is bound to that exact service, command and agent id.
Step 5: Check a ticket is genuine and still valid before relying on it
ai-gateway approve verify --ticket "$TICKET" health-control block-internet --agent-id nullclaw --json
Note
The service and command are positional and must match the ones the ticket was issued for, or verification fails.
Step 6: The agent presents its identity and its ticket to run a gated command
ai-gateway run health-control --command block-internet --agent-id nullclaw --agent-token "$KODACHI_AGENT_TOKEN_NULLCLAW" --approval-ticket "$TICKET" --dry-run --json
Note
block-internet cuts all network access on this machine. Drop --dry-run only when you mean it. Without a valid ticket the gateway refuses and returns requires_approval.
Step 7: Run several invocations in one call, sequentially, as a trusted agent
KODACHI_TRUSTED_BATCH_MODE=true ai-gateway run --agent-id nullclaw --agent-token "$KODACHI_AGENT_TOKEN_NULLCLAW" --batch-json '[{"service":"ip-fetch","command":"fetch","dry_run":true},{"service":"tor-switch","command":"tor-status","dry_run":true}]' --json
Note
Batch mode needs three things at once: KODACHI_TRUSTED_BATCH_MODE=true, an authenticated agent, and a profile that requires a token. anonymous can never batch. When --batch-json is used, the service argument and --command are supplied inside the JSON instead of on the command line. Each entry may set its own dry_run.
Environment Variables
| Variable | Description | Default | Values |
|---|---|---|---|
NO_COLOR |
Disable all colored output when set | unset | 1|true|yes (any value disables color) |
Exit Codes
| Code | Description |
|---|---|
| 5 | File not found |
| 4 | Network error |
| 0 | Success |
| 1 | General error |
| 2 | Invalid arguments |
| 3 | Permission denied |