Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"metadata": {
"description": "Altimate's Claude Code plugin — data tools through the altimate-code MCP server, or the model-free CLI where MCP is disallowed, plus delegation of long dbt jobs to the CLI agent.",
"version": "1.8.2"
"version": "1.8.3"
},
"plugins": [
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/altimate-code/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "altimate-code",
"displayName": "Altimate Code",
"version": "1.8.2",
"version": "1.8.3",
"description": "Gives Claude Code altimate-code's model-free data tools (column-level lineage, impact analysis, PII detection, data-diff, FinOps, query equivalence, dialect translation, warehouse queries) through its MCP server, or through `altimate tool run` when MCP servers are not allowed, with delegation to the altimate-code agent for long dbt jobs, access to a linked Altimate workspace's knowledge, and the workspace's team rules in each session.",
"author": {
"name": "AltimateAI",
Expand Down
9 changes: 9 additions & 0 deletions plugins/altimate-code/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this plugin will be documented in this file.

## [1.8.3] — 2026-11-19

### Fixed
- Project health: a Bash command with its own `cd` is read from the folder it started in even when another Bash call finishes meanwhile (a subagent's); the start folder is kept per call. `echo ${#arr[@]}; git push` is found as a push. A session outside a dbt project no longer looks up the shell folder or holds a push.
- `/scan-cost` with no model keeps the planner label of the last Snowflake or Databricks estimate ("Snowflake plan estimate").

### Added
- The README explains `altimate-dbt`, the dbt command line that comes with altimate-code, what the agent uses it for, and that you do not need to run it.

## [1.8.2] — 2026-11-19

### Added
Expand Down
4 changes: 4 additions & 0 deletions plugins/altimate-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ Opening a dbt folder runs two programs the repository supplies, with no action f

Compile and validate runs a query on your warehouse after every model edit (`dbt show --limit 1`). On a warehouse that bills by bytes scanned or wakes a suspended warehouse for it, that costs money. Set the plugin's `dbt_mods` option to false (in `/config`) to turn all of the helpers off.

### altimate-dbt

When Claude mentions `altimate-dbt`, it is the dbt command line that comes with altimate-code (`npm i -g @altimateai/altimate-code`, the same install as the plugin's engine). It finds your dbt project folder, Python environment and warehouse adapter by itself, and altimate-code's agent uses it instead of the raw dbt tool for better error messages. Its commands include `init`, `doctor`, `compile`, `build`, `run`, `test`, `deps`, `columns <model>`, `graph` (lineage) and `execute "<sql>"` (a query through the dbt adapter). You do not need to run it yourself: Claude and the altimate-code agent call it when a task needs it, and the plugin's own dbt helpers above do not depend on it. See [altimate-dbt in the altimate-code docs](https://docs.altimate.sh/data-engineering/tools/dbt-tools/#altimate-dbt-cli).

## Settings

The plugin has seven settings, shown when you enable it (`userConfig` in `.claude-plugin/plugin.json`). All are optional: Claude Code may report them as "not set", and each then takes the default below. `dbt_mods` is used by the dbt helpers, `maxScanBytes` by the scan check (BigQuery, Snowflake, Databricks), `healthBlocksPush` and `healthConfigPath` by the project health check, the two comments settings by team comments, and `show_edit_impact` by the per-edit impact note.
Expand Down
6 changes: 6 additions & 0 deletions plugins/altimate-code/hooks/features/cost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,12 @@ test('/scan-cost on Snowflake names the plan estimate and the verdict', async ($
)
})

test('/scan-cost with no model keeps the plan estimate label of the last estimate', async ($, on) => {
await start($, on, { answers: { orders: planned('snowflake', 20 * GIB, '20.0 GiB') } })
await $.command.run({ command: 'scan-cost', args: 'orders' } as any)
expect((await $.command.run({ command: 'scan-cost', args: '' } as any)).text).toBe('Last estimate: orders would scan 20.0 GiB (Snowflake plan estimate). Run /scan-cost <model> for another.')
})

test('/scan-cost on an older altimate-code over Databricks says a newer one is needed', async ($, on) => {
await start($, on, { fallback: { success: true, supported: false, adapter: 'databricks' } })
expect((await $.command.run({ command: 'scan-cost', args: 'orders' } as any)).text).toBe(
Expand Down
10 changes: 5 additions & 5 deletions plugins/altimate-code/hooks/features/cost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function register(on: On, context: FeatureContext) {
const target = e.args.trim()
if (!target) {
const last = (await read($, costAtom))?.lastEstimate
return { text: last ? `Last estimate: ${last.target} would scan ${last.display}. Run /scan-cost <model> for another.` : 'Run /scan-cost <model> to estimate the scan of a model.' }
return { text: last ? `Last estimate: ${last.target} would scan ${last.display}${basisOf(last)}. Run /scan-cost <model> for another.` : 'Run /scan-cost <model> to estimate the scan of a model.' }
}
const began = await $.clock.now()
// The wait is short (the user is looking at the screen); the estimate's own budget starts when the wait ends, at the latest.
Expand All @@ -171,7 +171,7 @@ export function register(on: On, context: FeatureContext) {
const answer = await started.answer
if (answer.kind === 'bytes') {
await forgetUnsupported($)
await rememberEstimate($, target, answer.bytes, answer.display)
await rememberEstimate($, target, answer.bytes, answer.display, answer.planner)
return { text: `${target} would scan ${answer.display}${basisOf(answer)}${verdict(answer.maxBytes)}` }
}
return { text: answer.kind === 'unsupported' ? `No estimate: ${unsupportedWhy(answer.adapter)}.` : `No estimate: ${answer.reason}` }
Expand Down Expand Up @@ -358,7 +358,7 @@ async function gate($: EngineInterface, e: BashCall, mine: { note?: object }): P
mine.note = { label, bytes: answer.maxBytes, display: answer.display, planner: answer.planner }
overNow.set(e.command, mine.note as { label: string; bytes: number; display: string; planner?: string })
}
await rememberEstimate($, label, answer.bytes, answer.display)
await rememberEstimate($, label, answer.bytes, answer.display, answer.planner)
if (answer.maxBytes <= limitBytes) lines.push(`cost · ${label} would scan ${answer.display}${basisOf(answer)}`)
else over.push({ label, bytes: answer.maxBytes, point: answer.bytes, display: answer.display, planner: answer.planner })
}
Expand Down Expand Up @@ -768,10 +768,10 @@ async function estimateWithin($: EngineInterface, args: { model?: string; sql?:
return done.answer
}

async function rememberEstimate($: EngineInterface, target: string, bytes: number, display: string) {
async function rememberEstimate($: EngineInterface, target: string, bytes: number, display: string, planner?: string) {
// What is shown never decides the gate: a failure here must not let a scan the gate knows is over the limit through.
try {
await update($, costAtom, prev => ({ ...(prev ?? FRESH), lastEstimate: { target, bytes, display } }))
await update($, costAtom, prev => ({ ...(prev ?? FRESH), lastEstimate: { target, bytes, display, ...(planner && { planner }) } }))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: planner is now written into lastEstimate, but its declared shape was not updated.

CostState.lastEstimate in types/index.d.ts:507 is still { target: string; bytes: number; display: string }, so the persisted state and its documented type disagree (the sibling held field already declares planner?: string). Reading last.planner anywhere later would fail typecheck, and the type comment no longer describes what is stored. Add planner?: string there (the spread hides the excess property from typecheck here).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2a08944: planner?: string is declared on CostState.lastEstimate.

await setStatusPart($, 'cost', `scan ≈ ${display}`)
} catch {}
}
Expand Down
31 changes: 22 additions & 9 deletions plugins/altimate-code/hooks/features/health.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ export function simpleCommands(line: string): string[][] {
}
for (let i = 0; i < line.length; i++) {
const c = line[i]!
if (c === '#' && !inWord) {
if (c === '#' && !inWord && !(line[i - 1] === '{' && line[i - 2] === '$')) {
// An unquoted `#` at the start of a word is a comment to the end of the line: its quotes and commands are text.
// The `#` of `${#name}` (a length) is not one: `{` ends the word before it.
const end = line.indexOf('\n', i)
i = end < 0 ? line.length : end - 1
} else if (c === "'") {
Expand Down Expand Up @@ -649,7 +650,7 @@ export async function sessionStart($: EngineInterface, e: Args<'session.start'>)
enabled = false
toldProblem = null
known = []
shellBefore = null
shellBefore.clear()
projects.clear()
await update($, healthAtom, () => fresh())
// The status line outlives a process: a part an earlier one left is cleared whether or not this one drew it.
Expand Down Expand Up @@ -705,9 +706,11 @@ export function pushRefusal(blocks: unknown, command: string, issues: readonly H
* they have new health issues. A check that cannot run or does not finish holds it too.
*/
export async function bashGate($: EngineInterface, e: BashCall): Promise<{ deny: string } | null> {
// A session outside a dbt project has no check to wait for and no folder to note.
if (!enabled) return null
if (!(options.healthBlocksPush === true || options.healthBlocksPush === 'true') || !isGitPush(e.command)) {
// Where the shell is before this command runs: its own `cd`s are read from there, and `bashAfter` sees the folder after them.
if (CHANGES_FOLDER.test(e.command)) shellBefore = { command: e.command, folder: await within($, GATE_WAIT_MS, shellFolder($)) }
if (CHANGES_FOLDER.test(e.command)) noteFolder(e, await within($, GATE_WAIT_MS, shellFolder($)))
return null
}
// The whole decision, folder lookups included, is bounded inside the chain's deadline: past it the gate is given up on and the push runs.
Expand All @@ -725,7 +728,7 @@ async function decide($: EngineInterface, e: BashCall): Promise<{ deny: string }
const startedAt = await $.clock.now()
// An edit in the same command would run before any check of it.
const here = await shellFolder($)
if (CHANGES_FOLDER.test(e.command)) shellBefore = { command: e.command, folder: here }
if (CHANGES_FOLDER.test(e.command)) noteFolder(e, here)
for (const name of filesWrittenBy(e.command)) if (await isModelFile($, name.startsWith('/') || /^[A-Za-z]:/.test(name) ? name : `${here}/${name}`)) return hold(`this command changes the model file ${name} and pushes in one go, so the change is not checked first. Run them as separate commands.`)
// With nothing changed this session there is nothing to wait for or hold.
if (((await read($, healthAtom))?.touched.length ?? 0) === 0) return 'run'
Expand All @@ -741,8 +744,16 @@ async function decide($: EngineInterface, e: BashCall): Promise<{ deny: string }
return pushRefusal(options.healthBlocksPush, e.command, state?.issues ?? []) ?? 'run'
}

// The folder noted before a command with its own `cd` ran; `folder` is null when the lookup ran out of time.
let shellBefore: { command: string; folder: string | null } | null = null
// The folder noted before each command with its own `cd` ran, by call (by command when the call has no id); `folder` is null when the lookup ran out of time.
// Calls can overlap (a subagent's), so one slot would lose a start folder.
const shellBefore = new Map<string, string | null>()
const callKey = (e: BashCall) => e.tool_use_id ?? e.command
function noteFolder(e: BashCall, folder: string | null) {
shellBefore.delete(callKey(e))
shellBefore.set(callKey(e), folder)
// A call a later gate refused never reaches its after-phase: only the newest notes are kept.
for (const old of [...shellBefore.keys()].slice(0, -50)) shellBefore.delete(old)
}
const CHANGES_FOLDER = /\b(cd|pushd)\b/

/** The folder the session's shell is in now; the session's root when the host does not say. */
Expand All @@ -752,13 +763,15 @@ async function shellFolder($: EngineInterface): Promise<string> {

/** A model file Bash writes (a `sed -i`, a redirect, a `git checkout -- file`) is checked like one Claude edited. */
export async function bashAfter($: EngineInterface, e: BashCall, result: ToolCallResult): Promise<ContextLines> {
if (!enabled) return
const root = await $.session.root().catch(() => '')
// A relative name is relative to the folder the session's shell is in now: an earlier `cd` moved it.
// A command with its own `cd` is read from the folder it started in, which the gate noted.
// A note belongs to its own command; a command with a `cd` whose start is unknown is read from the session's root, where it began.
const noted = shellBefore?.command === e.command ? shellBefore : null
shellBefore = null
const here = noted ? (noted.folder ?? root) : CHANGES_FOLDER.test(e.command) ? root : await shellFolder($)
const noted = shellBefore.has(callKey(e))
const folder = shellBefore.get(callKey(e)) ?? null
shellBefore.delete(callKey(e))
const here = noted ? (folder ?? root) : CHANGES_FOLDER.test(e.command) ? root : await shellFolder($)
for (const name of filesWrittenBy(e.command)) await markChanged($, name.startsWith('/') || /^[A-Za-z]:/.test(name) ? name : `${here}/${name}`, root)
}

Expand Down
55 changes: 52 additions & 3 deletions plugins/altimate-code/hooks/health.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Options = {
/** Holds the folder lookup while it returns a promise. */
holdCwd?: () => Promise<void> | undefined
/** Called when the Bash command itself runs, between the gate and the after-phase. */
onCall?: () => void
onCall?: () => Promise<void> | void
/** Called at each project lookup; a promise it returns holds the lookup. */
onExists?: () => Promise<void> | void
/** The environment the plugin reads, which turns the usage events on (none set) or off; unset, they are not sent. */
Expand Down Expand Up @@ -123,8 +123,8 @@ async function start($: any, on: any, options: Options, session: { isInteractive
on('fs.read', () => ({ value: '' }))
on('tool.list', () => ({ value: [] }))
on('mcp.connect', () => ({ value: { isConnected: false, reason: 'not_connected', message: 'off' } }))
on('tool.call', () => {
options.onCall?.()
on('tool.call', async () => {
await options.onCall?.()
return { result: { ok: true } }
})
let run = 0
Expand Down Expand Up @@ -546,6 +546,8 @@ test('a comment never hides the push that follows it, and a push inside a commen
expect(isGitPush('echo x # ; git push')).toBe(false)
expect(isGitPush('git status # git push')).toBe(false)
expect(isGitPush('echo a#b && git push')).toBe(true)
expect(isGitPush('echo ${#arr[@]}; git push')).toBe(true)
expect(isGitPush('echo $# ${#x}; git push')).toBe(true)
})

test('an unnamed YAML file edited before the baseline lands does not empty the baseline', async ($, on) => {
Expand Down Expand Up @@ -876,6 +878,53 @@ test('the push gate waits for less than the tool chain gives a phase, so a held
expect(GATE_WAIT_MS).toBeLessThan(PHASE_TIMEOUT_MS)
})

test('a Bash call that finishes while another is running leaves the other its own start folder', async ($, on) => {
let inner = false
const options: Options = {
runs: [[], [NEW_STG]],
cwd: `${ROOT}/models`,
onCall: async () => {
if (inner) return
inner = true
await $.tool.call({ ...command('ls'), tool_use_id: 'b' })
},
}
const { clock, calls, toasts } = await start($, on, options)
await $.tool.call({ ...command(`cd staging && sed -i 's/a/b/' stg_orders.sql`), tool_use_id: 'a' })
await endTurn($, clock, 't1')
expect(calls).toHaveLength(2)
expect(toasts).toEqual(['◆ 1 new health issue · stg_orders: hard coded references · /health'])
})

let stall = false

test('a command with its own cd whose start folder could not be read in time is read from the session root', async ($, on) => {
const never = new Promise<void>(() => {})
const { clock, calls, toasts } = await start($, on, { runs: [[], [NEW_STG]], cwd: `${ROOT}/models/staging`, holdCwd: () => (stall ? never : undefined) })
stall = true
const pending = $.tool.call(command(`cd models/staging && sed -i 's/a/b/' stg_orders.sql`))
await clock.advance(GATE_WAIT_MS + 100)
await pending
stall = false
await endTurn($, clock, 't1')
expect(calls).toHaveLength(2)
expect(toasts).toEqual(['◆ 1 new health issue · stg_orders: hard coded references · /health'])
})

test('a YAML file no insight names, edited after the baseline, counts every model as edited', async ($, on) => {
const { clock, calls, toasts } = await start($, on, { runs: [[OLD_STG, OLD_FCT], [OLD_STG, OLD_FCT, NEW_FCT]] })
await $.tool.call(edit(`${ROOT}/models/_sources.yml`))
await endTurn($, clock, 't1')
expect(calls).toHaveLength(2)
expect(toasts).toEqual(['◆ 1 new health issue · fct_orders: model fanout · /health'])
})

test('with the push gate on, a session opened above its dbt project holds nothing', { options: { healthBlocksPush: true } }, async ($, on) => {
await start($, on, { runs: [[]], projects: [`${ROOT}/dbt`] })
const allowed: any = await $.tool.call(command(`cd dbt && echo x > models/a.sql && git push`))
expect(allowed?.deny).toBeUndefined()
})

test('with the push gate on, a held push sends one health_push_gate held usage event, and /health one opened', { options: { healthBlocksPush: true } }, async ($, on) => {
const { clock, usage } = await start($, on, { runs: [[OLD_STG], [OLD_STG, NEW_STG]], env: {} })
await $.tool.call(edit(STG))
Expand Down
2 changes: 1 addition & 1 deletion plugins/altimate-code/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export interface CostState {
/** The warehouse with no estimate (not BigQuery, Snowflake or Databricks, or an altimate-code too old for it), once the tool said so: nothing is estimated after that. */
unsupportedAdapter: string | null
/** The newest estimate: what was estimated, in bytes, as the dry run or the planner gave it. */
lastEstimate: { target: string; bytes: number; display: string } | null
lastEstimate: { target: string; bytes: number; display: string; planner?: string } | null
/** The command held for being over the limit, until it is allowed or a later dbt command is estimated under the limit; `bytes` is its scan's upper bound, `planner` the warehouse whose planner made the estimate (none for a dry run). */
held: { command: string; target: string; bytes: number; display: string; planner?: string } | null
/** /allow-scan was given for the held command: that same command runs once. */
Expand Down
Loading