# Automation Rules

<details>

<summary><strong>Create Rules from Transaction Patterns</strong></summary>

**The Script**

bash

```bash
#!/bin/bash
# suggest-rules.sh

kick transactions list \
  --from="2025-01-01" \
  --format=json | \
jq -r '
  group_by(.counterparty) |
  map(select(length >= 10)) |
  map({
    counterparty: .[0].counterparty,
    count: length,
    categories: [.[].category] | unique
  }) |
  map(select(.categories | length == 1)) |
  .[] |
  "Suggested rule: counterparty=\"\(.counterparty)\" → category=\"\(.categories[0])\" (based on \(.count) transactions)"
'

echo ""
echo "Create rules with: kick rules create --condition=\"counterparty=<name>\" --action=\"set-category:<category>\""
```

**How to Customize**

* Adjust minimum transaction count threshold
* Look at description patterns instead of counterparties
* Auto-create rules instead of just suggesting

**What It Outputs**

```
Suggested rule: counterparty="Amazon Web Services" → category="Cloud Infrastructure" (based on 47 transactions)
```

</details>

<details>

<summary><strong>Test Rules Before Deploying</strong></summary>

**The Script**

bash

```bash
#!/bin/bash
# test-rule.sh

CONDITION="description contains 'AWS'"
NEW_CATEGORY="Cloud Infrastructure"

echo "Testing rule: $CONDITION → $NEW_CATEGORY"
echo ""

kick transactions list \
  --filter="$CONDITION" \
  --format=json | \
jq -r '.[] | "Would update: \(.date) | \(.amount) | \(.counterparty) | Current category: \(.category // "none")"'

echo ""
count=$(kick transactions list --filter="$CONDITION" --format=json | jq 'length')
echo "This rule would affect $count transactions"

read -p "Create this rule? (y/n) " -n 1 -r
echo

if [[ $REPLY =~ ^[Yy]$ ]]; then
  kick rules create \
    --name="AWS Categorization" \
    --condition="$CONDITION" \
    --action="set-category:$NEW_CATEGORY"
  echo "✓ Rule created"
fi
```

**How to Customize**

* Test multiple conditions at once
* Save preview results to a file
* Add rule to specific entity

**What It Outputs**

```
Testing rule: description contains 'AWS' → Cloud Infrastructure

Would update: 2026-01-05 | 125.00 | Amazon Web Services | Current category: none
This rule would affect 3 transactions
```

</details>

<details>

<summary><strong>Audit and Clean Up Unused Rules</strong></summary>

**The Script**

bash

```bash
#!/bin/bash
# audit-rules.sh

echo "Auditing automation rules..."
echo ""

rules=$(kick rules list --format=json)

echo "$rules" | jq -r '.[] | .id' | while read -r rule_id; do
  rule_name=$(echo "$rules" | jq -r ".[] | select(.id==\"$rule_id\") | .name")
  rule_condition=$(echo "$rules" | jq -r ".[] | select(.id==\"$rule_id\") | .condition")
  
  count=$(kick transactions list \
    --from="$(date -d '90 days ago' +%Y-%m-%d)" \
    --filter="$rule_condition" \
    --format=json | jq 'length')
  
  if [ "$count" -eq 0 ]; then
    echo "⚠️  Rule '$rule_name' matched 0 transactions in last 90 days"
    echo "    Consider deleting: kick rules delete --id=$rule_id"
    echo ""
  else
    echo "✓ Rule '$rule_name' matched $count transactions"
  fi
done
```

**How to Customize**

* Change lookback period
* Auto-delete rules with zero matches
* Send weekly audit report via email

**What It Outputs**

```
✓ Rule 'AWS Categorization' matched 12 transactions
⚠️  Rule 'Old Vendor Auto-Category' matched 0 transactions in last 90 days
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kick.co/ai/kick-cli/cli-use-case-library/automation-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
