Flow of one monthly run: holdings go into a free Python screen, Claude judges only the stocks that qualify (the one paid step), free Python allocates the budget, and an email goes out.
FIG. 1 One month, start to finish. Only the highlighted step costs money.

This is Part 1 of three. It covers the system: the problem, how it’s built, and why it’s built this way. Part 2 is about what it costs to run Claude inside it. Part 3 will move the result off my inbox and onto a small screen on my desk, once the hardware is ready.

Everything here is from the real system as it ran in August 2026, with every rupee figure masked. Some of it has changed since. There’s a short note on that at the end.

The problem

I’ve been investing for close to four years across equity stocks, REITs, InvITs, and gold and silver ETFs. My strategy is simple: pick quality, buy it cheap, and hold it unless the quality itself starts to slip.

That worked. The portfolio was beating its benchmarks. But somewhere around a hundred stocks and ticks in, I could see a challenge coming. How do you keep an eye on that many positions every month, and catch the ones losing quality before it’s too late? Doing that by hand turns a monthly review into a second job.

The question I needed answered is always the same. When a holding has dropped well below what I paid, is the damage to the price, or to the business? If it’s only the price, that’s a chance to add more. If it’s the business, adding more is throwing good money after bad. I couldn’t keep asking that properly by hand, every month, for every holding that fell, so I built a pipeline to ask it for me.

The idea

Once a month, unattended, a GCP pipeline:

  1. screens my holdings (around 80 at the time, and growing every month),
  2. runs Buffett’s temporary vs permanent damage test on the few that fell far enough to matter,
  3. splits the month’s money across asset classes by a fixed plan,
  4. and emails me the answer.

I went with email because a dashboard only works if I remember to open it, and an email lands whether I go looking or not. It carries a money ledger (what’s coming in, what’s going out, what stays uninvested), the asset split against my targets, and a check on how evenly my equity picks are weighted against each other.

I read it and can override any of it. Nothing executes on its own; the pipeline only recommends.

The locked split

Every new rupee goes into a fixed split across six asset classes. I decided the split once, ahead of time, so a good or bad month never turns into an excuse to improvise. The allocation step checks new money against this split on every run.

Donut chart of the locked target split as of August 2026: equity 66%, banking 10%, REITs 7%, InvITs 7%, gold ETF 6.2%, silver ETF 3.8%.
FIG. 2 The locked split as it was in August 2026. It has changed since.

Gold and silver share one 10% slot, but not as a fixed 50/50. A gold-silver ratio (GSR) rule tilts each month’s metal buy toward whichever one is cheaper compared to the other. The lean is small, and the combined 10% doesn’t move. It’s the same idea as the check on stocks: the target stays fixed, and only the path to it changes with what the market is offering that month.

How it runs: the 10 steps

The 10 steps in four lanes. A, get the holdings: 1 Claude scheduled routine, 2 Google Drive, 3 Cloud Scheduler. B, land the data: 4 Cloud Function, 5 BigQuery, plus Secret Manager. C, screen, judge, allocate: 6 free price screen, 7 paid Claude judgment call, 8 free allocation. D, send it: 9 MJML to HTML, 10 Gmail.
FIG. 3 Every box is a real deployed piece. The steps below use the same numbers.

A. Get the holdings

Step 1: a Claude scheduled routine. This step sits outside the pipeline on purpose. Zerodha needs a live login every trading day. The only way to script that away is to store my broker password and TOTP secret, and that wasn’t a trade I’d make for a once-a-month convenience. So a Claude routine does it with me:

  • It runs on a fixed monthly cron, 30 3 25 * *, which is 9:00 IST on the 25th. A fixed cron heals itself: if I miss the login one month, it just runs again next month.
  • It finds the Kite login tool with its own ToolSearch, shows me the login link, and sends a phone notification so I don’t miss it.
  • It pulls raw holdings with the Kite MCP connector’s get_holdings. It does no filtering or scoring; its only job is a clean pull.
  • It saves the result as a dated CSV/Sheet in a fixed Drive folder, “Zerodha Monthly Holdings”.
  • It runs on Haiku 4.5. Fetch-and-save has no judgment in it, so a bigger model would add nothing.
The Claude routine's settings: active, runs at 09:00 AM on day 25 of the month, uses the Zerodha Kite MCP connector and Google Drive, on Haiku 4.5, 4 of 4 recent runs succeeded.
FIG. 4 Real screenshot: the Step 1 routine. Its prompt isn't shown, on purpose.

Step 2: Google Drive holds that Sheet, named with the pull date. Before doing anything, Step 4 checks the file name against the current month. If the newest file isn’t from this month, the whole run waits instead of working on old data.

Google Drive folder "Zerodha Monthly Holdings" with two dated Sheets from real runs, thumbnails too small to read any figures.
FIG. 5 Real screenshot: the Drive folder with two monthly pulls.

