Integrating Custom Agents
hcom supports any AI tool that can run shell commands. Beyond Claude Code, Gemini CLI, Codex, and OpenCode, you can integrate custom tools using manual mode or by implementing hooks.Manual Mode (Ad-Hoc)
The simplest integration: no hooks required. Agent polls for messages manually.Setup
Inside any AI tool session:[hcom:luna] marker is used for vanilla binding (tool-specific).
Send Messages
Receive Messages
Agent must poll manually:External Processes
For non-interactive scripts, send messages with--from flag:
Agent Identity
All hcom commands require identity context. There are 4 ways to provide it:1. Process Binding (PTY Mode)
Best: Automatic identity via process tracking.hcom claude/gemini/codex/opencode work.
2. Session Binding (Vanilla Mode)
Good: Bind session afterhcom start.
3. Name Flag (Explicit)
Manual: Pass--name to every command.
4. External Sender (Fire and Forget)
Simple: Use--from for one-off messages.
Implementing Custom Hooks
For automatic message delivery, implement hooks that call hcom commands.Hook Requirements
- Start hook: Bind session on startup
- Turn completion hook: Update status to listening
- Message delivery: Inject messages when idle
Example: Bash-Based Tool
Suppose your tool runs bash commands and has a plugin system: 1. Start Hook:Example: Python-Based Tool
Suppose your tool has a Python plugin API:Hook Implementation Guide
Required Hooks
- session_start: Bind identity
- turn_complete: Signal idle
- idle_poll: Deliver messages
Optional Hooks
- status_change: Track tool execution
- session_end: Cleanup
Hook Data Flow
Using hcom Commands
Start Session
--as <name>: Reclaim identity after disconnect--orphan <name>: Recover orphaned PTY process
Update Status
active: Processinglistening: Idle, ready for messagesblocked: Needs approvalinactive: Dead/stopped
Read Messages
Stop Session
PTY Wrapper Integration
For instant message delivery without polling, use hcom’s PTY wrapper.How PTY Mode Works
- Launch:
hcom <tool>spawns PTY wrapper - Wrap: PTY wrapper spawns actual tool as subprocess
- Monitor: Wrapper monitors terminal I/O
- Inject: When messages arrive, wrapper injects text
- Tool sees: Tool sees injected text as if user typed it
Custom PTY Wrapper
If you want PTY mode for your custom tool:- Add tool to launcher registry
- Implement
launch_mytool()function - Use PTY wrapper:
pty_mode::launch_pty_wrapped() - Tool hooks call
hcom opencode-status
Reference
Identity Resolution Priority
HCOM_PROCESS_IDenv var (PTY mode)- Session binding (after
hcom start) --nameflag (explicit)--fromflag (external sender)
Commands for Custom Integration
| Command | Purpose | Required Args |
|---|---|---|
hcom start | Bind identity | None (uses env) |
hcom send | Send message | @target -- text |
hcom listen | Block for message | None |
hcom events | Query events | Filters optional |
hcom list | Check status | None |
hcom opencode-status | Update status | --name, --status |
hcom opencode-read | Fetch messages | --name |
hcom opencode-stop | Disconnect | --name |
Message Delivery Comparison
| Integration | Delivery Method | Latency | Complexity |
|---|---|---|---|
| Claude (PTY) | Hook + PTY injection | Less than 100ms | High |
| Gemini (PTY) | Hook + PTY injection | Less than 100ms | High |
| Codex (PTY) | Hook + PTY injection | Less than 100ms | High |
| OpenCode | Plugin + TCP notify | Less than 200ms | Medium |
| Custom (hooks) | Hook + polling | ~1s | Medium |
| Ad-hoc | Manual listen | Variable | Low |
Examples
Webhook Integration
Receive webhook, send message:Cron Job Integration
Scheduled task sends message:LLM API Integration
Wrap API calls with hcom:Subprocess Agent
Long-running subprocess that participates:Tips
Performance
- Use
--checkbefore--formatto avoid unnecessary work - Acknowledge messages promptly to avoid re-delivery
- Use TCP notify for sub-second latency
Reliability
- Always check exit codes
- Handle
hcom startfailures gracefully - Store identity for reconnection
- Use
--asto reclaim identity after disconnect
Security
- Validate message sources before executing commands
- Use intents to distinguish requests from info
- Implement approval logic for dangerous operations
Troubleshooting
”No instance bound to this process”
Identity not set. Solutions:- Run
hcom startfirst - Export
HCOM_PROCESS_IDbefore commands - Use
--nameflag explicitly