{"data":{"slug":"discovered-4d2cb4165b4c7b21594165cbfacd53d3570190b2dfe1f78f","title":"bkcodex - Background Worker Orchestration for Codex CLI on Linux and Windows","summary":"Orchestrate persistent, isolated Codex CLI background workers through bkcodex on Linux (systemd + tmux) and Windows (detached processes). Use this skill when delegating multi-step coding, refactoring, batch annotation, or verification tasks to background Codex CLI sessions with a SQLite task queue, structured result.json receipts, and automated domain validation.","url":"https:\/\/skillshunter.net\/skills\/discovered-4d2cb4165b4c7b21594165cbfacd53d3570190b2dfe1f78f","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-4d2cb4165b4c7b21594165cbfacd53d3570190b2dfe1f78f","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-4d2cb4165b4c7b21594165cbfacd53d3570190b2dfe1f78f.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-4d2cb4165b4c7b21594165cbfacd53d3570190b2dfe1f78f\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before enqueuing work, ensure the environment is healthy by running `bkcodex --config config.local.toml init` and `bkcodex --config config.local.toml doctor`. Verify that `workspace_exists`, `codex_exists`, and authentication are ready. On Linux, ensure `systemctl: true` and `linger: yes` for offline persistence. On Windows, use `bkcodex worker --name worker-01` within a managed background task to avoid process termination.","instructions":"---\nname: bkcodex\ndescription: >-\n  Orchestrate persistent, isolated Codex CLI background workers through bkcodex on Linux (systemd + tmux) and Windows (detached processes). Use this skill when delegating multi-step coding, refactoring, batch annotation, or verification tasks to background Codex CLI sessions with a SQLite task queue, structured result.json receipts, and automated domain validation.\n---\n\n# bkcodex Background Worker Orchestration\n\nUse `bkcodex` when a primary agent acts as the architect\/reviewer and delegates self-contained execution tasks to one or more background Codex CLI workers. Every task runs in a fresh `codex exec` session, writes artifacts and `result.json`, and passes an optional external domain validator before being marked `completed`.\n\n## Quick Preflight\n\nBefore enqueuing work, check config and environment health:\n\n```bash\nbkcodex --config config.local.toml init\nbkcodex --config config.local.toml doctor\n```\n\nVerify from `doctor` output:\n- `workspace_exists: true`\n- `codex_exists: true`\n- Authentication is ready (`auth_file_exists: true`, or on Windows\/local dev if pointing `codex.home` to an already authenticated `~\/.codex` directory, verify with `<binary> login status`).\n- On Linux servers, `systemctl: true` and `linger: yes` for offline `systemd --user` persistence.\n- On Windows, `runtime: \"windows-detached\"`; `systemctl` and `tmux` are not required.\n\nIf authentication is missing in an isolated `codex.home`, instruct the user to run `bkcodex --config config.local.toml login` (device auth). Never hardcode or print credentials.\n\n## End-to-End Orchestration Workflow\n\n### 1. Design Clean, Non-Overlapping Tasks\n- Give each task a unique ID matching `[A-Za-z0-9][A-Za-z0-9_-]{0,79}` (re-enqueuing the same ID with different prompt\/payload raises `ValueError`).\n- When running multiple workers (`workers.count > 1`) in parallel on the same workspace, **partition target files strictly** so two workers never edit the same file simultaneously.\n- Write a focused Markdown prompt file (`task.md`) stating:\n  - Concrete goal and files in scope (and files NOT to modify);\n  - Exact acceptance\/test commands;\n  - Requirement to write `result.json` (and `CHECKPOINT.json` if blocked\/partial) \u2014 `bkcodex` automatically appends the exact `run_dir` paths.\n- Optionally pair it with a JSON payload (`payload.json`) consumed by your custom `[validation].command` (e.g., `expected_artifacts`, `verify_commands`).\n\n### 2. Enqueue Tasks\nSingle task:\n```bash\nbkcodex --config config.local.toml enqueue \\\n  --id task-001 \\\n  --prompt-file tasks\/task-001.md \\\n  --payload tasks\/payload-001.json\n```\n\nBatch JSONL (`{\"id\": \"...\", \"prompt_file\": \"...\", \"payload\": {...}}`):\n```bash\nbkcodex --config config.local.toml import tasks\/manifest.jsonl\n```\n\n### 3. Run Workers\n\nChoose the execution mode based on OS and host runner:\n- **Windows inside an agent tool-runner, IDE task, or CI (strongly preferred)**:\n  Do **NOT** call `bkcodex start`. Many Windows subprocess runners wrap each short command in a Job Object with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`, which immediately terminates detached child processes when `bkcodex start` exits. Instead, launch one long-lived managed background task per worker directly:\n  ```bash\n  bkcodex --config config.local.toml worker --name worker-01\n  ```\n  Each worker drains the SQLite queue under its exclusive `msvcrt` lock, honors `STOP` \/ `stop --now` \/ `status`, and exits cleanly when the queue is empty. Streamed logs go to the host runner's task output rather than `state_dir\/logs\/<worker>.log`.\n- **Linux (`systemd` + `tmux`) or interactive Windows terminals (PowerShell \/ Windows Terminal)**:\n  ```bash\n  bkcodex --config config.local.toml install   # required once on Linux; initializes dirs on Windows\n  bkcodex --config config.local.toml start\n  ```\n\n### 4. Monitor, Review, and Recover\n\n```bash\nbkcodex --config config.local.toml status\nbkcodex --config config.local.toml logs --name worker-01 --tail 80  # Linux journalctl or Windows `start` mode; in direct `worker` mode read host task output + run_dir\n```\n\nWhen a task finishes, always inspect its `run_dir` from `status`:\n- `result.json`: `task_id`, `status` (`completed` \/ `blocked` \/ `needs_input`), `summary`, `artifacts`.\n- `receipt.json`: written only after schema, artifact existence, path containment (within `state_dir` or `workspace`), and `[validation].command` all succeed.\n- `validation.log` & `stderr.log` & `execution.json`: inspect first whenever a task ends up `blocked`.\n- `CHECKPOINT.json`: read if a worker paused or hit timeout before resuming.\n\nControl and recovery commands:\n```bash\nbkcodex --config config.local.toml stop           # pause after current task finishes\nbkcodex --config config.local.toml stop --now     # immediately terminate running worker\/Codex trees\nbkcodex --config config.local.toml retry task-001 # re-queue a blocked \/ needs_input \/ interrupted task\nbkcodex --config config.local.toml resume         # clear STOP marker and restart workers\n```\n\n## Artifact & Validation Rules\n\n- Completed tasks (`status: \"completed\"`) must declare at least one existing file in `artifacts`.\n- Relative artifact paths resolve against `run_dir` first, then `workspace`; every resolved artifact must remain strictly inside `state_dir` or `workspace`.\n- `[validation].command` is an argv array (no shell expansion) supporting `{task}`, `{result}`, and `{run_dir}`.\n- **Timeout tip**: If your validation command runs a full PyTorch\/integration test suite taking >2 minutes, raise `validation.timeout_seconds` (e.g., `300`) in `config.local.toml` so valid completions are not marked `blocked` by validator timeout.\n\n## Platform Notes & Common Pitfalls\n\n- **Windows Job Object reaping**: Agent\/IDE\/CI subprocess runners commonly terminate all processes in a command's Windows Job Object as soon as that command returns. Always run `bkcodex worker --name <role>` as a managed background task in those environments instead of `bkcodex start`.\n- **Windows Codex binary**: If an older global npm `codex` fails to parse newer `~\/.codex\/config.toml` keys (such as newer `reasoning_effort` values), point `codex.binary` to the Codex Desktop executable (`C:\/Program Files\/WindowsApps\/OpenAI.Codex_...\/app\/resources\/codex.exe`) or update the CLI.\n- **Windows paths & encoding**: Prefer forward slashes (`C:\/path\/to\/codex.exe`) or escaped backslashes in TOML strings. `bkcodex` sets `PYTHONUTF8=1` and reads\/writes all JSON, prompts, and logs as UTF-8.\n- **CLI flags**: Keep `global_args = [\"--no-daemon\"]` only if the installed Codex CLI supports it; otherwise set `global_args = []`.\n- **Network vs. auth\/quota failures**: `bkcodex` automatically retries transient network failures up to `workers.max_attempts` with shared `NETWORK_COOLDOWN.json`, and stops the worker immediately on `auth` or `quota` errors or 3 consecutive failures.\n","use_cases":["Delegating multi-step coding tasks to background workers","Refactoring code in isolated sessions","Batch annotation and verification tasks","Automated domain validation with structured result receipts"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/sanhui-cloud\/bkcodex\/blob\/0a1b36abcc08b0ab0edab633fddfe8cea1418832\/skills\/bkcodex\/SKILL.md","source_commit":"0a1b36abcc08b0ab0edab633fddfe8cea1418832","license":null,"version":null,"listing_approved_at":"2026-11-28","created_at":"2026-11-28T07:59:25.000000Z","updated_at":"2026-11-28T18:37:41.000000Z","seo_title":"bkcodex - Background Worker Orchestration for Codex CLI","seo_description":"bkcodex is a tool for orchestrating persistent, isolated Codex CLI background workers on Linux and Windows. It supports task delegation, SQLite task queues, and automated","seo_keywords":["bkcodex","Codex CLI","background worker orchestration","Linux systemd","Windows detached processes","task delegation","SQLite task queue","result.json receipts"]}}