For scale, this is what the Sheet is built from: my real Zerodha holdings screen, 83 positions and counting, with every rupee figure masked. These are the ~80 holdings Step 6 screens each month.

Zerodha holdings screen with 83 equity positions. Quantity, cost, value and P&L are masked; only symbols and the public last traded price are visible.
FIG. 6 Real screenshot: 83 positions, every rupee figure masked.

Step 3: Cloud Scheduler fires the next day, the 26th. The one-day gap is buffer time for my login click to actually happen. It sends an authenticated HTTP POST to Step 4 with an empty body. A body is only used to override the budget when I trigger a test run by hand.

Cloud Scheduler job zerodha-holdings-pipeline-monthly: region asia-south1, cron 30 9 26 * * in Asia/Calcutta, enabled, last run succeeded.
FIG. 7 Real screenshot: the monthly trigger.

B. Land the data

Step 4: a Cloud Function (Gen2), HTTP triggered and deployed with --no-allow-unauthenticated, so it’s called with an identity token and isn’t open to the internet.

  • It first checks whether this run_id was already landed or processed. A retry never lands or processes the same month twice.
  • It downloads the CSV from Step 2 and loads it into BigQuery (Step 5).
  • The run_id comes straight from the date in the Drive file name, so the two can’t drift out of sync.
Cloud Function zerodha-holdings-pipeline: Gen2, asia-south1, Python 3.12, scaling from 0 to 1 instance, with the entry point's docstring visible in the source view.
FIG. 8 Real screenshot: the Cloud Function, with the budget figure in the code masked. It scales to zero, so it's billed only for the minutes it runs.

Step 5: BigQuery, dataset sudhirkenguva.zerodha_pipeline, with four tables:

Table What it holds
zerodha_holdings_pipeline the landing table, one row per holding per run
averaging_screening each stock’s trigger and verdict from Steps 6 and 7
claude_usage one row per Claude API call: model, input/output tokens, cost_usd. Part 2 is built on this
equity_parity_snapshots one row per run, tracking the concentration score (HHI) over time

Rows go in with load_table_from_json(), not the streaming insert API. Streaming inserts sit in a buffer that blocks UPDATE and DELETE for a while, and this pipeline inserts a batch and then updates it a few minutes later in the same run (the verdicts from Steps 6 and 7). A load job doesn’t have that problem.

BigQuery dataset zerodha_pipeline showing the four tables above with their real creation timestamps.
FIG. 9 Real screenshot: the dataset and its four tables.

The real claude_usage schema, from INFORMATION_SCHEMA:

run_id (STRING)       call_type (STRING)     tradingsymbol (STRING)
model (STRING)        input_tokens (INT64)   output_tokens (INT64)
cost_usd (FLOAT64)    called_at_ist (DATETIME)

C. Screen, judge, allocate

These three steps read straight from Step 5. Only the middle one spends money.

Step 6: a free price screen. Plain Python, no API call. A holding is flagged when both are true:

  • it’s at least 15% below my average cost (TRIGGER_PCT_BELOW_AVG_COST), and
  • it’s under 8% of the whole portfolio (TRIGGER_MAX_POSITION_WEIGHT_PCT). The second rule stops an already large position from getting even more money.

Out of ~80 holdings, this usually flags about 5 in a month.

Step 7: the judgment call. For each flagged stock:

  • claude-sonnet-5 with effort: "low" and the web_search tool, capped at 4 searches with a floor of 2 set in the prompt. The range lets it reach for one more search on a messy stock.
  • It answers in structured JSON with these fields: cause_classification, ground_truth_signal, management_response, balance_sheet_health, confidence_tier, confidence_pct, verdict, short_reason, rationale, sources. No later step ever has to parse free text.
  • A second signal runs every month no matter what Step 6 found: a gold-silver ratio check. A small claude-haiku-4-5 call with web_search looks up spot prices and flags a partial trim when gold and silver are priced at an extreme against each other.
  • This is the only step in the whole pipeline that spends money. How much, and what it took to bring that down, is Part 2.

Step 8: allocation. Plain Python, no model.

  • It splits the money for the month (the budget plus any money freed up by exits from Step 7) across asset classes by the locked split, and holds back a 20% reserve in each class for later.
  • Inside a class, candidates share by confidence_pct. A 78% candidate gets more than a 62% one.
  • A class already at or above its target gets nothing that month, and an underweight class can never be pushed past its target in one go.
  • It builds one ledger, every buy and sell as a row plus totals, and that ledger becomes the email.

D. Send it

Step 8 writes the verdicts and cost back to Step 5 and hands the ledger to Step 9, which builds the email with MJML → HTML in Python. I picked MJML because it avoids a real Gmail Android rendering bug: it wraps each stacked line in its own table row. Step 10 sends it through Gmail.

One real run: 20 August 2026

Here’s what one run (run_id=2026-08-20) produced. The tables show API cost data and Claude’s verdicts, and nothing about the portfolio’s value.

What the Claude calls cost, straight from claude_usage:

