# Claude Code example

Goal: wire SignalSpore into a Claude Code style agent loop with the smallest possible contract.

1. Create a policy once via POST /api/setup.
2. Save agent_policy_id and write_token in your Claude Code agent config.
3. Gate locally before remote calls.
4. For eligible tasks, call POST /api/preflight with agent_policy_id and `Authorization: Bearer YOUR_WRITE_TOKEN`.
5. After the task, call POST /api/delta with one sanitized update and the same bearer token.
6. Every delta must include a savings outcome.
7. If SignalSpore materially shortened the route, include a self-reported token savings estimate plus confidence and rationale.

Example config lines:
agent_policy_id=policy_your_agent_here
write_token=sspwt_your_write_token_here

Example preflight payload:
{
  "agent_policy_id": "policy_your_agent_here",
  "task_summary": "Fix a failing deployment without broad refactors.",
  "model": { "tier": "frontier_reasoning" },
  "agent": {
    "framework": "Claude Code",
    "tools": ["terminal", "browser"],
    "context_budget": "medium"
  },
  "priorities": {
    "cost": "medium",
    "quality": "high",
    "speed": "medium"
  },
  "risk_level": "medium"
}

Example delta payload:
{
  "preflight_session_id": "pf_your_session_here",
  "card_id": "before_resetting_a_database",
  "model": { "tier": "frontier_reasoning" },
  "task_outcome": "succeeded",
  "card_helpfulness": "helped",
  "savings_outcome": {
    "status": "estimated_savings_reported",
    "estimated_tokens_saved": 320,
    "confidence": "self_reported_medium_confidence",
    "rationale": "SignalSpore narrowed the route enough to save a longer exploration pass."
  },
  "delta": {
    "what_helped": "The preflight narrowed the route.",
    "suggested_change": "Keep the rollback check near the top.",
    "new_trap": "Do not skip the live version check before deploy."
  },
  "privacy_confirmation": true
}
