Background Agents (nikctl)
Thenikctl CLI provides comprehensive management of background agents and jobs. Background agents can execute long-running tasks autonomously while you continue working.
Installation
Global Options
Allnikctl commands support these global options:
| Option | Description | Default |
|---|---|---|
--api-url <url> | API server URL | http://localhost:3000 |
--debug | Enable debug logging | false |
--json | Output in JSON format | false |
Commands Overview
nikctl bg start
Start a new background job with specified parameters.
Syntax:
-r, --repo <repo>- Repository in formatowner/name-t, --task <task>- Task description for the agent
-b, --branch <branch>- Base branch (default:main)-p, --playbook <playbook>- Playbook name to use--time <minutes>- Maximum execution time in minutes (default:30)--tokens <count>- Maximum tool calls allowed (default:50)--reviewers <reviewers>- PR reviewers, comma-separated--labels <labels>- PR labels, comma-separated--draft- Create draft PR instead of regular PR--priority <priority>- Job priority 0-10 (default:5)
nikctl bg list
List background jobs with optional filtering.
Syntax:
-s, --status <status>- Filter by job status-r, --repo <repo>- Filter by repository-l, --limit <limit>- Limit number of results (default:20)--json- Output as JSON
queued- Job is waiting to startrunning- Job is currently executingsucceeded- Job completed successfullyfailed- Job failed with errorcancelled- Job was cancelledtimeout- Job exceeded time limit
nikctl bg show <jobId>
Show detailed information for a specific job.
Syntax:
--json- Output as JSON format
- Job ID and status
- Repository and branch information
- Task description and playbook
- Timing information (created, started, completed)
- Resource usage metrics (tokens, tool calls, memory)
- Pull request URL (if created)
- Error details (if failed)
- Recent log entries
nikctl bg logs <jobId>
Stream or view logs for a specific job.
Syntax:
-f, --follow- Follow logs in real-time--tail <lines>- Show last N lines (default:50)
INFO- General informationWARN- Warning messagesERROR- Error messagesDEBUG- Debug information
nikctl bg cancel <jobId>
Cancel a running or queued job.
Syntax:
- Only jobs in
queuedorrunningstatus can be cancelled - Cancelled jobs cannot be restarted (use
retryto create new job) - Cancellation is immediate and cannot be undone
nikctl bg followup <jobId> <message>
Send a follow-up message to a running job.
Syntax:
-p, --priority <priority>- Message priority:low,normal,high(default:normal)
high- Interrupts current work immediatelynormal- Processed at next checkpointlow- Processed when convenient
nikctl bg open <jobId>
Open job in browser (console or PR).
Syntax:
--pr- Open pull request instead of console
CONSOLE_URL- Base URL for job console (default:http://localhost:3001)
nikctl bg stats
Show background agent statistics and metrics.
Syntax:
--json- Output as JSON format
- Total jobs created
- Jobs by status (queued, running, succeeded, failed, cancelled)
- Average execution time
- Resource utilization
- Success rate
nikctl bg retry <jobId>
Retry a failed job by creating a new job with the same parameters.
Syntax:
- Only failed jobs can be retried
- Creates a new job with a new ID
- Uses the same parameters as the original job
- Original job remains in failed state
Job Lifecycle
Configuration
Environment Variables
Set these in your environment or.env file:
API Server Setup
Background agents require thenikd daemon to be running:
Integration Examples
CI/CD Pipeline
Slack Integration
Troubleshooting
Common Issues
Job stuck in queued status:Debug Mode
Enable debug logging for detailed information:Log Locations
- nikctl logs: Stdout/stderr
- nikd daemon logs:
~/.nikcli/logs/nikd.log - Job logs: Stored in daemon memory and database
- Debug logs:
~/.nikcli/logs/debug.log(when enabled)
Best Practices
Job Design
- Keep tasks focused and specific
- Use descriptive task descriptions
- Set appropriate time limits
- Include acceptance criteria in task description
Resource Management
- Monitor job statistics regularly
- Set reasonable token limits
- Use priority levels appropriately
- Clean up old jobs periodically
Security
- Use draft PRs for experimental work
- Review generated code before merging
- Limit repository access appropriately
- Monitor job logs for sensitive data
Monitoring
- Set up notifications for job failures
- Monitor resource usage trends
- Track success rates over time
- Use health checks for daemon monitoring