Symbol Call Model In tokens Out tokens Cost
IRCTC stage_b sonnet-5 78,981 1,998 $0.178
ITC stage_b sonnet-5 79,968 2,861 $0.189
JYOTIRES stage_b sonnet-5 75,273 2,466 $0.175
KSOLVES stage_b sonnet-5 51,484 1,509 $0.118
PIIND stage_b sonnet-5 44,177 1,161 $0.100
(none) gsr_lookup haiku-4.5 9,867 138 $0.011
(none) notes haiku-4.5 410 108 $0.001

The table also has a second, more expensive row for some stocks that day: a retry after an earlier partial failure. The log keeps both rows instead of only the clean pass.

What Claude decided, in its own words, before any sizing:

Symbol Verdict Confidence Why
PIIND candidate Medium (62%) Cyclical export destocking, not moat damage; strong balance sheet supports recovery but timing uncertain.
IRCTC candidate Medium (62%) Price hit by regulatory fee-sharing fears and valuation reset, not by any real erosion of IRCTC’s ticketing/catering monopoly.
ITC candidate Medium (62%) Price hit by tax/policy noise, not a broken moat; cash-rich balance sheet, cigarette/FMCG franchise intact.
KSOLVES candidate Medium (62%) Margin dip is a self-funded growth investment, not moat erosion; cash-rich, debt-free, revenue still growing.
JYOTIRES not_candidate Low (38%) Stock is down sharply but cause and fundamentals could not be verified this cycle — don’t add yet.

What the money did: all 4 candidates qualified, and all 4 got ₹0. Equity was already above its locked target, so Step 8’s cap set the amount to zero. A good verdict from Claude still doesn’t get funded when the class is already overweight. Nothing to mask here; the real number is zero.

And this is the email, rebuilt from the real one’s sections and counts, with every rupee figure masked (budget, cost, money in and out, current and after-purchase weights):

Mockup of the monthly email with rupee figures masked: the Claude cost pill, the price-or-business question, counts of 5 evaluated, 2 add, 3 hold, 0 exit, the allocation table with real targets and masked actuals, a masked budget box, and one held stock card for JYOTIRES with Claude's reasoning.
FIG. 10 Mockup of the August email. Sections and counts are real, every rupee is masked.

Why it’s built this way

Three stages

The judgment is the only part that needs a model. Plain code screens by price and sizes by a formula just as well, for free. So Steps 6 and 8 do everything code can do, and Step 7, the expensive one, only runs on the handful of stocks that really need judgment. (What that saved, and what it took to tune Step 7, is Part 2.)

Buffett’s test

Averaging down only works when the business is still sound. “Is the damage to the price, or the business?” is the exact question that tells the two apart. A general good-news/bad-news check wouldn’t.

A locked split

Sizing in the moment is exactly the kind of decision market noise is good at spoiling. Fixing the split ahead of time, and capping each class at its target every month, takes that decision out of the moment.

A separate check for gold and silver

Buffett’s test is about businesses, and gold and silver aren’t businesses. So they get a gold-silver ratio check instead.

A balance check on the equity book

Nothing above stops slow, accidental concentration, where a few winners grow into a much bigger share of the book than I ever meant. Catching that is arithmetic, so it’s not a Claude call. It runs on data that’s already landed, for free, every month.

Unattended, with me still deciding

The goal was to make sure the review always happens while the decision stays with me. I’d rather read an email and override it than trust a system to act without me.

Tech stack

Part What it uses
Compute and scheduling Cloud Functions (Gen2, HTTP triggered), Cloud Scheduler
Data BigQuery: holdings landing, screening state, Claude API cost log, equity parity snapshots
Secrets Secret Manager: Claude API and Gmail credentials
AI Claude API: claude-sonnet-5 for judgment, claude-haiku-4-5 for small notes, with the web_search tool
Language Python throughout: the screen, the allocation math, the orchestration
Email MJML → HTML, sent with Gmail
Source data (Step 1) a separate Claude scheduled routine, the Kite MCP connector, a monthly Google Drive Sheet

What it doesn’t do

In scope: averaging into equity, ETF, REIT and InvIT holdings that fell well below cost, plus the separate gold and silver signal. Out of scope, on purpose: it doesn’t find new stocks to buy, it doesn’t review every holding for an exit unless its price dropped, and it never places a trade. Each of those was a deliberate “not yet”.

What’s changed since August 2026

This article is a record of how the system worked in August 2026. A few things have moved on since:

  • The monthly review now runs locally in Claude Code, with a newer set of rules.
  • It now looks for new stocks as well, and rates each company’s moat before buying.
  • The locked split has changed. Equity is now 76%, and the separate banking slot is gone.

The new version will get its own write-up.

Part 2 is about what happened when a paid model call went into this unattended monthly run: the real cost data, the tuning that worked, the tuning that backfired, and where retrieval (RAG) might take it next. Part 3, putting the results on a physical screen, is on hold until there’s real hardware to show.