Experimental API - Context Engine SDK is experimental and subject to breaking changes.
Installation
npm install -g @augmentcode/auggie@latest && npm install @augmentcode/auggie-sdk
Getting Credentials
Sign in to Augment using the CLI:
Your credentials will be stored in ~/.augment/session.json and the SDK will automatically use them.
Alternatively, for automation or non-interactive environments, set the AUGMENT_SESSION_AUTH environment variable to the session JSON:
auggie token print # Get your session JSON
export AUGMENT_SESSION_AUTH = '<session-json>'
The session JSON includes both your access token and tenant URL, so no separate URL variable is needed. Run auggie token print after logging in to get the full session JSON.
Direct Context
Explicitly index files from any source (APIs, databases, memory, disk) with full control over what gets indexed and the ability to save/load state:
import { DirectContext } from '@augmentcode/auggie-sdk' ;
async function main () {
// Authentication is automatic via:
// 1. Options parameters (apiKey, apiUrl passed to create())
// 2. AUGMENT_SESSION_AUTH environment variable (session JSON from `auggie token print`)
// 3. ~/.augment/session.json (created by `auggie login`)
const context = await DirectContext . create ();
// Add files to index
const result = await context . addToIndex ([
{ path: 'src/main.ts' , contents: 'export function main() { ... }' },
{ path: 'src/auth.ts' , contents: 'export function authenticate() { ... }' }
]);
console . log ( `Newly uploaded: ${ result . newlyUploaded . length } ` );
console . log ( `Already uploaded: ${ result . alreadyUploaded . length } ` );
// Search - returns formatted string ready for LLM use or display
const results = await context . search ( 'authentication logic' );
console . log ( results );
// Or use searchAndAsk for one-step Q&A
const answer = await context . searchAndAsk (
'How does authentication work?'
);
console . log ( answer );
// Save state to avoid re-indexing
await context . exportToFile ( '/tmp/state.json' );
}
main ();
FileSystem Context
Automatically index and search a local directory - just point to a directory path and start searching, perfect for local development and testing:
import { FileSystemContext } from '@augmentcode/auggie-sdk' ;
async function main () {
const context = await FileSystemContext . create ({
directory: '/path/to/workspace' ,
});
// Search the directory
const results = await context . search ( 'authentication logic' );
console . log ( results );
// Or ask a question
const answer = await context . searchAndAsk (
'How does authentication work?'
);
console . log ( answer );
// Clean up
await context . close ();
}
main ();
Next Steps
Examples See more example applications
API Reference Explore the complete API