Live data from Hacker News

Ask HN: "AST vs. Code" as Context for AI Agents

news.ycombinator.com

1–6 of 6 posts

Re: Ask HN: "AST vs. Code" as Context for AI Agents

#2
Code has commentary parts, which vanish when generating AST. Also, if feeding AST, sometimes the broad context is lost. And, AST might have a compression advantage on looong code, but inflate on short functions (means it would be better to feed the code line) and from my experience, AST use up more tokens then the plain code just caused by "AST representation is longer than the peace of code it represents". So, I stopped trying to teach Claude what I wanted with the AST.

Re: Ask HN: "AST vs. Code" as Context for AI Agents

#3

Code has commentary parts, which vanish when generating AST. Also, if feeding AST, sometimes the broad context is lost. And, AST might have a compression advantage on looong code, but inflate on short functions (means it would be better to feed the code line) and from my experience, AST use up more tokens then the plain code just caused by "AST representation is longer than the peace of code it represents". So, I sto…

Couldn't that problem be mitigated by offering the agents tools to query the AST and isolate the code they want to read or change? Wouldn't this work better that the grep tools? Regarding the comments, I agree that AST do not provide the much broader context!

Re: Ask HN: "AST vs. Code" as Context for AI Agents

#4

Code has commentary parts, which vanish when generating AST. Also, if feeding AST, sometimes the broad context is lost. And, AST might have a compression advantage on looong code, but inflate on short functions (means it would be better to feed the code line) and from my experience, AST use up more tokens then the plain code just caused by "AST representation is longer than the peace of code it represents". So, I sto…

Couldn't that problem be mitigated by offering the agents tools to query the AST and isolate the code they want to read or change? Wouldn't this work better that the grep tools? Regarding the comments, I agree that AST do not provide the much broader context!

May be. Keep in mind that every system you build around AST is language specific. AST python is a different thing than AST from other languages. So, the grep idea holds because it works on source and Claude can work with it.

There are a few MCP Server presented here at HN in the last time that do graphs and such things. May be that's a better way?

Re: Ask HN: "AST vs. Code" as Context for AI Agents

#5

Earlier quoted context omitted.

Couldn't that problem be mitigated by offering the agents tools to query the AST and isolate the code they want to read or change? Wouldn't this work better that the grep tools? Regarding the comments, I agree that AST do not provide the much broader context!

May be. Keep in mind that every system you build around AST is language specific. AST python is a different thing than AST from other languages. So, the grep idea holds because it works on source and Claude can work with it. There are a few MCP Server presented here at HN in the last time that do graphs and such things. May be that's a better way?

Yes the AST would be language specific, but I believe that it has benefits when it comes at code processing/modification within a programming language. For example when it comes to package upgrades. When you have to upgrade the version of a package and adjust the client code over multiple projects, lets say they are written in TypeScript, you will have to provide Claude the code as context for each project. Maybe if you use AST transformation rules, you could apply the changes to all your projects.

I am trying to build this tool Apiweiser, https://apiweiser.vercel.app/ which tracks your packages and REST APIs you call, and applies fixes to your code whenever they change. That's why I am brainstorming ideas on how to be more efficient on code changes across repos. You can join the waitlist if you are interested :) !