CLI: Agent Mode

When running inside an AI agent environment, the CLI automatically detects the agent context and sets the source field to "agent".

Auto-Detection

The CLI checks for these environment variables:

VariableAgent PlatformSets agent_type to
CLAUDE_SESSION_IDClaude Codeclaude-code
CODEX_SESSION_IDCodexcodex
OPENCLAW_AGENT_IDOpenClawopenclaw
CURSOR_AGENTCursorcursor

When detected, the CLI automatically:

  1. Sets source: "agent" on all entries.
  2. Populates metadata.agent_type from the environment.
  3. Uses the session ID as metadata.session_id.

Zero-Config Example (inside Claude Code)

# These are auto-detected — no flags needed
keito time start --project acme --task development
# ... agent works ...
keito time stop --notes "Implemented OAuth flow"
keito expense log --project acme --quantity 45 \
  --notes "claude-opus-4-6: 30k input + 15k output tokens"

The resulting time entry:

{
  "source": "agent",
  "metadata": {
    "agent_type": "claude-code",
    "session_id": "auto-detected-from-env",
    "agent_id": "review-bot-01"
  }
}

Explicit Mode

Override auto-detection with flags:

keito time start --project acme --task development \
  --source agent \
  --agent-id my-custom-bot \
  --session-id "$(uuidgen)"

Discarding Sessions

If an agent session fails and you want to discard the timer:

keito time stop --discard

This deletes the running time entry instead of saving it.

Paired Workflow

The recommended pattern for agent work is to always pair time and expense logging:

# Start
keito time start --project acme --task development

# ... agent does work ...

# Stop + log expense in one pipeline
keito time stop --notes "Reviewed 5 pull requests" && \
keito expense log --project acme --quantity 62 \
  --notes "claude-opus-4-6: 42k input + 20k output tokens"