feat: codex app-server integration, token sync fix, typing fix
- Rewrite codex-runner to use `codex app-server` JSON-RPC instead of `codex exec`. Supports streaming (item/agentMessage/delta), session persistence (thread/start, thread/resume), and mid-turn message injection (turn/steer with IPC polling during execution). - Fix token refresh not syncing to per-group session directories, causing 401 errors on running agents. - Fix typing indicator staying on when codex returns null result by always clearing typing on any streaming callback. - Update README and CLAUDE.md to reflect dual-service architecture, host process mode, and codex app-server integration.
This commit is contained in:
269
README.md
269
README.md
@@ -3,211 +3,148 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
An AI assistant that runs agents securely in their own containers. Lightweight, built to be easily understood and completely customized for your needs.
|
||||
Dual-agent AI assistant running Claude Code + Codex as parallel services over Discord.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://nanoclaw.dev">nanoclaw.dev</a> •
|
||||
<a href="README_zh.md">中文</a> •
|
||||
<a href="https://discord.gg/VDdww8qS42"><img src="https://img.shields.io/discord/1470188214710046894?label=Discord&logo=discord&v=2" alt="Discord" valign="middle"></a> •
|
||||
<a href="repo-tokens"><img src="repo-tokens/badge.svg" alt="34.9k tokens, 17% of context window" valign="middle"></a>
|
||||
Fork of <a href="https://github.com/qwibitai/nanoclaw">qwibitai/nanoclaw</a>
|
||||
</p>
|
||||
Using Claude Code, NanoClaw can dynamically rewrite its code to customize its feature set for your needs.
|
||||
|
||||
**New:** First AI assistant to support [Agent Swarms](https://code.claude.com/docs/en/agent-teams). Spin up teams of agents that collaborate in your chat.
|
||||
## Overview
|
||||
|
||||
## Why I Built NanoClaw
|
||||
This fork runs two independent NanoClaw instances as systemd services:
|
||||
|
||||
[OpenClaw](https://github.com/openclaw/openclaw) is an impressive project, but I wouldn't have been able to sleep if I had given complex software I didn't understand full access to my life. OpenClaw has nearly half a million lines of code, 53 config files, and 70+ dependencies. Its security is at the application level (allowlists, pairing codes) rather than true OS-level isolation. Everything runs in one Node process with shared memory.
|
||||
- **nanoclaw** (Claude Code) — powered by Claude Agent SDK, trigger `@claude`
|
||||
- **nanoclaw-codex** (Codex) — powered by Codex app-server JSON-RPC, trigger `@codex`
|
||||
|
||||
NanoClaw provides that same core functionality, but in a codebase small enough to understand: one process and a handful of files. Claude agents run in their own Linux containers with filesystem isolation, not merely behind permission checks.
|
||||
Each service has its own store, data, and groups directories. Discord channels can be registered with either or both bots.
|
||||
|
||||
## Quick Start
|
||||
## Key Differences from Upstream
|
||||
|
||||
```bash
|
||||
gh repo fork qwibitai/nanoclaw --clone
|
||||
cd nanoclaw
|
||||
claude
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Without GitHub CLI</summary>
|
||||
|
||||
1. Fork [qwibitai/nanoclaw](https://github.com/qwibitai/nanoclaw) on GitHub (click the Fork button)
|
||||
2. `git clone https://github.com/<your-username>/nanoclaw.git`
|
||||
3. `cd nanoclaw`
|
||||
4. `claude`
|
||||
|
||||
</details>
|
||||
|
||||
Then run `/setup`. Claude Code handles everything: dependencies, authentication, container setup and service configuration.
|
||||
|
||||
> **Note:** Commands prefixed with `/` (like `/setup`, `/add-whatsapp`) are [Claude Code skills](https://code.claude.com/docs/en/skills). Type them inside the `claude` CLI prompt, not in your regular terminal. If you don't have Claude Code installed, get it at [claude.com/product/claude-code](https://claude.com/product/claude-code).
|
||||
|
||||
## Philosophy
|
||||
|
||||
**Small enough to understand.** One process, a few source files and no microservices. If you want to understand the full NanoClaw codebase, just ask Claude Code to walk you through it.
|
||||
|
||||
**Secure by isolation.** Agents run in Linux containers (Apple Container on macOS, or Docker) and they can only see what's explicitly mounted. Bash access is safe because commands run inside the container, not on your host.
|
||||
|
||||
**Built for the individual user.** NanoClaw isn't a monolithic framework; it's software that fits each user's exact needs. Instead of becoming bloatware, NanoClaw is designed to be bespoke. You make your own fork and have Claude Code modify it to match your needs.
|
||||
|
||||
**Customization = code changes.** No configuration sprawl. Want different behavior? Modify the code. The codebase is small enough that it's safe to make changes.
|
||||
|
||||
**AI-native.**
|
||||
- No installation wizard; Claude Code guides setup.
|
||||
- No monitoring dashboard; ask Claude what's happening.
|
||||
- No debugging tools; describe the problem and Claude fixes it.
|
||||
|
||||
**Skills over features.** Instead of adding features (e.g. support for Telegram) to the codebase, contributors submit [claude code skills](https://code.claude.com/docs/en/skills) like `/add-telegram` that transform your fork. You end up with clean code that does exactly what you need.
|
||||
|
||||
**Best harness, best model.** NanoClaw runs on the Claude Agent SDK, which means you're running Claude Code directly. Claude Code is highly capable and its coding and problem-solving capabilities allow it to modify and expand NanoClaw and tailor it to each user.
|
||||
|
||||
## What It Supports
|
||||
|
||||
- **Multi-channel messaging** - Talk to your assistant from WhatsApp, Telegram, Discord, Slack, or Gmail. Add channels with skills like `/add-whatsapp` or `/add-telegram`. Run one or many at the same time.
|
||||
- **Isolated group context** - Each group has its own `CLAUDE.md` memory, isolated filesystem, and runs in its own container sandbox with only that filesystem mounted to it.
|
||||
- **Main channel** - Your private channel (self-chat) for admin control; every group is completely isolated
|
||||
- **Scheduled tasks** - Recurring jobs that run Claude and can message you back
|
||||
- **Web access** - Search and fetch content from the Web
|
||||
- **Container isolation** - Agents are sandboxed in Apple Container (macOS) or Docker (macOS/Linux)
|
||||
- **Agent Swarms** - Spin up teams of specialized agents that collaborate on complex tasks. NanoClaw is the first personal AI assistant to support agent swarms.
|
||||
- **Optional integrations** - Add Gmail (`/add-gmail`) and more via skills
|
||||
|
||||
## Usage
|
||||
|
||||
Talk to your assistant with the trigger word (default: `@Andy`):
|
||||
|
||||
```
|
||||
@Andy send an overview of the sales pipeline every weekday morning at 9am (has access to my Obsidian vault folder)
|
||||
@Andy review the git history for the past week each Friday and update the README if there's drift
|
||||
@Andy every Monday at 8am, compile news on AI developments from Hacker News and TechCrunch and message me a briefing
|
||||
```
|
||||
|
||||
From the main channel (your self-chat), you can manage groups and tasks:
|
||||
```
|
||||
@Andy list all scheduled tasks across groups
|
||||
@Andy pause the Monday briefing task
|
||||
@Andy join the Family Chat group
|
||||
```
|
||||
|
||||
## Customizing
|
||||
|
||||
NanoClaw doesn't use configuration files. To make changes, just tell Claude Code what you want:
|
||||
|
||||
- "Change the trigger word to @Bob"
|
||||
- "Remember in the future to make responses shorter and more direct"
|
||||
- "Add a custom greeting when I say good morning"
|
||||
- "Store conversation summaries weekly"
|
||||
|
||||
Or run `/customize` for guided changes.
|
||||
|
||||
The codebase is small enough that Claude can safely modify it.
|
||||
|
||||
## Contributing
|
||||
|
||||
**Don't add features. Add skills.**
|
||||
|
||||
If you want to add Telegram support, don't create a PR that adds Telegram to the core codebase. Instead, fork NanoClaw, make the code changes on a branch, and open a PR. We'll create a `skill/telegram` branch from your PR that other users can merge into their fork.
|
||||
|
||||
Users then run `/add-telegram` on their fork and get clean code that does exactly what they need, not a bloated system trying to support every use case.
|
||||
|
||||
### RFS (Request for Skills)
|
||||
|
||||
Skills we'd like to see:
|
||||
|
||||
**Communication Channels**
|
||||
- `/add-signal` - Add Signal as a channel
|
||||
|
||||
**Session Management**
|
||||
- `/clear` - Add a `/clear` command that compacts the conversation (summarizes context while preserving critical information in the same session). Requires figuring out how to trigger compaction programmatically via the Claude Agent SDK.
|
||||
|
||||
## Requirements
|
||||
|
||||
- macOS or Linux
|
||||
- Node.js 20+
|
||||
- [Claude Code](https://claude.ai/download)
|
||||
- [Apple Container](https://github.com/apple/container) (macOS) or [Docker](https://docker.com/products/docker-desktop) (macOS/Linux)
|
||||
| Area | Upstream NanoClaw | This Fork |
|
||||
|------|-------------------|-----------|
|
||||
| Agent runtime | Container-isolated (Docker/Apple Container) | Direct host processes (no containers) |
|
||||
| Agent backends | Claude Code only | Claude Code + OpenAI Codex |
|
||||
| Codex integration | N/A | `codex app-server` (JSON-RPC, streaming, `turn/steer`) |
|
||||
| Session management | Container-based | Per-group `CLAUDE_CONFIG_DIR` / `CODEX_HOME` |
|
||||
| Token management | Manual | Auto-refresh with session sync |
|
||||
| Channel | Multi-channel (WhatsApp, Telegram, etc.) | Discord-focused |
|
||||
| Deployment | Single service | Dual systemd services |
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
Channels --> SQLite --> Polling loop --> Container (Claude Agent SDK) --> Response
|
||||
Discord ──► SQLite ──► Polling Loop ──┬──► Claude Agent SDK (host process)
|
||||
└──► Codex App-Server (JSON-RPC stdio)
|
||||
├── thread/start, thread/resume
|
||||
├── turn/start (streaming)
|
||||
├── turn/steer (mid-turn injection)
|
||||
└── Auto-approval (bypass sandbox)
|
||||
```
|
||||
|
||||
Single Node.js process. Channels are added via skills and self-register at startup — the orchestrator connects whichever ones have credentials present. Agents execute in isolated Linux containers with filesystem isolation. Only mounted directories are accessible. Per-group message queue with concurrency control. IPC via filesystem.
|
||||
### Directory Layout
|
||||
|
||||
For the full architecture details, see [docs/SPEC.md](docs/SPEC.md).
|
||||
```
|
||||
nanoclaw/
|
||||
├── src/ # Core source
|
||||
│ ├── index.ts # Orchestrator: state, message loop, agent invocation
|
||||
│ ├── container-runner.ts # Spawns agent processes, manages env/sessions
|
||||
│ ├── token-refresh.ts # OAuth auto-refresh + session directory sync
|
||||
│ ├── channels/discord.ts # Discord channel implementation
|
||||
│ ├── db.ts # SQLite operations
|
||||
│ ├── ipc.ts # IPC watcher and task processing
|
||||
│ ├── task-scheduler.ts # Scheduled tasks (cron/interval/once)
|
||||
│ └── config.ts # Paths, intervals, trigger patterns
|
||||
├── container/
|
||||
│ ├── agent-runner/ # Claude Code runner (Agent SDK)
|
||||
│ ├── codex-runner/ # Codex runner (app-server JSON-RPC)
|
||||
│ └── skills/ # Shared agent skills (browser, etc.)
|
||||
├── store/ # Claude Code service DB
|
||||
├── store-codex/ # Codex service DB
|
||||
├── data/sessions/ # Per-group Claude sessions (.claude/)
|
||||
├── data-codex/sessions/ # Per-group Codex sessions (.codex/)
|
||||
├── groups/ # Per-group memory (Claude Code)
|
||||
├── groups-codex/ # Per-group memory (Codex)
|
||||
└── logs/ # Service logs
|
||||
```
|
||||
|
||||
Key files:
|
||||
- `src/index.ts` - Orchestrator: state, message loop, agent invocation
|
||||
- `src/channels/registry.ts` - Channel registry (self-registration at startup)
|
||||
- `src/ipc.ts` - IPC watcher and task processing
|
||||
- `src/router.ts` - Message formatting and outbound routing
|
||||
- `src/group-queue.ts` - Per-group queue with global concurrency limit
|
||||
- `src/container-runner.ts` - Spawns streaming agent containers
|
||||
- `src/task-scheduler.ts` - Runs scheduled tasks
|
||||
- `src/db.ts` - SQLite operations (messages, groups, sessions, state)
|
||||
- `groups/*/CLAUDE.md` - Per-group memory
|
||||
### Codex App-Server Integration
|
||||
|
||||
## FAQ
|
||||
The Codex runner (`container/codex-runner/`) communicates with `codex app-server` via JSON-RPC over stdio:
|
||||
|
||||
**Why Docker?**
|
||||
- **Session persistence**: Thread IDs stored in DB, sessions saved as JSONL on disk
|
||||
- **Streaming**: `item/agentMessage/delta` notifications for real-time text
|
||||
- **Mid-turn steering**: IPC messages injected via `turn/steer` during execution
|
||||
- **Auto-approval**: `approvalPolicy: "never"` + `sandbox: "danger-full-access"`
|
||||
- **Per-group config**: Model, effort, MCP servers configured per channel
|
||||
|
||||
Docker provides cross-platform support (macOS, Linux and even Windows via WSL2) and a mature ecosystem. On macOS, you can optionally switch to Apple Container via `/convert-to-apple-container` for a lighter-weight native runtime.
|
||||
### OAuth Token Auto-Refresh
|
||||
|
||||
**Can I run this on Linux?**
|
||||
`src/token-refresh.ts` handles Claude Code OAuth token lifecycle:
|
||||
|
||||
Yes. Docker is the default runtime and works on both macOS and Linux. Just run `/setup`.
|
||||
- Checks every 5 minutes, refreshes 30 minutes before expiry
|
||||
- Tries `platform.claude.com` then falls back to `api.anthropic.com`
|
||||
- Syncs refreshed credentials to all per-group session directories
|
||||
- Solves the known headless environment token expiry issue
|
||||
|
||||
**Is this secure?**
|
||||
## Setup
|
||||
|
||||
Agents run in containers, not behind application-level permission checks. They can only access explicitly mounted directories. You should still review what you're running, but the codebase is small enough that you actually can. See [docs/SECURITY.md](docs/SECURITY.md) for the full security model.
|
||||
### Prerequisites
|
||||
|
||||
**Why no configuration files?**
|
||||
- Linux (Ubuntu 22.04+) or macOS
|
||||
- Node.js 20+
|
||||
- [Claude Code CLI](https://claude.ai/download)
|
||||
- [Codex CLI](https://github.com/openai/codex) (`npm install -g @openai/codex`)
|
||||
|
||||
We don't want configuration sprawl. Every user should customize NanoClaw so that the code does exactly what they want, rather than configuring a generic system. If you prefer having config files, you can tell Claude to add them.
|
||||
|
||||
**Can I use third-party or open-source models?**
|
||||
|
||||
Yes. NanoClaw supports any Claude API-compatible model endpoint. Set these environment variables in your `.env` file:
|
||||
### Environment Variables
|
||||
|
||||
```bash
|
||||
ANTHROPIC_BASE_URL=https://your-api-endpoint.com
|
||||
ANTHROPIC_AUTH_TOKEN=your-token-here
|
||||
# .env
|
||||
DISCORD_BOT_TOKEN= # Claude Code bot token
|
||||
DISCORD_CODEX_BOT_TOKEN= # Codex bot token (optional, for dual-bot)
|
||||
ANTHROPIC_API_KEY= # Or use OAuth (CLAUDE_CODE_OAUTH_TOKEN)
|
||||
OPENAI_API_KEY= # For Codex
|
||||
CODEX_MODEL= # Default codex model
|
||||
CODEX_EFFORT= # Default reasoning effort (low/medium/high)
|
||||
```
|
||||
|
||||
This allows you to use:
|
||||
- Local models via [Ollama](https://ollama.ai) with an API proxy
|
||||
- Open-source models hosted on [Together AI](https://together.ai), [Fireworks](https://fireworks.ai), etc.
|
||||
- Custom model deployments with Anthropic-compatible APIs
|
||||
### Service Management (Linux)
|
||||
|
||||
Note: The model must support the Anthropic API format for best compatibility.
|
||||
```bash
|
||||
systemctl --user start nanoclaw # Claude Code service
|
||||
systemctl --user start nanoclaw-codex # Codex service
|
||||
systemctl --user restart nanoclaw nanoclaw-codex # Restart both
|
||||
journalctl --user -u nanoclaw -f # Follow logs
|
||||
```
|
||||
|
||||
**How do I debug issues?**
|
||||
### Service Management (macOS)
|
||||
|
||||
Ask Claude Code. "Why isn't the scheduler running?" "What's in the recent logs?" "Why did this message not get a response?" That's the AI-native approach that underlies NanoClaw.
|
||||
```bash
|
||||
launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist
|
||||
launchctl load ~/Library/LaunchAgents/com.nanoclaw-codex.plist
|
||||
launchctl kickstart -k gui/$(id -u)/com.nanoclaw
|
||||
```
|
||||
|
||||
**Why isn't the setup working for me?**
|
||||
## Channel Registration
|
||||
|
||||
If you have issues, during setup, Claude will try to dynamically fix them. If that doesn't work, run `claude`, then run `/debug`. If Claude finds an issue that is likely affecting other users, open a PR to modify the setup SKILL.md.
|
||||
Channels are registered in each service's SQLite database (`registered_groups` table). Each entry specifies:
|
||||
|
||||
**What changes will be accepted into the codebase?**
|
||||
- **jid**: Discord channel ID (`dc:<channel_id>`)
|
||||
- **folder**: Group folder name (matches Discord channel name)
|
||||
- **trigger_pattern**: Regex for bot activation (`@claude` or `@codex`)
|
||||
- **agent_type**: `claude-code` or `codex`
|
||||
- **work_dir**: Working directory for the agent
|
||||
- **container_config**: JSON config (e.g., `{"codexEffort":"high"}`)
|
||||
|
||||
Only security fixes, bug fixes, and clear improvements will be accepted to the base configuration. That's all.
|
||||
## Development
|
||||
|
||||
Everything else (new capabilities, OS compatibility, hardware support, enhancements) should be contributed as skills.
|
||||
|
||||
This keeps the base system minimal and lets every user customize their installation without inheriting features they don't want.
|
||||
|
||||
## Community
|
||||
|
||||
Questions? Ideas? [Join the Discord](https://discord.gg/VDdww8qS42).
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG.md](CHANGELOG.md) for breaking changes and migration notes.
|
||||
```bash
|
||||
npm run build # Build main project
|
||||
cd container/agent-runner && npm run build # Build Claude runner
|
||||
cd container/codex-runner && npm run build # Build Codex runner
|
||||
npm run dev # Dev mode with hot reload
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
MIT — Fork of [qwibitai/nanoclaw](https://github.com/qwibitai/nanoclaw)
|
||||
|
||||
Reference in New Issue
Block a user