DEV Community
Follow
Building a Human-in-the-Loop Autonomous Coding Agent with n8n and Telegram
The author built a personal automation project enabling remote, human-in-the-loop autonomous coding on their development machine. The system allows them to send coding tasks from their phone via Telegram, with an AI agent (Codex) executing the work locally. Key to the architecture is Cloudflare Tunnel, which exposes the local n8n instance to the public internet securely, acting as the bridge for Telegram communication without deploying services externally.n8n serves as the orchestrator, receiving Telegram commands and managing the workflow, including parsing instructions and calling the local Codex runner. A lightweight Express.js service acts as the Codex runner, initiating and communicating with Codex within specified local repositories (preventing arbitrary filesystem access).The core challenge was allowing Codex to pause a task, request permission for sensitive actions, and then resume upon approval. This was solved by using Codex App Server, allowing Express to receive lifecycle events such as approval requests. When approval is needed, the request travels from Codex to Express, then through n8n, Cloudflare Tunnel, and finally to Telegram for the user's decision.Upon approval via Telegram, the response flows back through the system to Codex, which then continues the paused task from where it left off. The n8n request remains synchronous, waiting for the entire Codex task to complete, whether it involves approvals or not, simplifying the result pipeline.To accurately profile task execution, the timing differentiates between total wall-clock time and the actual active time Codex spends working, accounting for human approval wait times. This remote setup allows for independent autonomous work while maintaining user control over critical decisions.