Skip to main content

Background Agents (nikctl)

The nikctl CLI provides comprehensive management of background agents and jobs. Background agents can execute long-running tasks autonomously while you continue working.

Installation

Global Options

All nikctl commands support these global options:
OptionDescriptionDefault
--api-url <url>API server URLhttp://localhost:3000
--debugEnable debug loggingfalse
--jsonOutput in JSON formatfalse

Commands Overview

nikctl bg start

Start a new background job with specified parameters. Syntax:
Required Options:
  • -r, --repo <repo> - Repository in format owner/name
  • -t, --task <task> - Task description for the agent
Optional Options:
  • -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)
Examples:

nikctl bg list

List background jobs with optional filtering. Syntax:
Options:
  • -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
Job Statuses:
  • queued - Job is waiting to start
  • running - Job is currently executing
  • succeeded - Job completed successfully
  • failed - Job failed with error
  • cancelled - Job was cancelled
  • timeout - Job exceeded time limit
Examples:

nikctl bg show <jobId>

Show detailed information for a specific job. Syntax:
Options:
  • --json - Output as JSON format
Examples:
Output includes:
  • 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:
Options:
  • -f, --follow - Follow logs in real-time
  • --tail <lines> - Show last N lines (default: 50)
Examples:
Log Format:
Log Levels:
  • INFO - General information
  • WARN - Warning messages
  • ERROR - Error messages
  • DEBUG - Debug information

nikctl bg cancel <jobId>

Cancel a running or queued job. Syntax:
Examples:
Notes:
  • Only jobs in queued or running status can be cancelled
  • Cancelled jobs cannot be restarted (use retry to 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:
Options:
  • -p, --priority <priority> - Message priority: low, normal, high (default: normal)
Examples:
Message Priorities:
  • high - Interrupts current work immediately
  • normal - Processed at next checkpoint
  • low - Processed when convenient

nikctl bg open <jobId>

Open job in browser (console or PR). Syntax:
Options:
  • --pr - Open pull request instead of console
Examples:
Environment Variables:
  • CONSOLE_URL - Base URL for job console (default: http://localhost:3001)

nikctl bg stats

Show background agent statistics and metrics. Syntax:
Options:
  • --json - Output as JSON format
Examples:
Statistics Include:
  • 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:
Examples:
Notes:
  • 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 the nikd daemon to be running:

Integration Examples

CI/CD Pipeline

Slack Integration

Troubleshooting

Common Issues

Job stuck in queued status:
Job fails immediately:
Cannot connect to API:

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