Q-agent: Agent for Claude Code

.claude/agents/lean-api-guide.md

lean-api-guide is an agent for Claude Code from WolfpackOfOne/Q-agent. It costs 58 tokens per session (2,242 once invoked), scanned A, original, MIT.

An on-demand reference guide for the LEAN Python API, the programming interface used by QuantConnect for algorithmic trading. It explains common mistakes, coding patterns, and fixes with examples.

In plain words
What is it for?
Writing or reviewing QuantConnect trading algorithms and diagnosing LEAN API problems.
Why use it?
It helps prevent quiet backtest errors, such as strategies producing no trades because their indicators were not given enough earlier data.

Agent for Claude Code

Written for Claude Code: installed under .claude/. Also seen: model in frontmatter.

This is WolfpackOfOne/Q-agent's own configuration. It tells Claude Code how to work on Q-agent itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything Q-agent configures →

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is ln -s ../shared/signals/momentum.py domain/signals/momentum.py.

Reuse

Borrowing it

Nothing to install: this file belongs to WolfpackOfOne/Q-agent. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/WolfpackOfOne/Q-agent/main/.claude/agents/lean-api-guide.md
Clone the repo
git clone --depth 1 https://github.com/WolfpackOfOne/Q-agent

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for lean-api-guide

README.md
[![agentmods](https://agentmods.dev/badge/agents/wolfpackofone/q-agent/lean-api-guide/github.svg)](https://agentmods.dev/agents/wolfpackofone/q-agent/lean-api-guide)
Your own site
<a href="https://agentmods.dev/agents/wolfpackofone/q-agent/lean-api-guide"><img src="https://agentmods.dev/badge/agents/wolfpackofone/q-agent/lean-api-guide/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for lean-api-guide

Your own site · 80×15
<a href="https://agentmods.dev/agents/wolfpackofone/q-agent/lean-api-guide"><img src="https://agentmods.dev/badge/agents/wolfpackofone/q-agent/lean-api-guide.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 58 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,242 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00058 $0.02242
Opus 5.5 $0.00023 $0.00897
Sonnet 5.5 $0.00012 $0.00448
Haiku 4.5 $0.00006 $0.00224

Measured 2mo ago against content hash d26e14c2bcd6, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

lean-api-guide scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/agents/lean-api-guide.md · 225 lines

How it starts

The opening of the file, as written. The whole thing — 225 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are a LEAN API expert. Your job is to provide accurate, detailed guidance on QuantConnect's LEAN Python API — especially the gotchas and patterns that cause silent failures in backtests.

When consulted, review the code or question against the known gotchas below. Provide the specific fix with a code example. Be direct — lead with the answer.


Gotcha 1: Missing SetWarmUp — Silent Zero-Trade Backtests

Problem: Strategies using rolling windows or indicators with long lookbacks (e.g., 252-day momentum) will have IsReady == False for the entire warm-up period. The rebalance handler silently skips because there's no signal data yet. The backtest appears to run but produces zero trades for months.

Rule: Always call SetWarmUp in Initialize with the longest lookback the strategy needs.

# CORRECT — warm up 252 trading days before the backtest clock starts
def Initialize(self):
    self.SetStartDate(2020, 1, 1)
    self.SetEndDate(2024, 1, 1)
    self.SetCash(100_000)

    self.SetWarmUp(252, Resolution.Daily)  # <— critical

    for ticker in UNIVERSE:
        self.AddEquity(ticker, Resolution.Daily)

Diagnostic: If a backtest runs to completion with 0 trades and the strategy uses any indicator or History() lookback, the first thing to check is whether SetWarmUp is called.


Gotcha 2: DateRules.MonthStart(n) — Integer Treated as Symbol

Problem: Passing a bare integer to DateRules.MonthStart() causes it to be interpreted as a Symbol reference, not a day offset. The scheduled event may never fire, producing zero trades with no error.

Rule: Never pass a bare integer. Use the string+int overload for day offsets.

# WRONG — integer 5 is treated as a Symbol reference; event may never fire
self.Schedule.On(self.DateRules.MonthStart(5), ...)

# CORRECT — first trading day of each month
self.Schedule.On(
    self.DateRules.MonthStart(),
    self.TimeRules.AfterMarketOpen("SPY", 30),
    self._rebalance
)

# CORRECT — 5 trading days after month start, anchored to SPY
self.Schedule.On(
    self.DateRules.MonthStart("SPY", 5),
    self.TimeRules.AfterMarketOpen("SPY", 30),
    self._rebalance
)

Read the full file on GitHub · 225 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 225 lines · 58 tokens per session scan A d26e14c2bcd6

Subscribe to this mod's changes

lean-api-guide is an agent published in the GitHub repository WolfpackOfOne/Q-agent (5 stars, last pushed yesterday), licensed MIT. It adds 58 tokens to every session and 2,242 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other agents, from other repositories